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.
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
, params
, obj
):
37 self
.assertEqual(comp_self
.name
, 'yaes')
39 def _user_consume(self
):
42 comp
= self
._create
_comp
(MySink
, 'yaes')
44 def test_logging_level(self
):
45 class MySink(bt2
._UserSinkComponent
):
46 def __init__(comp_self
, params
, obj
):
47 self
.assertEqual(comp_self
.logging_level
, bt2
.LoggingLevel
.INFO
)
49 def _user_consume(self
):
52 comp
= self
._create
_comp
(MySink
, 'yaes', bt2
.LoggingLevel
.INFO
)
55 class MySink(bt2
._UserSinkComponent
):
56 def __init__(comp_self
, params
, obj
):
57 self
.assertEqual(comp_self
.cls
, MySink
)
59 def _user_consume(self
):
62 self
._create
_comp
(MySink
)
65 class MySink(bt2
._UserSinkComponent
):
66 def __init__(comp_self
, params
, obj
):
67 self
.assertIsInstance(comp_self
.addr
, int)
68 self
.assertNotEqual(comp_self
.addr
, 0)
70 def _user_consume(self
):
73 self
._create
_comp
(MySink
)
75 def test_finalize(self
):
78 class MySink(bt2
._UserSinkComponent
):
79 def _user_consume(self
):
82 def _user_finalize(comp_self
):
87 comp
= graph
.add_component(MySink
, 'lel')
91 self
.assertTrue(finalized
)
94 class GenericComponentTestCase(unittest
.TestCase
):
96 def _create_comp(comp_cls
, name
=None, log_level
=bt2
.LoggingLevel
.NONE
):
102 return graph
.add_component(comp_cls
, name
, logging_level
=log_level
)
105 class MySink(bt2
._UserSinkComponent
):
106 def _user_consume(self
):
109 comp
= self
._create
_comp
(MySink
, 'yaes')
110 self
.assertEqual(comp
.name
, 'yaes')
112 def test_logging_level(self
):
113 class MySink(bt2
._UserSinkComponent
):
114 def _user_consume(self
):
117 comp
= self
._create
_comp
(MySink
, 'yaes', bt2
.LoggingLevel
.WARNING
)
118 self
.assertEqual(comp
.logging_level
, bt2
.LoggingLevel
.WARNING
)
120 def test_class(self
):
121 class MySink(bt2
._UserSinkComponent
):
122 def _user_consume(self
):
125 comp
= self
._create
_comp
(MySink
)
126 self
.assertEqual(comp
.cls
, MySink
)
129 class MySink(bt2
._UserSinkComponent
):
130 def _user_consume(self
):
133 comp
= self
._create
_comp
(MySink
)
134 self
.assertIsInstance(comp
.addr
, int)
135 self
.assertNotEqual(comp
.addr
, 0)
This page took 0.032124 seconds and 4 git commands to generate.