6 class UserComponentClassTestCase(unittest
.TestCase
):
7 def _test_no_init(self
, cls
):
8 with self
.assertRaises(bt2
.Error
):
11 def test_no_init_source(self
):
12 class MyIter(bt2
._UserMessageIterator
):
16 class MySource(bt2
._UserSourceComponent
,
17 message_iterator_class
=MyIter
):
20 self
._test
_no
_init
(MySource
)
22 def test_no_init_filter(self
):
23 class MyIter(bt2
._UserMessageIterator
):
27 class MyFilter(bt2
._UserFilterComponent
,
28 message_iterator_class
=MyIter
):
31 self
._test
_no
_init
(MyFilter
)
33 def test_no_init_sink(self
):
34 class MySink(bt2
._UserSinkComponent
):
38 self
._test
_no
_init
(MySink
)
40 def test_incomplete_source_no_msg_iter_cls(self
):
41 class MyIter(bt2
._UserMessageIterator
):
44 with self
.assertRaises(bt2
.IncompleteUserClass
):
45 class MySource(bt2
._UserSourceComponent
):
48 def test_incomplete_source_wrong_msg_iter_cls_type(self
):
49 class MyIter(bt2
._UserMessageIterator
):
52 with self
.assertRaises(bt2
.IncompleteUserClass
):
53 class MySource(bt2
._UserSourceComponent
,
54 message_iterator_class
=int):
57 def test_incomplete_filter_no_msg_iter_cls(self
):
58 class MyIter(bt2
._UserMessageIterator
):
61 with self
.assertRaises(bt2
.IncompleteUserClass
):
62 class MyFilter(bt2
._UserFilterComponent
):
65 def test_incomplete_sink_no_consume_method(self
):
66 class MyIter(bt2
._UserMessageIterator
):
69 with self
.assertRaises(bt2
.IncompleteUserClass
):
70 class MySink(bt2
._UserSinkComponent
):
73 def test_minimal_source(self
):
74 class MyIter(bt2
._UserMessageIterator
):
77 class MySource(bt2
._UserSourceComponent
,
78 message_iterator_class
=MyIter
):
81 def test_minimal_filter(self
):
82 class MyIter(bt2
._UserMessageIterator
):
85 class MyFilter(bt2
._UserFilterComponent
,
86 message_iterator_class
=MyIter
):
89 def test_minimal_sink(self
):
90 class MySink(bt2
._UserSinkComponent
):
94 def test_default_name(self
):
95 class MySink(bt2
._UserSinkComponent
):
99 self
.assertEqual(MySink
.name
, 'MySink')
101 def test_custom_name(self
):
102 class MySink(bt2
._UserSinkComponent
, name
='salut'):
106 self
.assertEqual(MySink
.name
, 'salut')
108 def test_invalid_custom_name(self
):
109 with self
.assertRaises(TypeError):
110 class MySink(bt2
._UserSinkComponent
, name
=23):
114 def test_description(self
):
115 class MySink(bt2
._UserSinkComponent
):
119 Bacon ipsum dolor amet ribeye t-bone corned beef, beef jerky
120 porchetta burgdoggen prosciutto chicken frankfurter boudin
121 hamburger doner bacon turducken. Sirloin shank sausage,
122 boudin meatloaf alcatra meatball t-bone tongue pastrami
123 cupim flank tenderloin.
129 self
.assertEqual(MySink
.description
, 'The description.')
131 def test_empty_description(self
):
132 class MySink(bt2
._UserSinkComponent
):
139 self
.assertIsNone(MySink
.description
)
142 class MySink(bt2
._UserSinkComponent
):
154 self
.assertEqual(MySink
.help, 'The help\ntext is\nhere.')
157 class MySink(bt2
._UserSinkComponent
):
161 self
.assertIsInstance(MySink
.addr
, int)
162 self
.assertNotEqual(MySink
.addr
, 0)
164 def test_query_not_implemented(self
):
165 class MySink(bt2
._UserSinkComponent
):
169 with self
.assertRaises(bt2
.Error
):
170 bt2
.QueryExecutor().query(MySink
, 'obj', 23)
172 def test_query_raises(self
):
173 class MySink(bt2
._UserSinkComponent
):
178 def _query(cls
, query_exec
, obj
, params
):
181 with self
.assertRaises(bt2
.Error
):
182 bt2
.QueryExecutor().query(MySink
, 'obj', 23)
184 def test_query_wrong_return_type(self
):
185 class MySink(bt2
._UserSinkComponent
):
190 def _query(cls
, query_exec
, obj
, params
):
193 with self
.assertRaises(bt2
.Error
):
194 bt2
.QueryExecutor().query(MySink
, 'obj', 23)
196 def test_query_params_none(self
):
197 class MySink(bt2
._UserSinkComponent
):
202 def _query(cls
, query_exec
, obj
, params
):
203 nonlocal query_params
204 query_params
= params
209 res
= bt2
.QueryExecutor().query(MySink
, 'obj', params
)
210 self
.assertEqual(query_params
, params
)
211 self
.assertIsNone(res
)
214 def test_query_simple(self
):
215 class MySink(bt2
._UserSinkComponent
):
220 def _query(cls
, query_exec
, obj
, params
):
221 nonlocal query_params
222 query_params
= params
226 params
= ['coucou', 23, None]
227 res
= bt2
.QueryExecutor().query(MySink
, 'obj', params
)
228 self
.assertEqual(query_params
, params
)
229 self
.assertEqual(res
, 17.5)
232 def test_query_complex(self
):
233 class MySink(bt2
._UserSinkComponent
):
238 def _query(cls
, query_exec
, obj
, params
):
239 nonlocal query_params
240 query_params
= params
248 'array': ['coucou', 23, None],
257 res
= bt2
.QueryExecutor().query(MySink
, 'obj', params
)
258 self
.assertEqual(query_params
, params
)
259 self
.assertEqual(res
, {
266 class MySink(bt2
._UserSinkComponent
):
270 self
.assertEqual(MySink
, MySink
)
273 class GenericComponentClassTestCase(unittest
.TestCase
):
275 class MySink(bt2
._UserSinkComponent
):
285 def _query(cls
, query_exec
, obj
, params
):
286 return [obj
, params
, 23]
288 self
._py
_comp
_cls
= MySink
290 comp
= graph
.add_sink_component(MySink
, 'salut')
291 self
._comp
_cls
= comp
.component_class
292 self
.assertTrue(issubclass(type(self
._comp
_cls
),
293 bt2
.component
._GenericComponentClass
))
296 del self
._py
_comp
_cls
299 def test_description(self
):
300 self
.assertEqual(self
._comp
_cls
.description
, 'The description.')
303 self
.assertEqual(self
._comp
_cls
.help, 'The help.')
306 self
.assertEqual(self
._comp
_cls
.name
, 'MySink')
309 self
.assertIsInstance(self
._comp
_cls
.addr
, int)
310 self
.assertNotEqual(self
._comp
_cls
.addr
, 0)
312 def test_eq_invalid(self
):
313 self
.assertFalse(self
._comp
_cls
== 23)
316 self
.assertEqual(self
._comp
_cls
, self
._comp
_cls
)
317 self
.assertEqual(self
._py
_comp
_cls
, self
._comp
_cls
)
319 def test_query(self
):
320 res
= bt2
.QueryExecutor().query(self
._comp
_cls
, 'an object',
321 {'yes': 'no', 'book': -17})
322 expected
= ['an object', {'yes': 'no', 'book': -17}, 23]
323 self
.assertEqual(res
, expected
)
This page took 0.035192 seconds and 4 git commands to generate.