bt2: Adapt test_field_class.py and make it pass
[babeltrace.git] / tests / bindings / python / bt2 / test_event_class.py
CommitLineData
9cf643d1 1import unittest
9cf643d1 2import bt2
65531d55 3from utils import get_default_trace_class
9cf643d1
PP
4
5
6class EventClassTestCase(unittest.TestCase):
7 def setUp(self):
65531d55
SM
8 self._tc = get_default_trace_class()
9
10 self._context_fc = self._tc.create_structure_field_class()
d47b87ac
SM
11 self._context_fc.append_member('allo', self._tc.create_string_field_class())
12 self._context_fc.append_member('zola', self._tc.create_signed_integer_field_class(18))
65531d55
SM
13
14 self._payload_fc = self._tc.create_structure_field_class()
d47b87ac 15 self._payload_fc.append_member('zoom', self._tc.create_string_field_class())
9cf643d1 16
65531d55 17 self._stream_class = self._tc.create_stream_class(assigns_automatic_event_class_id=True)
9cf643d1 18
65531d55
SM
19 def test_create_default(self):
20 ec = self._stream_class.create_event_class()
9cf643d1 21
65531d55
SM
22 self.assertIsNone(ec.name, 'my_event')
23 self.assertTrue(type(ec.id), int)
24 self.assertIsNone(ec.specific_context_field_class)
25 self.assertIsNone(ec.payload_field_class)
26 self.assertIsNone(ec.emf_uri)
27 self.assertIsNone(ec.log_level)
28
29 def test_create_invalid_id(self):
30 sc = self._tc.create_stream_class(assigns_automatic_event_class_id=False)
9cf643d1 31 with self.assertRaises(TypeError):
65531d55
SM
32 sc.create_event_class(id='lel')
33
34 def test_create_specific_context_field_class(self):
35 fc = self._tc.create_structure_field_class()
36 ec = self._stream_class.create_event_class(specific_context_field_class=fc)
37 self.assertEqual(ec.specific_context_field_class.addr, fc.addr)
9cf643d1 38
65531d55
SM
39 def test_create_invalid_specific_context_field_class(self):
40 with self.assertRaises(TypeError):
41 self._stream_class.create_event_class(specific_context_field_class='lel')
9cf643d1 42
65531d55
SM
43 def test_create_payload_field_class(self):
44 fc = self._tc.create_structure_field_class()
45 ec = self._stream_class.create_event_class(payload_field_class=fc)
46 self.assertEqual(ec.payload_field_class.addr, fc.addr)
9cf643d1 47
65531d55 48 def test_create_invalid_payload_field_class(self):
9cf643d1 49 with self.assertRaises(TypeError):
65531d55
SM
50 self._stream_class.create_event_class(payload_field_class='lel')
51
52 def test_create_name(self):
53 ec = self._stream_class.create_event_class(name='viande à chien')
54 self.assertEqual(ec.name, 'viande à chien')
55
56 def test_create_invalid_name(self):
57 with self.assertRaises(TypeError):
58 self._stream_class.create_event_class(name=2)
59
60 def test_emf_uri(self):
61 ec = self._stream_class.create_event_class(emf_uri='salut')
62 self.assertEqual(ec.emf_uri, 'salut')
63
64 def test_create_invalid_emf_uri(self):
811644b8 65 with self.assertRaises(TypeError):
65531d55 66 self._stream_class.create_event_class(emf_uri=23)
9cf643d1 67
65531d55
SM
68 def test_create_log_level(self):
69 ec = self._stream_class.create_event_class(log_level=bt2.EventClassLogLevel.EMERGENCY)
70 self.assertEqual(ec.log_level, bt2.EventClassLogLevel.EMERGENCY)
9cf643d1 71
65531d55 72 def test_create_invalid_log_level(self):
811644b8 73 with self.assertRaises(ValueError):
65531d55
SM
74 self._stream_class.create_event_class(log_level='zoom')
75
76 def test_stream_class(self):
77 ec = self._stream_class.create_event_class()
78 self.assertEqual(ec.stream_class.addr, self._stream_class.addr)
This page took 0.039871 seconds and 4 git commands to generate.