cpp-common/bt2c/fmt.hpp: use `wise_enum::string_type` in `EnableIfIsWiseEnum` definition
[babeltrace.git] / tests / bindings / python / bt2 / test_component_descriptor.py
1 # SPDX-License-Identifier: GPL-2.0-only
2 #
3 # Copyright (C) 2019 EfficiOS Inc.
4 #
5
6 import unittest
7
8 import bt2
9
10
11 class _DummySink(bt2._UserSinkComponent):
12 def _user_consume(self):
13 pass
14
15
16 class ComponentDescriptorTestCase(unittest.TestCase):
17 def setUp(self):
18 self._obj = object()
19 self._comp_descr = bt2.ComponentDescriptor(_DummySink, {"zoom": -23}, self._obj)
20
21 def _get_comp_cls_from_plugin(self):
22 plugin = bt2.find_plugin("text", find_in_user_dir=False, find_in_sys_dir=False)
23 assert plugin is not None
24 cc = plugin.source_component_classes["dmesg"]
25 assert cc is not None
26 return cc
27
28 def test_init_invalid_cls_type(self):
29 with self.assertRaises(TypeError):
30 bt2.ComponentDescriptor(int)
31
32 def test_init_invalid_params_type(self):
33 with self.assertRaises(TypeError):
34 bt2.ComponentDescriptor(_DummySink, object())
35
36 def test_init_invalid_obj_non_python_comp_cls(self):
37 cc = self._get_comp_cls_from_plugin()
38
39 with self.assertRaises(ValueError):
40 bt2.ComponentDescriptor(cc, obj=57)
41
42 def test_init_with_user_comp_cls(self):
43 bt2.ComponentDescriptor(_DummySink)
44
45 def test_init_with_gen_comp_cls(self):
46 cc = self._get_comp_cls_from_plugin()
47 bt2.ComponentDescriptor(cc)
48
49 def test_attr_component_class(self):
50 self.assertIs(self._comp_descr.component_class, _DummySink)
51
52 def test_attr_params(self):
53 self.assertEqual(self._comp_descr.params, {"zoom": -23})
54
55 def test_attr_obj(self):
56 self.assertIs(self._comp_descr.obj, self._obj)
57
58
59 if __name__ == "__main__":
60 unittest.main()
This page took 0.030536 seconds and 4 git commands to generate.