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 UserComponentTestCase(unittest
.TestCase
):
25 def _create_comp(comp_cls
, name
=None, log_level
=bt2
.LoggingLevel
.NONE
):
31 return graph
.add_component(comp_cls
, name
, logging_level
=log_level
)
34 class MySink(bt2
._UserSinkComponent
):
35 def __init__(comp_self
, params
, obj
):
36 self
.assertEqual(comp_self
.name
, 'yaes')
38 def _user_consume(self
):
41 self
._create
_comp
(MySink
, 'yaes')
43 def test_logging_level(self
):
44 class MySink(bt2
._UserSinkComponent
):
45 def __init__(comp_self
, params
, obj
):
46 self
.assertEqual(comp_self
.logging_level
, bt2
.LoggingLevel
.INFO
)
48 def _user_consume(self
):
51 self
._create
_comp
(MySink
, 'yaes', bt2
.LoggingLevel
.INFO
)
53 def test_graph_mip_version(self
):
54 class MySink(bt2
._UserSinkComponent
):
55 def __init__(comp_self
, params
, obj
):
56 self
.assertEqual(comp_self
._graph
_mip
_version
, 0)
58 def _user_consume(self
):
61 self
._create
_comp
(MySink
, 'yaes', bt2
.LoggingLevel
.INFO
)
64 class MySink(bt2
._UserSinkComponent
):
65 def __init__(comp_self
, params
, obj
):
66 self
.assertEqual(comp_self
.cls
, MySink
)
68 def _user_consume(self
):
71 self
._create
_comp
(MySink
)
74 class MySink(bt2
._UserSinkComponent
):
75 def __init__(comp_self
, params
, obj
):
76 self
.assertIsInstance(comp_self
.addr
, int)
77 self
.assertNotEqual(comp_self
.addr
, 0)
79 def _user_consume(self
):
82 self
._create
_comp
(MySink
)
84 def test_finalize(self
):
87 class MySink(bt2
._UserSinkComponent
):
88 def _user_consume(self
):
91 def _user_finalize(comp_self
):
96 comp
= graph
.add_component(MySink
, 'lel')
100 self
.assertTrue(finalized
)
103 class GenericComponentTestCase(unittest
.TestCase
):
105 def _create_comp(comp_cls
, name
=None, log_level
=bt2
.LoggingLevel
.NONE
):
111 return graph
.add_component(comp_cls
, name
, logging_level
=log_level
)
114 class MySink(bt2
._UserSinkComponent
):
115 def _user_consume(self
):
118 comp
= self
._create
_comp
(MySink
, 'yaes')
119 self
.assertEqual(comp
.name
, 'yaes')
121 def test_logging_level(self
):
122 class MySink(bt2
._UserSinkComponent
):
123 def _user_consume(self
):
126 comp
= self
._create
_comp
(MySink
, 'yaes', bt2
.LoggingLevel
.WARNING
)
127 self
.assertEqual(comp
.logging_level
, bt2
.LoggingLevel
.WARNING
)
129 def test_class(self
):
130 class MySink(bt2
._UserSinkComponent
):
131 def _user_consume(self
):
134 comp
= self
._create
_comp
(MySink
)
135 self
.assertEqual(comp
.cls
, MySink
)
138 class MySink(bt2
._UserSinkComponent
):
139 def _user_consume(self
):
142 comp
= self
._create
_comp
(MySink
)
143 self
.assertIsInstance(comp
.addr
, int)
144 self
.assertNotEqual(comp
.addr
, 0)
147 if __name__
== '__main__':
This page took 0.033535 seconds and 5 git commands to generate.