Commit | Line | Data |
---|---|---|
0235b0db | 1 | # SPDX-License-Identifier: GPL-2.0-only |
d2d857a8 MJ |
2 | # |
3 | # Copyright (C) 2019 EfficiOS Inc. | |
4 | # | |
d2d857a8 | 5 | |
9cf643d1 | 6 | import unittest |
f0a42b33 | 7 | import utils |
af4bbfc7 | 8 | from utils import run_in_component_init |
f0a42b33 FD |
9 | from bt2 import trace as bt2_trace |
10 | from bt2 import stream as bt2_stream | |
11 | from bt2 import value as bt2_value | |
12 | from bt2 import stream_class as bt2_stream_class | |
9cf643d1 PP |
13 | |
14 | ||
15 | class StreamTestCase(unittest.TestCase): | |
16 | def setUp(self): | |
af4bbfc7 SM |
17 | def f(comp_self): |
18 | return comp_self._create_trace_class() | |
9cf643d1 | 19 | |
af4bbfc7 SM |
20 | self._tc = run_in_component_init(f) |
21 | self._sc = self._tc.create_stream_class(assigns_automatic_stream_id=True) | |
22 | self._tr = self._tc() | |
811644b8 | 23 | |
af4bbfc7 SM |
24 | def test_create_default(self): |
25 | stream = self._tr.create_stream(self._sc) | |
26 | self.assertIsNone(stream.name) | |
f0a42b33 | 27 | self.assertIs(type(stream), bt2_stream._Stream) |
5783664e | 28 | self.assertEqual(len(stream.user_attributes), 0) |
9cf643d1 | 29 | |
af4bbfc7 SM |
30 | def test_name(self): |
31 | stream = self._tr.create_stream(self._sc, name='équidistant') | |
32 | self.assertEqual(stream.name, 'équidistant') | |
9cf643d1 | 33 | |
af4bbfc7 SM |
34 | def test_invalid_name(self): |
35 | with self.assertRaises(TypeError): | |
36 | self._tr.create_stream(self._sc, name=22) | |
9cf643d1 | 37 | |
5783664e PP |
38 | def test_create_user_attributes(self): |
39 | stream = self._tr.create_stream(self._sc, user_attributes={'salut': 23}) | |
40 | self.assertEqual(stream.user_attributes, {'salut': 23}) | |
f0a42b33 FD |
41 | self.assertIs(type(stream.user_attributes), bt2_value.MapValue) |
42 | ||
43 | def test_const_user_attributes(self): | |
44 | stream = utils.get_const_stream_beginning_message().stream | |
45 | self.assertEqual(stream.user_attributes, {'salut': 23}) | |
46 | self.assertIs(type(stream.user_attributes), bt2_value._MapValueConst) | |
5783664e PP |
47 | |
48 | def test_create_invalid_user_attributes(self): | |
49 | with self.assertRaises(TypeError): | |
50 | self._tr.create_stream(self._sc, user_attributes=object()) | |
51 | ||
52 | def test_create_invalid_user_attributes_value_type(self): | |
53 | with self.assertRaises(TypeError): | |
54 | self._tr.create_stream(self._sc, user_attributes=23) | |
55 | ||
af4bbfc7 SM |
56 | def test_stream_class(self): |
57 | stream = self._tr.create_stream(self._sc) | |
e8ac1aae | 58 | self.assertEqual(stream.cls, self._sc) |
f0a42b33 FD |
59 | self.assertIs(type(stream.cls), bt2_stream_class._StreamClass) |
60 | ||
61 | def test_const_stream_class(self): | |
62 | stream = utils.get_const_stream_beginning_message().stream | |
63 | self.assertIs(type(stream.cls), bt2_stream_class._StreamClassConst) | |
9cf643d1 | 64 | |
e071d36f FD |
65 | def test_trace(self): |
66 | stream = self._tr.create_stream(self._sc) | |
67 | self.assertEqual(stream.trace.addr, self._tr.addr) | |
f0a42b33 FD |
68 | self.assertIs(type(stream.trace), bt2_trace._Trace) |
69 | ||
70 | def test_const_trace(self): | |
71 | stream = utils.get_const_stream_beginning_message().stream | |
72 | self.assertIs(type(stream.trace), bt2_trace._TraceConst) | |
e071d36f | 73 | |
af4bbfc7 SM |
74 | def test_invalid_id(self): |
75 | sc = self._tc.create_stream_class(assigns_automatic_stream_id=False) | |
9cf643d1 | 76 | |
af4bbfc7 SM |
77 | with self.assertRaises(TypeError): |
78 | self._tr.create_stream(sc, id='string') | |
d14ddbba SM |
79 | |
80 | ||
81 | if __name__ == '__main__': | |
82 | unittest.main() |