X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=tests%2Fbindings%2Fpython%2Fbt2%2Ftest_clock_class.py;h=843333c8d6df91e0ccf0047d00dff3406ffaf04c;hb=HEAD;hp=26571bd40bd06b470ee186c4ec79c5cd3d4e116c;hpb=59225a3e0e13a9c674234755e55055d9ff68d635;p=babeltrace.git diff --git a/tests/bindings/python/bt2/test_clock_class.py b/tests/bindings/python/bt2/test_clock_class.py index 26571bd4..843333c8 100644 --- a/tests/bindings/python/bt2/test_clock_class.py +++ b/tests/bindings/python/bt2/test_clock_class.py @@ -1,28 +1,16 @@ +# 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 unittest + 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 +from utils import TestOutputPortMessageIterator, run_in_component_init class ClockClassOffsetTestCase(unittest.TestCase): @@ -43,11 +31,11 @@ class ClockClassOffsetTestCase(unittest.TestCase): def test_create_invalid_seconds(self): with self.assertRaises(TypeError): - bt2.ClockClassOffset('hello', 4871232) + bt2.ClockClassOffset("hello", 4871232) def test_create_invalid_cycles(self): with self.assertRaises(TypeError): - bt2.ClockClassOffset(23, 'hello') + bt2.ClockClassOffset(23, "hello") def test_eq(self): cco1 = bt2.ClockClassOffset(23, 42) @@ -94,10 +82,10 @@ class ClockClassTestCase(unittest.TestCase): def test_create_name(self): def f(comp_self): - return comp_self._create_clock_class(name='the_clock') + return comp_self._create_clock_class(name="the_clock") cc = run_in_component_init(f) - self.assertEqual(cc.name, 'the_clock') + self.assertEqual(cc.name, "the_clock") def test_create_invalid_name(self): def f(comp_self): @@ -107,10 +95,10 @@ class ClockClassTestCase(unittest.TestCase): def test_create_description(self): def f(comp_self): - return comp_self._create_clock_class(description='hi people') + return comp_self._create_clock_class(description="hi people") cc = run_in_component_init(f) - self.assertEqual(cc.description, 'hi people') + self.assertEqual(cc.description, "hi people") def test_create_invalid_description(self): def f(comp_self): @@ -127,7 +115,7 @@ class ClockClassTestCase(unittest.TestCase): def test_create_invalid_frequency(self): def f(comp_self): - return comp_self._create_clock_class(frequency='lel') + return comp_self._create_clock_class(frequency="lel") self.assertRaisesInComponentInit(TypeError, f) @@ -140,7 +128,7 @@ class ClockClassTestCase(unittest.TestCase): def test_create_invalid_precision(self): def f(comp_self): - return comp_self._create_clock_class(precision='lel') + return comp_self._create_clock_class(precision="lel") self.assertRaisesInComponentInit(TypeError, f) @@ -173,7 +161,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) @@ -185,16 +173,16 @@ 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): return comp_self._create_clock_class( - uuid=uuid.UUID('b43372c32ef0be28444dfc1c5cdafd33') + uuid=uuid.UUID("b43372c32ef0be28444dfc1c5cdafd33") ) cc = run_in_component_init(f) - self.assertEqual(cc.uuid, uuid.UUID('b43372c32ef0be28444dfc1c5cdafd33')) + self.assertEqual(cc.uuid, uuid.UUID("b43372c32ef0be28444dfc1c5cdafd33")) def test_create_invalid_uuid(self): def f(comp_self): @@ -204,10 +192,10 @@ class ClockClassTestCase(unittest.TestCase): def test_create_user_attributes(self): def f(comp_self): - return comp_self._create_clock_class(user_attributes={'salut': 23}) + return comp_self._create_clock_class(user_attributes={"salut": 23}) cc = run_in_component_init(f) - self.assertEqual(cc.user_attributes, {'salut': 23}) + self.assertEqual(cc.user_attributes, {"salut": 23}) self.assertIs(type(cc.user_attributes), bt2_value.MapValue) def test_create_invalid_user_attributes(self): @@ -231,7 +219,7 @@ class ClockSnapshotTestCase(unittest.TestCase): def setUp(self): def f(comp_self): cc = comp_self._create_clock_class( - 1000, 'my_cc', offset=bt2.ClockClassOffset(45, 354) + 1000, "my_cc", offset=bt2.ClockClassOffset(45, 354) ) tc = comp_self._create_trace_class() @@ -240,14 +228,14 @@ class ClockSnapshotTestCase(unittest.TestCase): _cc, _tc = run_in_component_init(f) _trace = _tc() _sc = _tc.create_stream_class(default_clock_class=_cc) - _ec = _sc.create_event_class(name='salut') + _ec = _sc.create_event_class(name="salut") _stream = _trace.create_stream(_sc) self._stream = _stream self._ec = _ec 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): @@ -256,7 +244,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: @@ -267,12 +255,12 @@ class ClockSnapshotTestCase(unittest.TestCase): class MySrc(bt2._UserSourceComponent, message_iterator_class=MyIter): def __init__(self, config, params, obj): - self._add_output_port('out') + self._add_output_port("out") self._graph = bt2.Graph() - self._src_comp = self._graph.add_component(MySrc, 'my_source') + self._src_comp = self._graph.add_component(MySrc, "my_source") self._msg_iter = TestOutputPortMessageIterator( - self._graph, self._src_comp.output_ports['out'] + self._graph, self._src_comp.output_ports["out"] ) for i, msg in enumerate(self._msg_iter): @@ -328,5 +316,5 @@ class ClockSnapshotTestCase(unittest.TestCase): self.assertFalse(self._msg.default_clock_snapshot <= 100) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main()