7 @unittest.skip("this is broken")
8 class UserComponentClassTestCase(unittest
.TestCase
):
9 def _test_no_init(self
, cls
):
10 with self
.assertRaises(bt2
.Error
):
13 def test_no_init_source(self
):
14 class MyIter(bt2
._UserMessageIterator
):
18 class MySource(bt2
._UserSourceComponent
,
19 message_iterator_class
=MyIter
):
22 self
._test
_no
_init
(MySource
)
24 def test_no_init_filter(self
):
25 class MyIter(bt2
._UserMessageIterator
):
29 class MyFilter(bt2
._UserFilterComponent
,
30 message_iterator_class
=MyIter
):
33 self
._test
_no
_init
(MyFilter
)
35 def test_no_init_sink(self
):
36 class MySink(bt2
._UserSinkComponent
):
40 self
._test
_no
_init
(MySink
)
42 def test_incomplete_source_no_msg_iter_cls(self
):
43 class MyIter(bt2
._UserMessageIterator
):
46 with self
.assertRaises(bt2
.IncompleteUserClass
):
47 class MySource(bt2
._UserSourceComponent
):
50 def test_incomplete_source_wrong_msg_iter_cls_type(self
):
51 class MyIter(bt2
._UserMessageIterator
):
54 with self
.assertRaises(bt2
.IncompleteUserClass
):
55 class MySource(bt2
._UserSourceComponent
,
56 message_iterator_class
=int):
59 def test_incomplete_filter_no_msg_iter_cls(self
):
60 class MyIter(bt2
._UserMessageIterator
):
63 with self
.assertRaises(bt2
.IncompleteUserClass
):
64 class MyFilter(bt2
._UserFilterComponent
):
67 def test_incomplete_sink_no_consume_method(self
):
68 class MyIter(bt2
._UserMessageIterator
):
71 with self
.assertRaises(bt2
.IncompleteUserClass
):
72 class MySink(bt2
._UserSinkComponent
):
75 def test_minimal_source(self
):
76 class MyIter(bt2
._UserMessageIterator
):
79 class MySource(bt2
._UserSourceComponent
,
80 message_iterator_class
=MyIter
):
83 def test_minimal_filter(self
):
84 class MyIter(bt2
._UserMessageIterator
):
87 class MyFilter(bt2
._UserFilterComponent
,
88 message_iterator_class
=MyIter
):
91 def test_minimal_sink(self
):
92 class MySink(bt2
._UserSinkComponent
):
96 def test_default_name(self
):
97 class MySink(bt2
._UserSinkComponent
):
101 self
.assertEqual(MySink
.name
, 'MySink')
103 def test_custom_name(self
):
104 class MySink(bt2
._UserSinkComponent
, name
='salut'):
108 self
.assertEqual(MySink
.name
, 'salut')
110 def test_invalid_custom_name(self
):
111 with self
.assertRaises(TypeError):
112 class MySink(bt2
._UserSinkComponent
, name
=23):
116 def test_description(self
):
117 class MySink(bt2
._UserSinkComponent
):
121 Bacon ipsum dolor amet ribeye t-bone corned beef, beef jerky
122 porchetta burgdoggen prosciutto chicken frankfurter boudin
123 hamburger doner bacon turducken. Sirloin shank sausage,
124 boudin meatloaf alcatra meatball t-bone tongue pastrami
125 cupim flank tenderloin.
131 self
.assertEqual(MySink
.description
, 'The description.')
133 def test_empty_description(self
):
134 class MySink(bt2
._UserSinkComponent
):
141 self
.assertIsNone(MySink
.description
)
144 class MySink(bt2
._UserSinkComponent
):
156 self
.assertEqual(MySink
.help, 'The help\ntext is\nhere.')
159 class MySink(bt2
._UserSinkComponent
):
163 self
.assertIsInstance(MySink
.addr
, int)
164 self
.assertNotEqual(MySink
.addr
, 0)
166 def test_query_not_implemented(self
):
167 class MySink(bt2
._UserSinkComponent
):
171 with self
.assertRaises(bt2
.Error
):
172 bt2
.QueryExecutor().query(MySink
, 'obj', 23)
174 def test_query_raises(self
):
175 class MySink(bt2
._UserSinkComponent
):
180 def _query(cls
, query_exec
, obj
, params
):
183 with self
.assertRaises(bt2
.Error
):
184 bt2
.QueryExecutor().query(MySink
, 'obj', 23)
186 def test_query_wrong_return_type(self
):
187 class MySink(bt2
._UserSinkComponent
):
192 def _query(cls
, query_exec
, obj
, params
):
195 with self
.assertRaises(bt2
.Error
):
196 bt2
.QueryExecutor().query(MySink
, 'obj', 23)
198 def test_query_params_none(self
):
199 class MySink(bt2
._UserSinkComponent
):
204 def _query(cls
, query_exec
, obj
, params
):
205 nonlocal query_params
206 query_params
= params
211 res
= bt2
.QueryExecutor().query(MySink
, 'obj', params
)
212 self
.assertEqual(query_params
, params
)
213 self
.assertIsNone(res
)
216 def test_query_simple(self
):
217 class MySink(bt2
._UserSinkComponent
):
222 def _query(cls
, query_exec
, obj
, params
):
223 nonlocal query_params
224 query_params
= params
228 params
= ['coucou', 23, None]
229 res
= bt2
.QueryExecutor().query(MySink
, 'obj', params
)
230 self
.assertEqual(query_params
, params
)
231 self
.assertEqual(res
, 17.5)
234 def test_query_complex(self
):
235 class MySink(bt2
._UserSinkComponent
):
240 def _query(cls
, query_exec
, obj
, params
):
241 nonlocal query_params
242 query_params
= params
250 'array': ['coucou', 23, None],
259 res
= bt2
.QueryExecutor().query(MySink
, 'obj', params
)
260 self
.assertEqual(query_params
, params
)
261 self
.assertEqual(res
, {
268 class MySink(bt2
._UserSinkComponent
):
272 self
.assertEqual(MySink
, MySink
)
275 @unittest.skip("this is broken")
276 class GenericComponentClassTestCase(unittest
.TestCase
):
278 class MySink(bt2
._UserSinkComponent
):
288 def _query(cls
, query_exec
, obj
, params
):
289 return [obj
, params
, 23]
291 self
._py
_comp
_cls
= MySink
293 comp
= graph
.add_component(MySink
, 'salut')
294 self
._comp
_cls
= comp
.component_class
295 self
.assertTrue(issubclass(type(self
._comp
_cls
),
296 bt2
.component
._GenericComponentClass
))
299 del self
._py
_comp
_cls
302 def test_description(self
):
303 self
.assertEqual(self
._comp
_cls
.description
, 'The description.')
306 self
.assertEqual(self
._comp
_cls
.help, 'The help.')
309 self
.assertEqual(self
._comp
_cls
.name
, 'MySink')
312 self
.assertIsInstance(self
._comp
_cls
.addr
, int)
313 self
.assertNotEqual(self
._comp
_cls
.addr
, 0)
315 def test_eq_invalid(self
):
316 self
.assertFalse(self
._comp
_cls
== 23)
319 self
.assertEqual(self
._comp
_cls
, self
._comp
_cls
)
320 self
.assertEqual(self
._py
_comp
_cls
, self
._comp
_cls
)
322 def test_query(self
):
323 res
= bt2
.QueryExecutor().query(self
._comp
_cls
, 'an object',
324 {'yes': 'no', 'book': -17})
325 expected
= ['an object', {'yes': 'no', 'book': -17}, 23]
326 self
.assertEqual(res
, expected
)
This page took 0.036775 seconds and 5 git commands to generate.