bt2: Add `_Clock*Const` classes and adapt tests
[babeltrace.git] / tests / bindings / python / bt2 / test_trace_class.py
index b36dafa1a1023d77aa73beec8657f5f330600e22..168ae86367992d7a61a7ea5837ce7ad0cc0eeb0c 100644 (file)
@@ -1,10 +1,36 @@
-import uuid
+#
+# 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 bt2
 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):
@@ -13,17 +39,27 @@ class TraceClassTestCase(unittest.TestCase):
         tc = run_in_component_init(f)
 
         self.assertEqual(len(tc), 0)
-        self.assertEqual(len(tc.env), 0)
-        self.assertIsNone(tc.uuid)
         self.assertTrue(tc.assigns_automatic_stream_class_id)
+        self.assertEqual(len(tc.user_attributes), 0)
 
-    def test_uuid(self):
+    def test_create_user_attributes(self):
         def f(comp_self):
-            return comp_self._create_trace_class(uuid=uuid.UUID('da7d6b6f-3108-4706-89bd-ab554732611b'))
+            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.assertEqual(tc.uuid, uuid.UUID('da7d6b6f-3108-4706-89bd-ab554732611b'))
+        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):
@@ -46,11 +82,13 @@ 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):
-            return comp_self._create_trace_class(assigns_automatic_stream_class_id=False)
+            return comp_self._create_trace_class(
+                assigns_automatic_stream_class_id=False
+            )
 
         tc = run_in_component_init(f)
         self.assertFalse(tc.assigns_automatic_stream_class_id)
@@ -60,7 +98,9 @@ class TraceClassTestCase(unittest.TestCase):
 
     def test_no_assigns_automatic_stream_class_id_raises(self):
         def f(comp_self):
-            return comp_self._create_trace_class(assigns_automatic_stream_class_id=False)
+            return comp_self._create_trace_class(
+                assigns_automatic_stream_class_id=False
+            )
 
         tc = run_in_component_init(f)
         self.assertFalse(tc.assigns_automatic_stream_class_id)
@@ -69,28 +109,12 @@ class TraceClassTestCase(unittest.TestCase):
         with self.assertRaises(ValueError):
             tc.create_stream_class()
 
-    def test_env_get(self):
-        def f(comp_self):
-            return comp_self._create_trace_class(env={'hello': 'you', 'foo': -5})
-
-        tc = run_in_component_init(f)
-
-        self.assertEqual(tc.env['hello'], 'you')
-        self.assertEqual(tc.env['foo'], -5)
-
-    def test_env_get_non_existent(self):
-        def f(comp_self):
-            return comp_self._create_trace_class(env={'hello': 'you', 'foo': -5})
-
-        tc = run_in_component_init(f)
-
-        with self.assertRaises(KeyError):
-            tc.env['lel']
-
     @staticmethod
     def _create_trace_class_with_some_stream_classes():
         def f(comp_self):
-            return comp_self._create_trace_class(assigns_automatic_stream_class_id=False)
+            return comp_self._create_trace_class(
+                assigns_automatic_stream_class_id=False
+            )
 
         tc = run_in_component_init(f)
         sc1 = tc.create_stream_class(id=12)
@@ -122,8 +146,6 @@ class TraceClassTestCase(unittest.TestCase):
         tc, sc1, sc2, sc3 = self._create_trace_class_with_some_stream_classes()
 
         for sc_id, stream_class in tc.items():
-            self.assertIsInstance(stream_class, bt2.stream_class._StreamClass)
-
             if sc_id == 12:
                 self.assertEqual(stream_class.addr, sc1.addr)
             elif sc_id == 54:
This page took 0.025213 seconds and 4 git commands to generate.