X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;ds=sidebyside;f=tests%2Fbindings%2Fpython%2Fbt2%2Ftest_clock_class.py;h=04df66ad90dda31eda2b41a9cb8139b3b97b1632;hb=768f9bcbf4b5acd09dda85ab32c0ea30d8826136;hp=3805c0d56168f87a18d94e935fe1f855f54c2f2b;hpb=6c373cc905e907ecbad698fee38db1d47a981b14;p=babeltrace.git diff --git a/tests/bindings/python/bt2/test_clock_class.py b/tests/bindings/python/bt2/test_clock_class.py index 3805c0d5..04df66ad 100644 --- a/tests/bindings/python/bt2/test_clock_class.py +++ b/tests/bindings/python/bt2/test_clock_class.py @@ -1,26 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0-only # # 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 unittest import uuid -import copy import bt2 +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 +77,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): @@ -170,7 +160,7 @@ class ClockClassTestCase(unittest.TestCase): def test_cycles_to_ns_from_origin(self): def f(comp_self): return comp_self._create_clock_class( - frequency=10 ** 8, origin_is_unix_epoch=True + frequency=10**8, origin_is_unix_epoch=True ) cc = run_in_component_init(f) @@ -182,7 +172,7 @@ class ClockClassTestCase(unittest.TestCase): cc = run_in_component_init(f) with self.assertRaises(bt2._OverflowError): - cc.cycles_to_ns_from_origin(2 ** 63) + cc.cycles_to_ns_from_origin(2**63) def test_create_uuid(self): def f(comp_self): @@ -199,6 +189,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 +234,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): @@ -229,7 +243,7 @@ class ClockSnapshotTestCase(unittest.TestCase): elif self._at == 1: notif = self._create_event_message(_ec, _stream, 123) elif self._at == 2: - notif = self._create_event_message(_ec, _stream, 2 ** 63) + notif = self._create_event_message(_ec, _stream, 2**63) elif self._at == 3: notif = self._create_stream_end_message(_stream) else: @@ -239,7 +253,7 @@ 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() @@ -266,9 +280,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 +313,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()