Move to kernel style SPDX license identifiers
[babeltrace.git] / tests / bindings / python / bt2 / test_component.py
CommitLineData
0235b0db 1# SPDX-License-Identifier: GPL-2.0-only
d2d857a8
MJ
2#
3# Copyright (C) 2019 EfficiOS Inc.
4#
d2d857a8 5
811644b8 6import unittest
811644b8 7import bt2
59225a3e 8from bt2 import component as bt2_component
811644b8
PP
9
10
11class UserComponentTestCase(unittest.TestCase):
12 @staticmethod
e6090a23 13 def _create_comp(comp_cls, name=None, log_level=bt2.LoggingLevel.NONE):
811644b8
PP
14 graph = bt2.Graph()
15
16 if name is None:
17 name = 'comp'
18
e6090a23 19 return graph.add_component(comp_cls, name, logging_level=log_level)
811644b8
PP
20
21 def test_name(self):
22 class MySink(bt2._UserSinkComponent):
59225a3e 23 def __init__(comp_self, config, params, obj):
811644b8
PP
24 self.assertEqual(comp_self.name, 'yaes')
25
6a91742b 26 def _user_consume(self):
a01b452b
SM
27 pass
28
082db648 29 self._create_comp(MySink, 'yaes')
811644b8 30
e6090a23
PP
31 def test_logging_level(self):
32 class MySink(bt2._UserSinkComponent):
59225a3e 33 def __init__(comp_self, config, params, obj):
e6090a23
PP
34 self.assertEqual(comp_self.logging_level, bt2.LoggingLevel.INFO)
35
6a91742b 36 def _user_consume(self):
a01b452b
SM
37 pass
38
082db648 39 self._create_comp(MySink, 'yaes', bt2.LoggingLevel.INFO)
e6090a23 40
056deb59
PP
41 def test_graph_mip_version(self):
42 class MySink(bt2._UserSinkComponent):
59225a3e 43 def __init__(comp_self, config, params, obj):
056deb59
PP
44 self.assertEqual(comp_self._graph_mip_version, 0)
45
46 def _user_consume(self):
47 pass
48
082db648 49 self._create_comp(MySink, 'yaes', bt2.LoggingLevel.INFO)
056deb59 50
811644b8
PP
51 def test_class(self):
52 class MySink(bt2._UserSinkComponent):
59225a3e 53 def __init__(comp_self, config, params, obj):
e8ac1aae 54 self.assertEqual(comp_self.cls, MySink)
811644b8 55
6a91742b 56 def _user_consume(self):
a01b452b
SM
57 pass
58
811644b8
PP
59 self._create_comp(MySink)
60
61 def test_addr(self):
62 class MySink(bt2._UserSinkComponent):
59225a3e 63 def __init__(comp_self, config, params, obj):
811644b8
PP
64 self.assertIsInstance(comp_self.addr, int)
65 self.assertNotEqual(comp_self.addr, 0)
66
6a91742b 67 def _user_consume(self):
a01b452b
SM
68 pass
69
811644b8
PP
70 self._create_comp(MySink)
71
72 def test_finalize(self):
73 finalized = False
74
75 class MySink(bt2._UserSinkComponent):
6a91742b 76 def _user_consume(self):
a01b452b
SM
77 pass
78
6a91742b 79 def _user_finalize(comp_self):
811644b8
PP
80 nonlocal finalized
81 finalized = True
82
83 graph = bt2.Graph()
894a8df5 84 comp = graph.add_component(MySink, 'lel')
1c9ed2ff 85
811644b8
PP
86 del graph
87 del comp
88 self.assertTrue(finalized)
89
59225a3e
SM
90 def test_source_component_config(self):
91 class MySource(
92 bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator
93 ):
94 def __init__(comp_self, config, params, obj):
95 nonlocal cfg_type
96 cfg_type = type(config)
97
98 cfg_type = None
99 self._create_comp(MySource)
100 self.assertIs(cfg_type, bt2_component._UserSourceComponentConfiguration)
101
102 def test_filter_component_config(self):
103 class MyFilter(
104 bt2._UserFilterComponent, message_iterator_class=bt2._UserMessageIterator
105 ):
106 def __init__(comp_self, config, params, obj):
107 nonlocal cfg_type
108 cfg_type = type(config)
109
110 cfg_type = None
111 self._create_comp(MyFilter)
112 self.assertIs(cfg_type, bt2_component._UserFilterComponentConfiguration)
113
114 def test_sink_component_config(self):
115 class MySink(bt2._UserSinkComponent):
116 def __init__(comp_self, config, params, obj):
117 nonlocal cfg_type
118 cfg_type = type(config)
119
120 def _user_consume(self):
121 pass
122
123 cfg_type = None
124 self._create_comp(MySink)
125 self.assertIs(cfg_type, bt2_component._UserSinkComponentConfiguration)
126
811644b8
PP
127
128class GenericComponentTestCase(unittest.TestCase):
129 @staticmethod
e6090a23 130 def _create_comp(comp_cls, name=None, log_level=bt2.LoggingLevel.NONE):
811644b8
PP
131 graph = bt2.Graph()
132
133 if name is None:
134 name = 'comp'
135
e6090a23 136 return graph.add_component(comp_cls, name, logging_level=log_level)
811644b8
PP
137
138 def test_name(self):
139 class MySink(bt2._UserSinkComponent):
6a91742b 140 def _user_consume(self):
a01b452b
SM
141 pass
142
811644b8
PP
143 comp = self._create_comp(MySink, 'yaes')
144 self.assertEqual(comp.name, 'yaes')
145
e6090a23
PP
146 def test_logging_level(self):
147 class MySink(bt2._UserSinkComponent):
6a91742b 148 def _user_consume(self):
a01b452b
SM
149 pass
150
770538dd
PP
151 comp = self._create_comp(MySink, 'yaes', bt2.LoggingLevel.WARNING)
152 self.assertEqual(comp.logging_level, bt2.LoggingLevel.WARNING)
e6090a23 153
811644b8
PP
154 def test_class(self):
155 class MySink(bt2._UserSinkComponent):
6a91742b 156 def _user_consume(self):
a01b452b
SM
157 pass
158
811644b8 159 comp = self._create_comp(MySink)
e8ac1aae 160 self.assertEqual(comp.cls, MySink)
811644b8
PP
161
162 def test_addr(self):
163 class MySink(bt2._UserSinkComponent):
6a91742b 164 def _user_consume(self):
a01b452b
SM
165 pass
166
811644b8
PP
167 comp = self._create_comp(MySink)
168 self.assertIsInstance(comp.addr, int)
169 self.assertNotEqual(comp.addr, 0)
d14ddbba
SM
170
171
172if __name__ == '__main__':
173 unittest.main()
This page took 0.059546 seconds and 4 git commands to generate.