a980d80f2984f8bce4d61da43f831490ce9823ae
[babeltrace.git] / tests / bindings / python / bt2 / test_component_descriptor.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 import unittest
20 import bt2
21
22
23 class _DummySink(bt2._UserSinkComponent):
24 def _user_consume(self):
25 pass
26
27
28 class ComponentDescriptorTestCase(unittest.TestCase):
29 def setUp(self):
30 self._obj = object()
31 self._comp_descr = bt2.ComponentDescriptor(_DummySink, {'zoom': -23}, self._obj)
32
33 def _get_comp_cls_from_plugin(self):
34 plugin = bt2.find_plugin('text', find_in_user_dir=False, find_in_sys_dir=False)
35 assert plugin is not None
36 cc = plugin.source_component_classes['dmesg']
37 assert cc is not None
38 return cc
39
40 def test_init_invalid_cls_type(self):
41 with self.assertRaises(TypeError):
42 bt2.ComponentDescriptor(int)
43
44 def test_init_invalid_params_type(self):
45 with self.assertRaises(TypeError):
46 bt2.ComponentDescriptor(_DummySink, object())
47
48 def test_init_invalid_obj_non_python_comp_cls(self):
49 cc = self._get_comp_cls_from_plugin()
50
51 with self.assertRaises(ValueError):
52 bt2.ComponentDescriptor(cc, obj=57)
53
54 def test_init_with_user_comp_cls(self):
55 bt2.ComponentDescriptor(_DummySink)
56
57 def test_init_with_gen_comp_cls(self):
58 cc = self._get_comp_cls_from_plugin()
59 bt2.ComponentDescriptor(cc)
60
61 def test_attr_component_class(self):
62 self.assertIs(self._comp_descr.component_class, _DummySink)
63
64 def test_attr_params(self):
65 self.assertEqual(self._comp_descr.params, {'zoom': -23})
66
67 def test_attr_obj(self):
68 self.assertIs(self._comp_descr.obj, self._obj)
69
70
71 if __name__ == '__main__':
72 unittest.main()
This page took 0.03083 seconds and 4 git commands to generate.