bt2: check for _graph_is_configured method in user sink classes
[babeltrace.git] / tests / bindings / python / bt2 / test_component.py
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
19 from bt2 import value
20 import unittest
21 import copy
22 import bt2
23
24
25 class UserComponentTestCase(unittest.TestCase):
26 @staticmethod
27 def _create_comp(comp_cls, name=None, log_level=bt2.LoggingLevel.NONE):
28 graph = bt2.Graph()
29
30 if name is None:
31 name = 'comp'
32
33 return graph.add_component(comp_cls, name, logging_level=log_level)
34
35 def test_name(self):
36 class MySink(bt2._UserSinkComponent):
37 def __init__(comp_self, params):
38 self.assertEqual(comp_self.name, 'yaes')
39
40 def _consume(self):
41 pass
42
43 def _graph_is_configured(self):
44 pass
45
46 comp = self._create_comp(MySink, 'yaes')
47
48 def test_logging_level(self):
49 class MySink(bt2._UserSinkComponent):
50 def __init__(comp_self, params):
51 self.assertEqual(comp_self.logging_level, bt2.LoggingLevel.INFO)
52
53 def _consume(self):
54 pass
55
56 def _graph_is_configured(self):
57 pass
58
59 comp = self._create_comp(MySink, 'yaes', bt2.LoggingLevel.INFO)
60
61 def test_class(self):
62 class MySink(bt2._UserSinkComponent):
63 def __init__(comp_self, params):
64 self.assertEqual(comp_self.cls, MySink)
65
66 def _consume(self):
67 pass
68
69 def _graph_is_configured(self):
70 pass
71
72 self._create_comp(MySink)
73
74 def test_addr(self):
75 class MySink(bt2._UserSinkComponent):
76 def __init__(comp_self, params):
77 self.assertIsInstance(comp_self.addr, int)
78 self.assertNotEqual(comp_self.addr, 0)
79
80 def _consume(self):
81 pass
82
83 def _graph_is_configured(self):
84 pass
85
86 self._create_comp(MySink)
87
88 def test_finalize(self):
89 finalized = False
90
91 class MySink(bt2._UserSinkComponent):
92 def _consume(self):
93 pass
94
95 def _graph_is_configured(self):
96 pass
97
98 def _finalize(comp_self):
99 nonlocal finalized
100 finalized = True
101
102 graph = bt2.Graph()
103 comp = graph.add_component(MySink, 'lel')
104
105 del graph
106 del comp
107 self.assertTrue(finalized)
108
109
110 class GenericComponentTestCase(unittest.TestCase):
111 @staticmethod
112 def _create_comp(comp_cls, name=None, log_level=bt2.LoggingLevel.NONE):
113 graph = bt2.Graph()
114
115 if name is None:
116 name = 'comp'
117
118 return graph.add_component(comp_cls, name, logging_level=log_level)
119
120 def test_name(self):
121 class MySink(bt2._UserSinkComponent):
122 def _consume(self):
123 pass
124
125 def _graph_is_configured(self):
126 pass
127
128 comp = self._create_comp(MySink, 'yaes')
129 self.assertEqual(comp.name, 'yaes')
130
131 def test_logging_level(self):
132 class MySink(bt2._UserSinkComponent):
133 def _consume(self):
134 pass
135
136 def _graph_is_configured(self):
137 pass
138
139 comp = self._create_comp(MySink, 'yaes', bt2.LoggingLevel.WARNING)
140 self.assertEqual(comp.logging_level, bt2.LoggingLevel.WARNING)
141
142 def test_class(self):
143 class MySink(bt2._UserSinkComponent):
144 def _consume(self):
145 pass
146
147 def _graph_is_configured(self):
148 pass
149
150 comp = self._create_comp(MySink)
151 self.assertEqual(comp.cls, MySink)
152
153 def test_addr(self):
154 class MySink(bt2._UserSinkComponent):
155 def _consume(self):
156 pass
157
158 def _graph_is_configured(self):
159 pass
160
161 comp = self._create_comp(MySink)
162 self.assertIsInstance(comp.addr, int)
163 self.assertNotEqual(comp.addr, 0)
This page took 0.035876 seconds and 5 git commands to generate.