bt2: Add remaining trace-ir `*Const` classes and adapt tests
[babeltrace.git] / tests / bindings / python / bt2 / test_stream.py
CommitLineData
d2d857a8
MJ
1#
2# Copyright (C) 2019 EfficiOS Inc.
3#
4# This program is free software; you can redistribute it and/or
5# modify it under the terms of the GNU General Public License
6# as published by the Free Software Foundation; only version 2
7# of the License.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17#
18
9cf643d1 19import unittest
f0a42b33 20import utils
af4bbfc7 21from utils import run_in_component_init
f0a42b33
FD
22from bt2 import trace as bt2_trace
23from bt2 import stream as bt2_stream
24from bt2 import value as bt2_value
25from bt2 import stream_class as bt2_stream_class
9cf643d1
PP
26
27
28class StreamTestCase(unittest.TestCase):
29 def setUp(self):
af4bbfc7
SM
30 def f(comp_self):
31 return comp_self._create_trace_class()
9cf643d1 32
af4bbfc7
SM
33 self._tc = run_in_component_init(f)
34 self._sc = self._tc.create_stream_class(assigns_automatic_stream_id=True)
35 self._tr = self._tc()
811644b8 36
af4bbfc7
SM
37 def test_create_default(self):
38 stream = self._tr.create_stream(self._sc)
39 self.assertIsNone(stream.name)
f0a42b33 40 self.assertIs(type(stream), bt2_stream._Stream)
5783664e 41 self.assertEqual(len(stream.user_attributes), 0)
9cf643d1 42
af4bbfc7
SM
43 def test_name(self):
44 stream = self._tr.create_stream(self._sc, name='équidistant')
45 self.assertEqual(stream.name, 'équidistant')
9cf643d1 46
af4bbfc7
SM
47 def test_invalid_name(self):
48 with self.assertRaises(TypeError):
49 self._tr.create_stream(self._sc, name=22)
9cf643d1 50
5783664e
PP
51 def test_create_user_attributes(self):
52 stream = self._tr.create_stream(self._sc, user_attributes={'salut': 23})
53 self.assertEqual(stream.user_attributes, {'salut': 23})
f0a42b33
FD
54 self.assertIs(type(stream.user_attributes), bt2_value.MapValue)
55
56 def test_const_user_attributes(self):
57 stream = utils.get_const_stream_beginning_message().stream
58 self.assertEqual(stream.user_attributes, {'salut': 23})
59 self.assertIs(type(stream.user_attributes), bt2_value._MapValueConst)
5783664e
PP
60
61 def test_create_invalid_user_attributes(self):
62 with self.assertRaises(TypeError):
63 self._tr.create_stream(self._sc, user_attributes=object())
64
65 def test_create_invalid_user_attributes_value_type(self):
66 with self.assertRaises(TypeError):
67 self._tr.create_stream(self._sc, user_attributes=23)
68
af4bbfc7
SM
69 def test_stream_class(self):
70 stream = self._tr.create_stream(self._sc)
e8ac1aae 71 self.assertEqual(stream.cls, self._sc)
f0a42b33
FD
72 self.assertIs(type(stream.cls), bt2_stream_class._StreamClass)
73
74 def test_const_stream_class(self):
75 stream = utils.get_const_stream_beginning_message().stream
76 self.assertIs(type(stream.cls), bt2_stream_class._StreamClassConst)
9cf643d1 77
e071d36f
FD
78 def test_trace(self):
79 stream = self._tr.create_stream(self._sc)
80 self.assertEqual(stream.trace.addr, self._tr.addr)
f0a42b33
FD
81 self.assertIs(type(stream.trace), bt2_trace._Trace)
82
83 def test_const_trace(self):
84 stream = utils.get_const_stream_beginning_message().stream
85 self.assertIs(type(stream.trace), bt2_trace._TraceConst)
e071d36f 86
af4bbfc7
SM
87 def test_invalid_id(self):
88 sc = self._tc.create_stream_class(assigns_automatic_stream_id=False)
9cf643d1 89
af4bbfc7
SM
90 with self.assertRaises(TypeError):
91 self._tr.create_stream(sc, id='string')
This page took 0.04901 seconds and 4 git commands to generate.