bt2: Adapt test_stream.py and make it pass
[babeltrace.git] / tests / bindings / python / bt2 / test_stream.py
index fa31088f9f3309b0c336468613e9f1373b8f08b4..19874f2392022567a72724a7befe81234dbef2cb 100644 (file)
-from collections import OrderedDict
-from bt2 import value
 import unittest
-import copy
-import bt2
+from utils import run_in_component_init
 
 
-@unittest.skip("this is broken")
 class StreamTestCase(unittest.TestCase):
     def setUp(self):
-        self._stream = self._create_stream(stream_id=23)
+        def f(comp_self):
+            return comp_self._create_trace_class()
 
-    def tearDown(self):
-        del self._stream
+        self._tc = run_in_component_init(f)
+        self._sc = self._tc.create_stream_class(assigns_automatic_stream_id=True)
+        self._tr = self._tc()
 
-    def _create_stream(self, name='my_stream', stream_id=None):
-        # event header
-        eh = bt2.StructureFieldClass()
-        eh += OrderedDict((
-            ('id', bt2.IntegerFieldClass(8)),
-            ('ts', bt2.IntegerFieldClass(32)),
-        ))
+    def test_create_default(self):
+        stream = self._tr.create_stream(self._sc)
+        self.assertIsNone(stream.name)
 
-        # stream event context
-        sec = bt2.StructureFieldClass()
-        sec += OrderedDict((
-            ('cpu_id', bt2.IntegerFieldClass(8)),
-            ('stuff', bt2.FloatingPointNumberFieldClass()),
-        ))
+    def test_name(self):
+        stream = self._tr.create_stream(self._sc, name='équidistant')
+        self.assertEqual(stream.name, 'équidistant')
 
-        # packet context
-        pc = bt2.StructureFieldClass()
-        pc += OrderedDict((
-            ('something', bt2.IntegerFieldClass(8)),
-            ('something_else', bt2.FloatingPointNumberFieldClass()),
-        ))
+    def test_invalid_name(self):
+        with self.assertRaises(TypeError):
+            self._tr.create_stream(self._sc, name=22)
 
-        # stream class
-        sc = bt2.StreamClass()
-        sc.packet_context_field_class = pc
-        sc.event_header_field_class = eh
-        sc.event_context_field_class = sec
+    def test_stream_class(self):
+        stream = self._tr.create_stream(self._sc)
+        self.assertEqual(stream.stream_class, self._sc)
 
-        # event context
-        ec = bt2.StructureFieldClass()
-        ec += OrderedDict((
-            ('ant', bt2.IntegerFieldClass(16, is_signed=True)),
-            ('msg', bt2.StringFieldClass()),
-        ))
+    def test_invalid_id(self):
+        sc = self._tc.create_stream_class(assigns_automatic_stream_id=False)
 
-        # event payload
-        ep = bt2.StructureFieldClass()
-        ep += OrderedDict((
-            ('giraffe', bt2.IntegerFieldClass(32)),
-            ('gnu', bt2.IntegerFieldClass(8)),
-            ('mosquito', bt2.IntegerFieldClass(8)),
-        ))
-
-        # event class
-        event_class = bt2.EventClass('ec')
-        event_class.context_field_class = ec
-        event_class.payload_field_class = ep
-        sc.add_event_class(event_class)
-
-        # packet header
-        ph = bt2.StructureFieldClass()
-        ph += OrderedDict((
-            ('magic', bt2.IntegerFieldClass(32)),
-            ('stream_id', bt2.IntegerFieldClass(16)),
-        ))
-
-        # trace c;ass
-        tc = bt2.Trace()
-        tc.packet_header_field_class = ph
-        tc.add_stream_class(sc)
-
-        # stream
-        return sc(name=name, id=stream_id)
-
-    def test_attr_stream_class(self):
-        self.assertIsNotNone(self._stream.stream_class)
-
-    def test_attr_name(self):
-        self.assertEqual(self._stream.name, 'my_stream')
-
-    def test_eq(self):
-        stream1 = self._create_stream(stream_id=17)
-        stream2 = self._create_stream(stream_id=17)
-        self.assertEqual(stream1, stream2)
-
-    def test_ne_name(self):
-        stream1 = self._create_stream(stream_id=17)
-        stream2 = self._create_stream('lel', 17)
-        self.assertNotEqual(stream1, stream2)
-
-    def test_ne_id(self):
-        stream1 = self._create_stream(stream_id=17)
-        stream2 = self._create_stream(stream_id=23)
-        self.assertNotEqual(stream1, stream2)
-
-    def test_eq_invalid(self):
-        self.assertFalse(self._stream == 23)
-
-    def _test_copy(self, func):
-        stream = self._create_stream()
-        cpy = func(stream)
-        self.assertIsNot(stream, cpy)
-        self.assertNotEqual(stream.addr, cpy.addr)
-        self.assertEqual(stream, cpy)
-
-    def test_copy(self):
-        self._test_copy(copy.copy)
-
-    def test_deepcopy(self):
-        self._test_copy(copy.deepcopy)
+        with self.assertRaises(TypeError):
+            self._tr.create_stream(sc, id='string')
This page took 0.024859 seconds and 4 git commands to generate.