X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=tests%2Fbindings%2Fpython%2Fbt2%2Ftest_graph.py;h=3ec32e628422d7591e5cad6bc2c31d8d36f4551c;hb=d24d56638469189904fb6ddbb3c725817b3e9417;hp=48e02873bb812b76d8c2bd414c4f1fb84b44bd8d;hpb=c5f330cd909f5dfbdb519546e875b4427434ba4f;p=babeltrace.git diff --git a/tests/bindings/python/bt2/test_graph.py b/tests/bindings/python/bt2/test_graph.py index 48e02873..3ec32e62 100644 --- a/tests/bindings/python/bt2/test_graph.py +++ b/tests/bindings/python/bt2/test_graph.py @@ -1,3 +1,21 @@ +# +# 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. +# + from bt2 import value import collections import unittest @@ -56,7 +74,7 @@ class GraphTestCase(unittest.TestCase): comp = self._graph.add_component(MySink, 'salut') assert comp - comp2 = self._graph.add_component(comp.component_class, 'salut2') + comp2 = self._graph.add_component(comp.cls, 'salut2') self.assertEqual(comp2.name, 'salut2') def test_add_component_params(self): @@ -79,6 +97,31 @@ class GraphTestCase(unittest.TestCase): with self.assertRaises(TypeError): self._graph.add_component(int, 'salut') + def test_add_component_invalid_logging_level_type(self): + class MySink(bt2._UserSinkComponent): + def _consume(self): + pass + + with self.assertRaises(TypeError): + self._graph.add_component(MySink, 'salut', logging_level='yo') + + def test_add_component_invalid_logging_level_value(self): + class MySink(bt2._UserSinkComponent): + def _consume(self): + pass + + with self.assertRaises(ValueError): + self._graph.add_component(MySink, 'salut', logging_level=12345) + + def test_add_component_logging_level(self): + class MySink(bt2._UserSinkComponent): + def _consume(self): + pass + + comp = self._graph.add_component(MySink, 'salut', + logging_level=bt2.LoggingLevel.DEBUG) + self.assertEqual(comp.logging_level, bt2.LoggingLevel.DEBUG) + def test_connect_ports(self): class MyIter(bt2._UserMessageIterator): def __next__(self): @@ -130,39 +173,12 @@ class GraphTestCase(unittest.TestCase): conn = self._graph.connect_ports(sink.input_ports['in'], src.output_ports['out']) - def test_connect_ports_refused(self): - class MyIter(bt2._UserMessageIterator): - def __next__(self): - raise bt2.Stop - - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): - def __init__(self, params): - self._add_output_port('out') - - class MySink(bt2._UserSinkComponent): - def __init__(self, params): - self._add_input_port('in') - - def _consume(self): - raise bt2.Stop - - def _accept_port_connection(self, port, other_port): - return False - - src = self._graph.add_component(MySource, 'src') - sink = self._graph.add_component(MySink, 'sink') - - with self.assertRaises(bt2.PortConnectionRefused): - conn = self._graph.connect_ports(src.output_ports['out'], - sink.input_ports['in']) - def test_cancel(self): self.assertFalse(self._graph.is_canceled) self._graph.cancel() self.assertTrue(self._graph.is_canceled) - # Test that Graph.run() raises bt2.GraphCanceled if the graph gets canceled + # Test that Graph.run() raises bt2.Canceled if the graph gets canceled # during execution. def test_cancel_while_running(self): class MyIter(_MyIter): @@ -192,7 +208,7 @@ class GraphTestCase(unittest.TestCase): up = graph.add_component(MySource, 'down') down = graph.add_component(MySink, 'up') graph.connect_ports(up.output_ports['out'], down.input_ports['in']) - with self.assertRaises(bt2.GraphCanceled): + with self.assertRaises(bt2.Canceled): graph.run() def test_run(self): @@ -234,7 +250,7 @@ class GraphTestCase(unittest.TestCase): self.assertIsInstance(msg, bt2.message._PacketBeginningMessage) elif comp_self._at >= 2 and comp_self._at <= 6: self.assertIsInstance(msg, bt2.message._EventMessage) - self.assertEqual(msg.event.event_class.name, 'salut') + self.assertEqual(msg.event.cls.name, 'salut') elif comp_self._at == 7: self.assertIsInstance(msg, bt2.message._PacketEndMessage) elif comp_self._at == 8: