Commit | Line | Data |
---|---|---|
0235b0db | 1 | # SPDX-License-Identifier: GPL-2.0-only |
f865c2aa PP |
2 | # |
3 | # Copyright (C) 2019 EfficiOS Inc. | |
4 | # | |
f865c2aa PP |
5 | |
6 | import unittest | |
7 | import bt2 | |
8 | ||
9 | ||
10 | class _DummySink(bt2._UserSinkComponent): | |
11 | def _user_consume(self): | |
12 | pass | |
13 | ||
14 | ||
15 | class ComponentDescriptorTestCase(unittest.TestCase): | |
16 | def setUp(self): | |
17 | self._obj = object() | |
18 | self._comp_descr = bt2.ComponentDescriptor(_DummySink, {'zoom': -23}, self._obj) | |
19 | ||
20 | def _get_comp_cls_from_plugin(self): | |
21 | plugin = bt2.find_plugin('text', find_in_user_dir=False, find_in_sys_dir=False) | |
22 | assert plugin is not None | |
23 | cc = plugin.source_component_classes['dmesg'] | |
24 | assert cc is not None | |
25 | return cc | |
26 | ||
27 | def test_init_invalid_cls_type(self): | |
28 | with self.assertRaises(TypeError): | |
29 | bt2.ComponentDescriptor(int) | |
30 | ||
31 | def test_init_invalid_params_type(self): | |
32 | with self.assertRaises(TypeError): | |
33 | bt2.ComponentDescriptor(_DummySink, object()) | |
34 | ||
35 | def test_init_invalid_obj_non_python_comp_cls(self): | |
36 | cc = self._get_comp_cls_from_plugin() | |
37 | ||
38 | with self.assertRaises(ValueError): | |
39 | bt2.ComponentDescriptor(cc, obj=57) | |
40 | ||
41 | def test_init_with_user_comp_cls(self): | |
42 | bt2.ComponentDescriptor(_DummySink) | |
43 | ||
44 | def test_init_with_gen_comp_cls(self): | |
45 | cc = self._get_comp_cls_from_plugin() | |
46 | bt2.ComponentDescriptor(cc) | |
47 | ||
48 | def test_attr_component_class(self): | |
49 | self.assertIs(self._comp_descr.component_class, _DummySink) | |
50 | ||
51 | def test_attr_params(self): | |
52 | self.assertEqual(self._comp_descr.params, {'zoom': -23}) | |
53 | ||
54 | def test_attr_obj(self): | |
55 | self.assertIs(self._comp_descr.obj, self._obj) | |
d14ddbba SM |
56 | |
57 | ||
58 | if __name__ == '__main__': | |
59 | unittest.main() |