- self._ec.payload_field_type = 'lel'
-
- def test_stream_class_prop_no_sc(self):
- self.assertIsNone(self._ec.stream_class)
-
- def test_stream_class_prop(self):
- sc = bt2.StreamClass()
- sc.add_event_class(self._ec)
- self.assertEqual(self._ec.stream_class.addr, sc.addr)
-
- def _test_copy(self, cpy):
- self.assertIsNot(cpy, self._ec)
- self.assertNotEqual(cpy.addr, self._ec.addr)
- self.assertEqual(cpy, self._ec)
-
- def test_copy(self):
- cpy = copy.copy(self._ec)
- self._test_copy(cpy)
- self.assertEqual(self._ec.context_field_type.addr, cpy.context_field_type.addr)
- self.assertEqual(self._ec.payload_field_type.addr, cpy.payload_field_type.addr)
-
- def test_deepcopy(self):
- cpy = copy.deepcopy(self._ec)
- self._test_copy(cpy)
- self.assertNotEqual(self._ec.context_field_type.addr, cpy.context_field_type.addr)
- self.assertNotEqual(self._ec.payload_field_type.addr, cpy.payload_field_type.addr)
-
- def test_attr_getitem(self):
- self.assertEqual(self._ec.attributes['id'], 18)
- self.assertEqual(self._ec.attributes['name'], 'my_event')
-
- def test_attr_setitem(self):
- self._ec.attributes['model.emf.uri'] = 'my url'
- self.assertEqual(self._ec.attributes['model.emf.uri'], 'my url')
-
- def test_attr_len(self):
- self.assertTrue(len(self._ec.attributes) != 0)
-
- def test_attr_iter(self):
- for name, value in self._ec.attributes.items():
- self.assertIsInstance(value, values._Value)
-
- if name == 'name':
- self.assertEqual(value, 'my_event')
- elif name == 'id':
- self.assertEqual(value, 18)
-
- def test_eq(self):
- ec1 = bt2.EventClass(name='name', id=23,
- context_field_type=self._context_ft,
- payload_field_type=self._payload_ft,
- attributes={'model.emf.uri': 'my URI'})
- ec2 = bt2.EventClass(name='name', id=23,
- context_field_type=self._context_ft,
- payload_field_type=self._payload_ft,
- attributes={'model.emf.uri': 'my URI'})
- self.assertEqual(ec1, ec2)
-
- def test_ne_name(self):
- ec1 = bt2.EventClass(name='name1', id=23,
- context_field_type=self._context_ft,
- payload_field_type=self._payload_ft,
- attributes={'model.emf.uri': 'my URI'})
- ec2 = bt2.EventClass(name='name', id=23,
- context_field_type=self._context_ft,
- payload_field_type=self._payload_ft,
- attributes={'model.emf.uri': 'my URI'})
- self.assertNotEqual(ec1, ec2)
-
- def test_ne_id(self):
- ec1 = bt2.EventClass(name='name', id=24,
- context_field_type=self._context_ft,
- payload_field_type=self._payload_ft,
- attributes={'model.emf.uri': 'my URI'})
- ec2 = bt2.EventClass(name='name', id=23,
- context_field_type=self._context_ft,
- payload_field_type=self._payload_ft,
- attributes={'model.emf.uri': 'my URI'})
- self.assertNotEqual(ec1, ec2)
-
- def test_ne_context_field_type(self):
- ec1 = bt2.EventClass(name='name', id=23,
- context_field_type=self._payload_ft,
- payload_field_type=self._payload_ft,
- attributes={'model.emf.uri': 'my URI'})
- ec2 = bt2.EventClass(name='name', id=23,
- context_field_type=self._context_ft,
- payload_field_type=self._payload_ft,
- attributes={'model.emf.uri': 'my URI'})
- self.assertNotEqual(ec1, ec2)
-
- def test_ne_payload_field_type(self):
- ec1 = bt2.EventClass(name='name', id=23,
- context_field_type=self._context_ft,
- payload_field_type=self._context_ft,
- attributes={'model.emf.uri': 'my URI'})
- ec2 = bt2.EventClass(name='name', id=23,
- context_field_type=self._context_ft,
- payload_field_type=self._payload_ft,
- attributes={'model.emf.uri': 'my URI'})
- self.assertNotEqual(ec1, ec2)
-
- def test_ne_attribute(self):
- ec1 = bt2.EventClass(name='name', id=23,
- context_field_type=self._context_ft,
- payload_field_type=self._payload_ft,
- attributes={'model.emf.uri': 'my URI'})
- ec2 = bt2.EventClass(name='name', id=23,
- context_field_type=self._context_ft,
- payload_field_type=self._payload_ft,
- attributes={'model.emf.uri': 'my UR'})
- self.assertNotEqual(ec1, ec2)
-
- def test_eq_invalid(self):
- self.assertFalse(self._ec == 23)
+ self._stream_class.create_event_class(emf_uri=23)
+
+ self.assertEqual(len(self._stream_class), 0)
+
+ def test_create_log_level(self):
+ 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')
+
+ self.assertEqual(len(self._stream_class), 0)
+
+ def test_create_user_attributes(self):
+ ec = self._stream_class.create_event_class(user_attributes={'salut': 23})
+ self.assertEqual(ec.user_attributes, {'salut': 23})
+ self.assertIs(type(ec.user_attributes), bt2_value.MapValue)
+
+ def test_const_create_user_attributes(self):
+ ec_const = _create_const_event_class(self._tc, self._stream_class)
+ self.assertIs(type(ec_const.user_attributes), bt2_value._MapValueConst)
+
+ def test_create_invalid_user_attributes(self):
+ with self.assertRaises(TypeError):
+ self._stream_class.create_event_class(user_attributes=object())
+
+ self.assertEqual(len(self._stream_class), 0)
+
+ def test_create_invalid_user_attributes_value_type(self):
+ with self.assertRaises(TypeError):
+ self._stream_class.create_event_class(user_attributes=23)
+
+ self.assertEqual(len(self._stream_class), 0)
+
+ def test_stream_class(self):
+ ec = self._stream_class.create_event_class()
+ self.assertEqual(ec.stream_class.addr, self._stream_class.addr)
+ self.assertIs(type(ec.stream_class), bt2_stream_class._StreamClass)
+
+ def test_const_stream_class(self):
+ ec_const = _create_const_event_class(self._tc, self._stream_class)
+ self.assertIs(type(ec_const.stream_class), bt2_stream_class._StreamClassConst)
+
+
+if __name__ == '__main__':
+ unittest.main()