X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=tests%2Fbindings%2Fpython%2Fbt2%2Ftest_trace.py;h=7fa8d8a56a28fc5d6fb46b96f99324400136b977;hb=f0a42b33ac3951cd5cb2ee0f66ac04437a681621;hp=6902924481f3c796b9afcaba226a29ace6e6a628;hpb=8c2367b884576ed438bc2e06cfc9205b2436838d;p=babeltrace.git diff --git a/tests/bindings/python/bt2/test_trace.py b/tests/bindings/python/bt2/test_trace.py index 69029244..7fa8d8a5 100644 --- a/tests/bindings/python/bt2/test_trace.py +++ b/tests/bindings/python/bt2/test_trace.py @@ -1,5 +1,29 @@ +# +# Copyright (C) 2019 EfficiOS Inc. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; only version 2 +# of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +import uuid import unittest +import utils from utils import get_default_trace_class +from bt2 import trace_class as bt2_trace_class +from bt2 import value as bt2_value +from bt2 import trace as bt2_trace +from bt2 import stream as bt2_stream class TraceTestCase(unittest.TestCase): @@ -8,16 +32,80 @@ class TraceTestCase(unittest.TestCase): def test_create_default(self): trace = self._tc() - self.assertEqual(trace.name, None) - - def test_create_full(self): - trace = self._tc(name='my name') - self.assertEqual(trace.name, 'my name') + self.assertIsNone(trace.name) + self.assertIsNone(trace.uuid) + self.assertEqual(len(trace.environment), 0) + self.assertEqual(len(trace.user_attributes), 0) def test_create_invalid_name(self): with self.assertRaises(TypeError): self._tc(name=17) + def test_create_user_attributes(self): + trace = self._tc(user_attributes={'salut': 23}) + self.assertEqual(trace.user_attributes, {'salut': 23}) + self.assertIs(type(trace.user_attributes), bt2_value.MapValue) + + def test_create_invalid_user_attributes(self): + with self.assertRaises(TypeError): + self._tc(user_attributes=object()) + + def test_create_invalid_user_attributes_value_type(self): + with self.assertRaises(TypeError): + self._tc(user_attributes=23) + + def test_attr_trace_class(self): + trace = self._tc() + self.assertEqual(trace.cls.addr, self._tc.addr) + self.assertIs(type(trace.cls), bt2_trace_class._TraceClass) + + def test_const_attr_trace_class(self): + trace = utils.get_const_stream_beginning_message().stream.trace + self.assertIs(type(trace.cls), bt2_trace_class._TraceClassConst) + + def test_attr_name(self): + trace = self._tc(name='mein trace') + self.assertEqual(trace.name, 'mein trace') + + def test_attr_uuid(self): + trace = self._tc(uuid=uuid.UUID('da7d6b6f-3108-4706-89bd-ab554732611b')) + self.assertEqual(trace.uuid, uuid.UUID('da7d6b6f-3108-4706-89bd-ab554732611b')) + + def test_env_get(self): + trace = self._tc(environment={'hello': 'you', 'foo': -5}) + self.assertIs(type(trace.environment), bt2_trace._TraceEnvironment) + self.assertIs(type(trace.environment['foo']), bt2_value.SignedIntegerValue) + self.assertEqual(trace.environment['hello'], 'you') + self.assertEqual(trace.environment['foo'], -5) + + def test_env_iter(self): + trace = self._tc(environment={'hello': 'you', 'foo': -5}) + values = set(trace.environment) + self.assertEqual(values, {'hello', 'foo'}) + + def test_const_env_get(self): + trace = utils.get_const_stream_beginning_message().stream.trace + self.assertIs(type(trace.environment), bt2_trace._TraceEnvironmentConst) + self.assertIs( + type(trace.environment['patate']), bt2_value._SignedIntegerValueConst + ) + + def test_env_iter(self): + trace = utils.get_const_stream_beginning_message().stream.trace + values = set(trace.environment) + self.assertEqual(values, {'patate'}) + + def test_const_env_set(self): + trace = utils.get_const_stream_beginning_message().stream.trace + with self.assertRaises(TypeError): + trace.environment['patate'] = 33 + + def test_env_get_non_existent(self): + trace = self._tc(environment={'hello': 'you', 'foo': -5}) + + with self.assertRaises(KeyError): + trace.environment['lel'] + def test_len(self): trace = self._tc() sc = self._tc.create_stream_class() @@ -42,8 +130,12 @@ class TraceTestCase(unittest.TestCase): def test_getitem(self): trace = self._create_trace_with_some_streams() - self.assertEqual(trace[12].id, 12) + self.assertIs(type(trace[12]), bt2_stream._Stream) + + def test_const_getitem(self): + trace = utils.get_const_stream_beginning_message().stream.trace + self.assertIs(type(trace[0]), bt2_stream._StreamConst) def test_getitem_invalid_key(self): trace = self._create_trace_with_some_streams()