bt2: add user attributes property support
[babeltrace.git] / tests / bindings / python / bt2 / test_event_class.py
index fdde035315658919711505a4a925dbf0d545843c..ffc10bc4bdac703635f5c24f442844f78906ec51 100644 (file)
@@ -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.
+#
+
 import unittest
 import bt2
 from utils import get_default_trace_class
@@ -9,12 +27,16 @@ class EventClassTestCase(unittest.TestCase):
 
         self._context_fc = self._tc.create_structure_field_class()
         self._context_fc.append_member('allo', self._tc.create_string_field_class())
-        self._context_fc.append_member('zola', self._tc.create_signed_integer_field_class(18))
+        self._context_fc.append_member(
+            'zola', self._tc.create_signed_integer_field_class(18)
+        )
 
         self._payload_fc = self._tc.create_structure_field_class()
         self._payload_fc.append_member('zoom', self._tc.create_string_field_class())
 
-        self._stream_class = self._tc.create_stream_class(assigns_automatic_event_class_id=True)
+        self._stream_class = self._tc.create_stream_class(
+            assigns_automatic_event_class_id=True
+        )
 
     def test_create_default(self):
         ec = self._stream_class.create_event_class()
@@ -25,6 +47,7 @@ class EventClassTestCase(unittest.TestCase):
         self.assertIsNone(ec.payload_field_class)
         self.assertIsNone(ec.emf_uri)
         self.assertIsNone(ec.log_level)
+        self.assertEqual(len(ec.user_attributes), 0)
 
     def test_create_invalid_id(self):
         sc = self._tc.create_stream_class(assigns_automatic_event_class_id=False)
@@ -66,13 +89,27 @@ class EventClassTestCase(unittest.TestCase):
             self._stream_class.create_event_class(emf_uri=23)
 
     def test_create_log_level(self):
-        ec = self._stream_class.create_event_class(log_level=bt2.EventClassLogLevel.EMERGENCY)
+        ec = self._stream_class.create_event_class(
+            log_level=bt2.EventClassLogLevel.EMERGENCY
+        )
         self.assertEqual(ec.log_level, bt2.EventClassLogLevel.EMERGENCY)
 
     def test_create_invalid_log_level(self):
         with self.assertRaises(ValueError):
             self._stream_class.create_event_class(log_level='zoom')
 
+    def test_create_user_attributes(self):
+        ec = self._stream_class.create_event_class(user_attributes={'salut': 23})
+        self.assertEqual(ec.user_attributes, {'salut': 23})
+
+    def test_create_invalid_user_attributes(self):
+        with self.assertRaises(TypeError):
+            self._stream_class.create_event_class(user_attributes=object())
+
+    def test_create_invalid_user_attributes_value_type(self):
+        with self.assertRaises(TypeError):
+            self._stream_class.create_event_class(user_attributes=23)
+
     def test_stream_class(self):
         ec = self._stream_class.create_event_class()
         self.assertEqual(ec.stream_class.addr, self._stream_class.addr)
This page took 0.025473 seconds and 4 git commands to generate.