bt2: clean available `bt2` package names
[babeltrace.git] / tests / bindings / python / bt2 / test_query_executor.py
CommitLineData
32d2d479
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
ae0bfae8 19from bt2 import value
1286dcbb
PP
20import unittest
21import copy
22import bt2
23
24
25class QueryExecutorTestCase(unittest.TestCase):
26 def test_query(self):
27 class MySink(bt2._UserSinkComponent):
28 def _consume(self):
29 pass
30
8a08af82
SM
31 def _graph_is_configured(self):
32 pass
33
1286dcbb 34 @classmethod
83da519a 35 def _query(cls, query_exec, obj, params, log_level):
1286dcbb
PP
36 nonlocal query_params
37 query_params = params
61d96b89 38 return {'null': None, 'bt2': 'BT2'}
1286dcbb
PP
39
40 query_params = None
41 params = {
42 'array': ['coucou', 23, None],
61d96b89 43 'other_map': {'yes': 'yeah', '19': 19, 'minus 1.5': -1.5},
1286dcbb
PP
44 'null': None,
45 }
46
47 res = bt2.QueryExecutor().query(MySink, 'obj', params)
48 self.assertEqual(query_params, params)
61d96b89 49 self.assertEqual(res, {'null': None, 'bt2': 'BT2'})
1286dcbb
PP
50 del query_params
51
52 def test_query_params_none(self):
53 class MySink(bt2._UserSinkComponent):
54 def _consume(self):
55 pass
56
8a08af82
SM
57 def _graph_is_configured(self):
58 pass
59
1286dcbb 60 @classmethod
83da519a 61 def _query(cls, query_exec, obj, params, log_level):
1286dcbb
PP
62 nonlocal query_params
63 query_params = params
64
65 query_params = 23
66 res = bt2.QueryExecutor().query(MySink, 'obj', None)
67 self.assertEqual(query_params, None)
68 del query_params
69
999e7442
PP
70 def test_query_logging_level(self):
71 class MySink(bt2._UserSinkComponent):
72 def _consume(self):
73 pass
74
8a08af82
SM
75 def _graph_is_configured(self):
76 pass
77
999e7442
PP
78 @classmethod
79 def _query(cls, query_exec, obj, params, log_level):
80 nonlocal query_log_level
81 query_log_level = log_level
82
83 query_log_level = None
61d96b89 84 res = bt2.QueryExecutor().query(MySink, 'obj', None, bt2.LoggingLevel.INFO)
999e7442
PP
85 self.assertEqual(query_log_level, bt2.LoggingLevel.INFO)
86 del query_log_level
87
1286dcbb
PP
88 def test_query_gen_error(self):
89 class MySink(bt2._UserSinkComponent):
90 def _consume(self):
91 pass
92
8a08af82
SM
93 def _graph_is_configured(self):
94 pass
95
1286dcbb 96 @classmethod
83da519a 97 def _query(cls, query_exec, obj, params, log_level):
1286dcbb
PP
98 raise ValueError
99
614743a5 100 with self.assertRaises(bt2._Error) as ctx:
1286dcbb
PP
101 res = bt2.QueryExecutor().query(MySink, 'obj', [17, 23])
102
3b2be708 103 exc = ctx.exception
574dea68 104 self.assertEqual(len(exc), 2)
3b2be708 105 cause = exc[0]
c946c9de 106 self.assertIsInstance(cause, bt2._ComponentClassErrorCause)
3b2be708
SM
107 self.assertIn('raise ValueError', cause.message)
108 self.assertEqual(cause.component_class_type, bt2.ComponentClassType.SINK)
109 self.assertEqual(cause.component_class_name, 'MySink')
110
1286dcbb
PP
111 def test_query_invalid_object(self):
112 class MySink(bt2._UserSinkComponent):
113 def _consume(self):
114 pass
115
8a08af82
SM
116 def _graph_is_configured(self):
117 pass
118
1286dcbb 119 @classmethod
83da519a 120 def _query(cls, query_exec, obj, params, log_level):
fb25b9e3 121 raise bt2.InvalidObject
1286dcbb 122
fb25b9e3 123 with self.assertRaises(bt2.InvalidObject):
1286dcbb
PP
124 res = bt2.QueryExecutor().query(MySink, 'obj', [17, 23])
125
999e7442
PP
126 def test_query_logging_level_invalid_type(self):
127 class MySink(bt2._UserSinkComponent):
128 def _consume(self):
129 pass
130
8a08af82
SM
131 def _graph_is_configured(self):
132 pass
133
999e7442
PP
134 @classmethod
135 def _query(cls, query_exec, obj, params, log_level):
136 pass
137
138 with self.assertRaises(TypeError):
139 res = bt2.QueryExecutor().query(MySink, 'obj', [17, 23], 'yeah')
140
141 def test_query_logging_level_invalid_value(self):
142 class MySink(bt2._UserSinkComponent):
143 def _consume(self):
144 pass
145
8a08af82
SM
146 def _graph_is_configured(self):
147 pass
148
999e7442
PP
149 @classmethod
150 def _query(cls, query_exec, obj, params, log_level):
151 pass
152
153 with self.assertRaises(ValueError):
154 res = bt2.QueryExecutor().query(MySink, 'obj', [17, 23], 12345)
155
1286dcbb
PP
156 def test_query_try_again(self):
157 class MySink(bt2._UserSinkComponent):
158 def _consume(self):
159 pass
160
8a08af82
SM
161 def _graph_is_configured(self):
162 pass
163
1286dcbb 164 @classmethod
83da519a 165 def _query(cls, query_exec, obj, params, log_level):
1286dcbb
PP
166 raise bt2.TryAgain
167
168 with self.assertRaises(bt2.TryAgain):
169 res = bt2.QueryExecutor().query(MySink, 'obj', [17, 23])
170
d73bb381
PP
171 def test_query_add_interrupter(self):
172 class MySink(bt2._UserSinkComponent):
173 def _consume(self):
174 pass
175
176 def _graph_is_configured(self):
177 pass
178
179 @classmethod
180 def _query(cls, query_exec, obj, params, log_level):
181 nonlocal interrupter2
182 test_self.assertFalse(query_exec.is_interrupted)
183 interrupter2.set()
184 test_self.assertTrue(query_exec.is_interrupted)
185 interrupter2.reset()
186 test_self.assertFalse(query_exec.is_interrupted)
187
188 interrupter1 = bt2.Interrupter()
189 interrupter2 = bt2.Interrupter()
190 test_self = self
1286dcbb 191 query_exec = bt2.QueryExecutor()
d73bb381
PP
192 query_exec.add_interrupter(interrupter1)
193 query_exec.add_interrupter(interrupter2)
194 query_exec.query(MySink, 'obj', [17, 23])
1286dcbb 195
d73bb381 196 def test_query_interrupt(self):
1286dcbb
PP
197 class MySink(bt2._UserSinkComponent):
198 def _consume(self):
199 pass
200
8a08af82
SM
201 def _graph_is_configured(self):
202 pass
203
1286dcbb 204 @classmethod
83da519a 205 def _query(cls, query_exec, obj, params, log_level):
d73bb381
PP
206 test_self.assertFalse(query_exec.is_interrupted)
207 query_exec.interrupt()
208 test_self.assertTrue(query_exec.is_interrupted)
1286dcbb 209
d73bb381 210 test_self = self
1286dcbb 211 query_exec = bt2.QueryExecutor()
d73bb381 212 query_exec.query(MySink, 'obj', [17, 23])
This page took 0.043116 seconds and 4 git commands to generate.