X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=tests%2Fbindings%2Fpython%2Fbt2%2Ftest_clock_class.py;h=c4b34bd29b14110f7674873177600e4db523f085;hb=8d8b141db4c46135a35be19e4a1c192f6a36d67b;hp=48ae9602fb7300858253605c92d65933254dcfc6;hpb=66964f3f7b0b7e3b774ddb043b0f197018d23730;p=babeltrace.git diff --git a/tests/bindings/python/bt2/test_clock_class.py b/tests/bindings/python/bt2/test_clock_class.py index 48ae9602..c4b34bd2 100644 --- a/tests/bindings/python/bt2/test_clock_class.py +++ b/tests/bindings/python/bt2/test_clock_class.py @@ -18,9 +18,11 @@ import unittest import uuid -import copy import bt2 -from utils import run_in_component_init +import utils +from utils import run_in_component_init, TestOutputPortMessageIterator +from bt2 import value as bt2_value +from bt2 import clock_class as bt2_clock_class class ClockClassOffsetTestCase(unittest.TestCase): @@ -88,6 +90,7 @@ class ClockClassTestCase(unittest.TestCase): self.assertEqual(cc.offset, bt2.ClockClassOffset()) self.assertTrue(cc.origin_is_unix_epoch) self.assertIsNone(cc.uuid) + self.assertEqual(len(cc.user_attributes), 0) def test_create_name(self): def f(comp_self): @@ -199,6 +202,30 @@ class ClockClassTestCase(unittest.TestCase): self.assertRaisesInComponentInit(TypeError, f) + def test_create_user_attributes(self): + def f(comp_self): + return comp_self._create_clock_class(user_attributes={'salut': 23}) + + cc = run_in_component_init(f) + self.assertEqual(cc.user_attributes, {'salut': 23}) + self.assertIs(type(cc.user_attributes), bt2_value.MapValue) + + def test_create_invalid_user_attributes(self): + def f(comp_self): + return comp_self._create_clock_class(user_attributes=object()) + + self.assertRaisesInComponentInit(TypeError, f) + + def test_create_invalid_user_attributes_value_type(self): + def f(comp_self): + return comp_self._create_clock_class(user_attributes=23) + + self.assertRaisesInComponentInit(TypeError, f) + + def test_const_user_attributes(self): + cc = utils.get_const_event_message().default_clock_snapshot.clock_class + self.assertIs(type(cc.user_attributes), bt2_value._MapValueConst) + class ClockSnapshotTestCase(unittest.TestCase): def setUp(self): @@ -220,7 +247,7 @@ class ClockSnapshotTestCase(unittest.TestCase): self._cc = _cc class MyIter(bt2._UserMessageIterator): - def __init__(self, self_port_output): + def __init__(self, config, self_port_output): self._at = 0 def __next__(self): @@ -239,13 +266,13 @@ class ClockSnapshotTestCase(unittest.TestCase): return notif class MySrc(bt2._UserSourceComponent, message_iterator_class=MyIter): - def __init__(self, params, obj): + def __init__(self, config, params, obj): self._add_output_port('out') self._graph = bt2.Graph() self._src_comp = self._graph.add_component(MySrc, 'my_source') - self._msg_iter = self._graph.create_output_port_message_iterator( - self._src_comp.output_ports['out'] + self._msg_iter = TestOutputPortMessageIterator( + self._graph, self._src_comp.output_ports['out'] ) for i, msg in enumerate(self._msg_iter): @@ -266,9 +293,9 @@ class ClockSnapshotTestCase(unittest.TestCase): self.assertEqual(self._msg.default_clock_snapshot.value, 123) def test_clock_class(self): - self.assertEqual( - self._msg.default_clock_snapshot.clock_class.addr, self._cc.addr - ) + cc = self._msg.default_clock_snapshot.clock_class + self.assertEqual(cc.addr, self._cc.addr) + self.assertIs(type(cc), bt2_clock_class._ClockClassConst) def test_ns_from_origin(self): s_from_origin = 45 + ((354 + 123) / 1000) @@ -299,3 +326,7 @@ class ClockSnapshotTestCase(unittest.TestCase): self.assertTrue(self._msg.default_clock_snapshot <= 123) self.assertFalse(self._msg.default_clock_snapshot <= 100) + + +if __name__ == '__main__': + unittest.main()