2 # Copyright (C) 2019 EfficiOS Inc.
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
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.
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.
23 class _DummySink(bt2
._UserSinkComponent
):
24 def _user_consume(self
):
28 class ComponentDescriptorTestCase(unittest
.TestCase
):
31 self
._comp
_descr
= bt2
.ComponentDescriptor(_DummySink
, {'zoom': -23}, self
._obj
)
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']
40 def test_init_invalid_cls_type(self
):
41 with self
.assertRaises(TypeError):
42 bt2
.ComponentDescriptor(int)
44 def test_init_invalid_params_type(self
):
45 with self
.assertRaises(TypeError):
46 bt2
.ComponentDescriptor(_DummySink
, object())
48 def test_init_invalid_obj_non_python_comp_cls(self
):
49 cc
= self
._get
_comp
_cls
_from
_plugin
()
51 with self
.assertRaises(ValueError):
52 bt2
.ComponentDescriptor(cc
, obj
=57)
54 def test_init_with_user_comp_cls(self
):
55 bt2
.ComponentDescriptor(_DummySink
)
57 def test_init_with_gen_comp_cls(self
):
58 cc
= self
._get
_comp
_cls
_from
_plugin
()
59 bt2
.ComponentDescriptor(cc
)
61 def test_attr_component_class(self
):
62 self
.assertIs(self
._comp
_descr
.component_class
, _DummySink
)
64 def test_attr_params(self
):
65 self
.assertEqual(self
._comp
_descr
.params
, {'zoom': -23})
67 def test_attr_obj(self
):
68 self
.assertIs(self
._comp
_descr
.obj
, self
._obj
)
71 if __name__
== '__main__':
This page took 0.031701 seconds and 4 git commands to generate.