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.
21 from bt2
import component
as bt2_component
24 class UserComponentTestCase(unittest
.TestCase
):
26 def _create_comp(comp_cls
, name
=None, log_level
=bt2
.LoggingLevel
.NONE
):
32 return graph
.add_component(comp_cls
, name
, logging_level
=log_level
)
35 class MySink(bt2
._UserSinkComponent
):
36 def __init__(comp_self
, config
, params
, obj
):
37 self
.assertEqual(comp_self
.name
, 'yaes')
39 def _user_consume(self
):
42 self
._create
_comp
(MySink
, 'yaes')
44 def test_logging_level(self
):
45 class MySink(bt2
._UserSinkComponent
):
46 def __init__(comp_self
, config
, params
, obj
):
47 self
.assertEqual(comp_self
.logging_level
, bt2
.LoggingLevel
.INFO
)
49 def _user_consume(self
):
52 self
._create
_comp
(MySink
, 'yaes', bt2
.LoggingLevel
.INFO
)
54 def test_graph_mip_version(self
):
55 class MySink(bt2
._UserSinkComponent
):
56 def __init__(comp_self
, config
, params
, obj
):
57 self
.assertEqual(comp_self
._graph
_mip
_version
, 0)
59 def _user_consume(self
):
62 self
._create
_comp
(MySink
, 'yaes', bt2
.LoggingLevel
.INFO
)
65 class MySink(bt2
._UserSinkComponent
):
66 def __init__(comp_self
, config
, params
, obj
):
67 self
.assertEqual(comp_self
.cls
, MySink
)
69 def _user_consume(self
):
72 self
._create
_comp
(MySink
)
75 class MySink(bt2
._UserSinkComponent
):
76 def __init__(comp_self
, config
, params
, obj
):
77 self
.assertIsInstance(comp_self
.addr
, int)
78 self
.assertNotEqual(comp_self
.addr
, 0)
80 def _user_consume(self
):
83 self
._create
_comp
(MySink
)
85 def test_finalize(self
):
88 class MySink(bt2
._UserSinkComponent
):
89 def _user_consume(self
):
92 def _user_finalize(comp_self
):
97 comp
= graph
.add_component(MySink
, 'lel')
101 self
.assertTrue(finalized
)
103 def test_source_component_config(self
):
105 bt2
._UserSourceComponent
, message_iterator_class
=bt2
._UserMessageIterator
107 def __init__(comp_self
, config
, params
, obj
):
109 cfg_type
= type(config
)
112 self
._create
_comp
(MySource
)
113 self
.assertIs(cfg_type
, bt2_component
._UserSourceComponentConfiguration
)
115 def test_filter_component_config(self
):
117 bt2
._UserFilterComponent
, message_iterator_class
=bt2
._UserMessageIterator
119 def __init__(comp_self
, config
, params
, obj
):
121 cfg_type
= type(config
)
124 self
._create
_comp
(MyFilter
)
125 self
.assertIs(cfg_type
, bt2_component
._UserFilterComponentConfiguration
)
127 def test_sink_component_config(self
):
128 class MySink(bt2
._UserSinkComponent
):
129 def __init__(comp_self
, config
, params
, obj
):
131 cfg_type
= type(config
)
133 def _user_consume(self
):
137 self
._create
_comp
(MySink
)
138 self
.assertIs(cfg_type
, bt2_component
._UserSinkComponentConfiguration
)
141 class GenericComponentTestCase(unittest
.TestCase
):
143 def _create_comp(comp_cls
, name
=None, log_level
=bt2
.LoggingLevel
.NONE
):
149 return graph
.add_component(comp_cls
, name
, logging_level
=log_level
)
152 class MySink(bt2
._UserSinkComponent
):
153 def _user_consume(self
):
156 comp
= self
._create
_comp
(MySink
, 'yaes')
157 self
.assertEqual(comp
.name
, 'yaes')
159 def test_logging_level(self
):
160 class MySink(bt2
._UserSinkComponent
):
161 def _user_consume(self
):
164 comp
= self
._create
_comp
(MySink
, 'yaes', bt2
.LoggingLevel
.WARNING
)
165 self
.assertEqual(comp
.logging_level
, bt2
.LoggingLevel
.WARNING
)
167 def test_class(self
):
168 class MySink(bt2
._UserSinkComponent
):
169 def _user_consume(self
):
172 comp
= self
._create
_comp
(MySink
)
173 self
.assertEqual(comp
.cls
, MySink
)
176 class MySink(bt2
._UserSinkComponent
):
177 def _user_consume(self
):
180 comp
= self
._create
_comp
(MySink
)
181 self
.assertIsInstance(comp
.addr
, int)
182 self
.assertNotEqual(comp
.addr
, 0)
185 if __name__
== '__main__':