lib: bt_graph_create(): accept MIP version
[babeltrace.git] / tests / bindings / python / bt2 / test_graph.py
index b7c0f0cb22f19cf6f82ce7a7d424b1f48adf2127..b719d9ca133e7b6956e7bbdb72a0bfc257f4ae01 100644 (file)
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #
 
-from bt2 import value
-import collections
 import unittest
-import copy
 import bt2
 
 
@@ -54,8 +51,19 @@ class GraphTestCase(unittest.TestCase):
     def tearDown(self):
         del self._graph
 
-    def test_create_empty(self):
-        graph = bt2.Graph()
+    def test_create_default(self):
+        bt2.Graph()
+
+    def test_create_known_mip_version(self):
+        bt2.Graph(0)
+
+    def test_create_invalid_mip_version_type(self):
+        with self.assertRaises(TypeError):
+            bt2.Graph('')
+
+    def test_create_unknown_mip_version(self):
+        with self.assertRaisesRegex(ValueError, 'unknown MIP version'):
+            bt2.Graph(1)
 
     def test_add_component_user_cls(self):
         class MySink(bt2._UserSinkComponent):
@@ -349,6 +357,59 @@ class GraphTestCase(unittest.TestCase):
         )
         self._graph.run()
 
+    def test_run_once(self):
+        class MyIter(_MyIter):
+            pass
+
+        class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter):
+            def __init__(self, params, obj):
+                self._add_output_port('out')
+
+        class MySink(bt2._UserSinkComponent):
+            def __init__(self, params, obj):
+                self._input_port = self._add_input_port('in')
+
+            def _user_consume(comp_self):
+                nonlocal run_count
+                run_count += 1
+                raise bt2.TryAgain
+
+        run_count = 0
+        src = self._graph.add_component(MySource, 'src')
+        sink = self._graph.add_component(MySink, 'sink')
+        conn = self._graph.connect_ports(
+            src.output_ports['out'], sink.input_ports['in']
+        )
+
+        with self.assertRaises(bt2.TryAgain):
+            self._graph.run_once()
+
+        self.assertEqual(run_count, 1)
+
+    def test_run_once_stops(self):
+        class MyIter(_MyIter):
+            pass
+
+        class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter):
+            def __init__(self, params, obj):
+                self._add_output_port('out')
+
+        class MySink(bt2._UserSinkComponent):
+            def __init__(self, params, obj):
+                self._input_port = self._add_input_port('in')
+
+            def _user_consume(comp_self):
+                raise bt2.Stop
+
+        src = self._graph.add_component(MySource, 'src')
+        sink = self._graph.add_component(MySink, 'sink')
+        conn = self._graph.connect_ports(
+            src.output_ports['out'], sink.input_ports['in']
+        )
+
+        with self.assertRaises(bt2.Stop):
+            self._graph.run_once()
+
     def test_run_again(self):
         class MyIter(_MyIter):
             def __next__(self):
This page took 0.025123 seconds and 4 git commands to generate.