bt2: Mass field_types -> field_class rename
[babeltrace.git] / tests / bindings / python / bt2 / test_stream.py
CommitLineData
9cf643d1
PP
1from collections import OrderedDict
2from bt2 import values
3import unittest
4import copy
5import bt2
6
7
90cfc012 8@unittest.skip("this is broken")
9cf643d1
PP
9class StreamTestCase(unittest.TestCase):
10 def setUp(self):
f6a5e476 11 self._stream = self._create_stream(stream_id=23)
9cf643d1 12
f6a5e476
PP
13 def tearDown(self):
14 del self._stream
15
16 def _create_stream(self, name='my_stream', stream_id=None):
9cf643d1 17 # event header
32656995 18 eh = bt2.StructureFieldClass()
9cf643d1 19 eh += OrderedDict((
32656995
SM
20 ('id', bt2.IntegerFieldClass(8)),
21 ('ts', bt2.IntegerFieldClass(32)),
9cf643d1
PP
22 ))
23
24 # stream event context
32656995 25 sec = bt2.StructureFieldClass()
9cf643d1 26 sec += OrderedDict((
32656995
SM
27 ('cpu_id', bt2.IntegerFieldClass(8)),
28 ('stuff', bt2.FloatingPointNumberFieldClass()),
9cf643d1
PP
29 ))
30
31 # packet context
32656995 32 pc = bt2.StructureFieldClass()
9cf643d1 33 pc += OrderedDict((
32656995
SM
34 ('something', bt2.IntegerFieldClass(8)),
35 ('something_else', bt2.FloatingPointNumberFieldClass()),
9cf643d1
PP
36 ))
37
38 # stream class
39 sc = bt2.StreamClass()
32656995
SM
40 sc.packet_context_field_class = pc
41 sc.event_header_field_class = eh
42 sc.event_context_field_class = sec
9cf643d1
PP
43
44 # event context
32656995 45 ec = bt2.StructureFieldClass()
9cf643d1 46 ec += OrderedDict((
32656995
SM
47 ('ant', bt2.IntegerFieldClass(16, is_signed=True)),
48 ('msg', bt2.StringFieldClass()),
9cf643d1
PP
49 ))
50
51 # event payload
32656995 52 ep = bt2.StructureFieldClass()
9cf643d1 53 ep += OrderedDict((
32656995
SM
54 ('giraffe', bt2.IntegerFieldClass(32)),
55 ('gnu', bt2.IntegerFieldClass(8)),
56 ('mosquito', bt2.IntegerFieldClass(8)),
9cf643d1
PP
57 ))
58
59 # event class
60 event_class = bt2.EventClass('ec')
32656995
SM
61 event_class.context_field_class = ec
62 event_class.payload_field_class = ep
9cf643d1
PP
63 sc.add_event_class(event_class)
64
65 # packet header
32656995 66 ph = bt2.StructureFieldClass()
9cf643d1 67 ph += OrderedDict((
32656995
SM
68 ('magic', bt2.IntegerFieldClass(32)),
69 ('stream_id', bt2.IntegerFieldClass(16)),
9cf643d1
PP
70 ))
71
72 # trace c;ass
73 tc = bt2.Trace()
32656995 74 tc.packet_header_field_class = ph
9cf643d1
PP
75 tc.add_stream_class(sc)
76
77 # stream
f6a5e476 78 return sc(name=name, id=stream_id)
9cf643d1
PP
79
80 def test_attr_stream_class(self):
81 self.assertIsNotNone(self._stream.stream_class)
82
83 def test_attr_name(self):
84 self.assertEqual(self._stream.name, 'my_stream')
85
86 def test_eq(self):
f6a5e476
PP
87 stream1 = self._create_stream(stream_id=17)
88 stream2 = self._create_stream(stream_id=17)
9cf643d1
PP
89 self.assertEqual(stream1, stream2)
90
91 def test_ne_name(self):
f6a5e476
PP
92 stream1 = self._create_stream(stream_id=17)
93 stream2 = self._create_stream('lel', 17)
94 self.assertNotEqual(stream1, stream2)
95
96 def test_ne_id(self):
97 stream1 = self._create_stream(stream_id=17)
98 stream2 = self._create_stream(stream_id=23)
9cf643d1
PP
99 self.assertNotEqual(stream1, stream2)
100
101 def test_eq_invalid(self):
102 self.assertFalse(self._stream == 23)
103
104 def _test_copy(self, func):
105 stream = self._create_stream()
106 cpy = func(stream)
107 self.assertIsNot(stream, cpy)
108 self.assertNotEqual(stream.addr, cpy.addr)
109 self.assertEqual(stream, cpy)
110
111 def test_copy(self):
112 self._test_copy(copy.copy)
113
114 def test_deepcopy(self):
115 self._test_copy(copy.deepcopy)
This page took 0.039829 seconds and 4 git commands to generate.