bt2: Add `_Clock*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
af4bbfc7 20from utils import run_in_component_init
9cf643d1
PP
21
22
23class StreamTestCase(unittest.TestCase):
24 def setUp(self):
af4bbfc7
SM
25 def f(comp_self):
26 return comp_self._create_trace_class()
9cf643d1 27
af4bbfc7
SM
28 self._tc = run_in_component_init(f)
29 self._sc = self._tc.create_stream_class(assigns_automatic_stream_id=True)
30 self._tr = self._tc()
811644b8 31
af4bbfc7
SM
32 def test_create_default(self):
33 stream = self._tr.create_stream(self._sc)
34 self.assertIsNone(stream.name)
5783664e 35 self.assertEqual(len(stream.user_attributes), 0)
9cf643d1 36
af4bbfc7
SM
37 def test_name(self):
38 stream = self._tr.create_stream(self._sc, name='équidistant')
39 self.assertEqual(stream.name, 'équidistant')
9cf643d1 40
af4bbfc7
SM
41 def test_invalid_name(self):
42 with self.assertRaises(TypeError):
43 self._tr.create_stream(self._sc, name=22)
9cf643d1 44
5783664e
PP
45 def test_create_user_attributes(self):
46 stream = self._tr.create_stream(self._sc, user_attributes={'salut': 23})
47 self.assertEqual(stream.user_attributes, {'salut': 23})
48
49 def test_create_invalid_user_attributes(self):
50 with self.assertRaises(TypeError):
51 self._tr.create_stream(self._sc, user_attributes=object())
52
53 def test_create_invalid_user_attributes_value_type(self):
54 with self.assertRaises(TypeError):
55 self._tr.create_stream(self._sc, user_attributes=23)
56
af4bbfc7
SM
57 def test_stream_class(self):
58 stream = self._tr.create_stream(self._sc)
e8ac1aae 59 self.assertEqual(stream.cls, self._sc)
9cf643d1 60
e071d36f
FD
61 def test_trace(self):
62 stream = self._tr.create_stream(self._sc)
63 self.assertEqual(stream.trace.addr, self._tr.addr)
64
af4bbfc7
SM
65 def test_invalid_id(self):
66 sc = self._tc.create_stream_class(assigns_automatic_stream_id=False)
9cf643d1 67
af4bbfc7
SM
68 with self.assertRaises(TypeError):
69 self._tr.create_stream(sc, id='string')
This page took 0.047965 seconds and 4 git commands to generate.