rename `babeltrace.trace-info` to `babeltrace.trace-infos`, `streams` to `stream...
[babeltrace.git] / tests / bindings / python / bt2 / test_trace_class.py
index 97ede58424d8e1499b29dda3206a81b126d34579..168ae86367992d7a61a7ea5837ce7ad0cc0eeb0c 100644 (file)
@@ -21,6 +21,17 @@ from utils import run_in_component_init, get_default_trace_class
 
 
 class TraceClassTestCase(unittest.TestCase):
+    def assertRaisesInComponentInit(self, expected_exc_type, user_code):
+        def f(comp_self):
+            try:
+                user_code(comp_self)
+            except Exception as exc:
+                return type(exc)
+
+        exc_type = run_in_component_init(f)
+        self.assertIsNotNone(exc_type)
+        self.assertEqual(exc_type, expected_exc_type)
+
     def test_create_default(self):
         def f(comp_self):
             return comp_self._create_trace_class()
@@ -29,6 +40,26 @@ class TraceClassTestCase(unittest.TestCase):
 
         self.assertEqual(len(tc), 0)
         self.assertTrue(tc.assigns_automatic_stream_class_id)
+        self.assertEqual(len(tc.user_attributes), 0)
+
+    def test_create_user_attributes(self):
+        def f(comp_self):
+            return comp_self._create_trace_class(user_attributes={'salut': 23})
+
+        tc = run_in_component_init(f)
+        self.assertEqual(tc.user_attributes, {'salut': 23})
+
+    def test_create_invalid_user_attributes(self):
+        def f(comp_self):
+            return comp_self._create_trace_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_trace_class(user_attributes=23)
+
+        self.assertRaisesInComponentInit(TypeError, f)
 
     def test_automatic_stream_class_id(self):
         def f(comp_self):
@@ -51,7 +82,7 @@ class TraceClassTestCase(unittest.TestCase):
         self.assertTrue(tc.assigns_automatic_stream_class_id)
 
         with self.assertRaises(ValueError):
-            sc1 = tc.create_stream_class(23)
+            tc.create_stream_class(23)
 
     def test_no_assigns_automatic_stream_class_id(self):
         def f(comp_self):
This page took 0.023736 seconds and 4 git commands to generate.