Commit | Line | Data |
---|---|---|
d2d857a8 MJ |
1 | # |
2 | # Copyright (C) 2019 EfficiOS Inc. | |
3 | # | |
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 | |
7 | # of the License. | |
8 | # | |
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. | |
13 | # | |
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. | |
17 | # | |
18 | ||
c4239792 | 19 | from bt2 import value |
811644b8 PP |
20 | import unittest |
21 | import copy | |
22 | import bt2 | |
23 | ||
24 | ||
25 | class UserComponentTestCase(unittest.TestCase): | |
26 | @staticmethod | |
e6090a23 | 27 | def _create_comp(comp_cls, name=None, log_level=bt2.LoggingLevel.NONE): |
811644b8 PP |
28 | graph = bt2.Graph() |
29 | ||
30 | if name is None: | |
31 | name = 'comp' | |
32 | ||
e6090a23 | 33 | return graph.add_component(comp_cls, name, logging_level=log_level) |
811644b8 PP |
34 | |
35 | def test_name(self): | |
36 | class MySink(bt2._UserSinkComponent): | |
37 | def __init__(comp_self, params): | |
38 | self.assertEqual(comp_self.name, 'yaes') | |
39 | ||
40 | def _consume(self): | |
41 | pass | |
42 | ||
a01b452b SM |
43 | def _graph_is_configured(self): |
44 | pass | |
45 | ||
811644b8 PP |
46 | comp = self._create_comp(MySink, 'yaes') |
47 | ||
e6090a23 PP |
48 | def test_logging_level(self): |
49 | class MySink(bt2._UserSinkComponent): | |
50 | def __init__(comp_self, params): | |
51 | self.assertEqual(comp_self.logging_level, bt2.LoggingLevel.INFO) | |
52 | ||
53 | def _consume(self): | |
54 | pass | |
55 | ||
a01b452b SM |
56 | def _graph_is_configured(self): |
57 | pass | |
58 | ||
e6090a23 PP |
59 | comp = self._create_comp(MySink, 'yaes', bt2.LoggingLevel.INFO) |
60 | ||
811644b8 PP |
61 | def test_class(self): |
62 | class MySink(bt2._UserSinkComponent): | |
63 | def __init__(comp_self, params): | |
e8ac1aae | 64 | self.assertEqual(comp_self.cls, MySink) |
811644b8 PP |
65 | |
66 | def _consume(self): | |
67 | pass | |
68 | ||
a01b452b SM |
69 | def _graph_is_configured(self): |
70 | pass | |
71 | ||
811644b8 PP |
72 | self._create_comp(MySink) |
73 | ||
74 | def test_addr(self): | |
75 | class MySink(bt2._UserSinkComponent): | |
76 | def __init__(comp_self, params): | |
77 | self.assertIsInstance(comp_self.addr, int) | |
78 | self.assertNotEqual(comp_self.addr, 0) | |
79 | ||
80 | def _consume(self): | |
81 | pass | |
82 | ||
a01b452b SM |
83 | def _graph_is_configured(self): |
84 | pass | |
85 | ||
811644b8 PP |
86 | self._create_comp(MySink) |
87 | ||
88 | def test_finalize(self): | |
89 | finalized = False | |
90 | ||
91 | class MySink(bt2._UserSinkComponent): | |
92 | def _consume(self): | |
93 | pass | |
94 | ||
a01b452b SM |
95 | def _graph_is_configured(self): |
96 | pass | |
97 | ||
811644b8 PP |
98 | def _finalize(comp_self): |
99 | nonlocal finalized | |
100 | finalized = True | |
101 | ||
102 | graph = bt2.Graph() | |
894a8df5 | 103 | comp = graph.add_component(MySink, 'lel') |
1c9ed2ff | 104 | |
811644b8 PP |
105 | del graph |
106 | del comp | |
107 | self.assertTrue(finalized) | |
108 | ||
109 | ||
110 | class GenericComponentTestCase(unittest.TestCase): | |
111 | @staticmethod | |
e6090a23 | 112 | def _create_comp(comp_cls, name=None, log_level=bt2.LoggingLevel.NONE): |
811644b8 PP |
113 | graph = bt2.Graph() |
114 | ||
115 | if name is None: | |
116 | name = 'comp' | |
117 | ||
e6090a23 | 118 | return graph.add_component(comp_cls, name, logging_level=log_level) |
811644b8 PP |
119 | |
120 | def test_name(self): | |
121 | class MySink(bt2._UserSinkComponent): | |
122 | def _consume(self): | |
123 | pass | |
124 | ||
a01b452b SM |
125 | def _graph_is_configured(self): |
126 | pass | |
127 | ||
811644b8 PP |
128 | comp = self._create_comp(MySink, 'yaes') |
129 | self.assertEqual(comp.name, 'yaes') | |
130 | ||
e6090a23 PP |
131 | def test_logging_level(self): |
132 | class MySink(bt2._UserSinkComponent): | |
133 | def _consume(self): | |
134 | pass | |
135 | ||
a01b452b SM |
136 | def _graph_is_configured(self): |
137 | pass | |
138 | ||
770538dd PP |
139 | comp = self._create_comp(MySink, 'yaes', bt2.LoggingLevel.WARNING) |
140 | self.assertEqual(comp.logging_level, bt2.LoggingLevel.WARNING) | |
e6090a23 | 141 | |
811644b8 PP |
142 | def test_class(self): |
143 | class MySink(bt2._UserSinkComponent): | |
144 | def _consume(self): | |
145 | pass | |
146 | ||
a01b452b SM |
147 | def _graph_is_configured(self): |
148 | pass | |
149 | ||
811644b8 | 150 | comp = self._create_comp(MySink) |
e8ac1aae | 151 | self.assertEqual(comp.cls, MySink) |
811644b8 PP |
152 | |
153 | def test_addr(self): | |
154 | class MySink(bt2._UserSinkComponent): | |
155 | def _consume(self): | |
156 | pass | |
157 | ||
a01b452b SM |
158 | def _graph_is_configured(self): |
159 | pass | |
160 | ||
811644b8 PP |
161 | comp = self._create_comp(MySink) |
162 | self.assertIsInstance(comp.addr, int) | |
163 | self.assertNotEqual(comp.addr, 0) |