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 | ||
811644b8 PP |
19 | import unittest |
20 | import copy | |
21 | import bt2 | |
22 | ||
23 | ||
24 | class UserComponentTestCase(unittest.TestCase): | |
25 | @staticmethod | |
e6090a23 | 26 | def _create_comp(comp_cls, name=None, log_level=bt2.LoggingLevel.NONE): |
811644b8 PP |
27 | graph = bt2.Graph() |
28 | ||
29 | if name is None: | |
30 | name = 'comp' | |
31 | ||
e6090a23 | 32 | return graph.add_component(comp_cls, name, logging_level=log_level) |
811644b8 PP |
33 | |
34 | def test_name(self): | |
35 | class MySink(bt2._UserSinkComponent): | |
36 | def __init__(comp_self, params): | |
37 | self.assertEqual(comp_self.name, 'yaes') | |
38 | ||
6a91742b | 39 | def _user_consume(self): |
a01b452b SM |
40 | pass |
41 | ||
811644b8 PP |
42 | comp = self._create_comp(MySink, 'yaes') |
43 | ||
e6090a23 PP |
44 | def test_logging_level(self): |
45 | class MySink(bt2._UserSinkComponent): | |
46 | def __init__(comp_self, params): | |
47 | self.assertEqual(comp_self.logging_level, bt2.LoggingLevel.INFO) | |
48 | ||
6a91742b | 49 | def _user_consume(self): |
a01b452b SM |
50 | pass |
51 | ||
e6090a23 PP |
52 | comp = self._create_comp(MySink, 'yaes', bt2.LoggingLevel.INFO) |
53 | ||
811644b8 PP |
54 | def test_class(self): |
55 | class MySink(bt2._UserSinkComponent): | |
56 | def __init__(comp_self, params): | |
e8ac1aae | 57 | self.assertEqual(comp_self.cls, MySink) |
811644b8 | 58 | |
6a91742b | 59 | def _user_consume(self): |
a01b452b SM |
60 | pass |
61 | ||
811644b8 PP |
62 | self._create_comp(MySink) |
63 | ||
64 | def test_addr(self): | |
65 | class MySink(bt2._UserSinkComponent): | |
66 | def __init__(comp_self, params): | |
67 | self.assertIsInstance(comp_self.addr, int) | |
68 | self.assertNotEqual(comp_self.addr, 0) | |
69 | ||
6a91742b | 70 | def _user_consume(self): |
a01b452b SM |
71 | pass |
72 | ||
811644b8 PP |
73 | self._create_comp(MySink) |
74 | ||
75 | def test_finalize(self): | |
76 | finalized = False | |
77 | ||
78 | class MySink(bt2._UserSinkComponent): | |
6a91742b | 79 | def _user_consume(self): |
a01b452b SM |
80 | pass |
81 | ||
6a91742b | 82 | def _user_finalize(comp_self): |
811644b8 PP |
83 | nonlocal finalized |
84 | finalized = True | |
85 | ||
86 | graph = bt2.Graph() | |
894a8df5 | 87 | comp = graph.add_component(MySink, 'lel') |
1c9ed2ff | 88 | |
811644b8 PP |
89 | del graph |
90 | del comp | |
91 | self.assertTrue(finalized) | |
92 | ||
93 | ||
94 | class GenericComponentTestCase(unittest.TestCase): | |
95 | @staticmethod | |
e6090a23 | 96 | def _create_comp(comp_cls, name=None, log_level=bt2.LoggingLevel.NONE): |
811644b8 PP |
97 | graph = bt2.Graph() |
98 | ||
99 | if name is None: | |
100 | name = 'comp' | |
101 | ||
e6090a23 | 102 | return graph.add_component(comp_cls, name, logging_level=log_level) |
811644b8 PP |
103 | |
104 | def test_name(self): | |
105 | class MySink(bt2._UserSinkComponent): | |
6a91742b | 106 | def _user_consume(self): |
a01b452b SM |
107 | pass |
108 | ||
811644b8 PP |
109 | comp = self._create_comp(MySink, 'yaes') |
110 | self.assertEqual(comp.name, 'yaes') | |
111 | ||
e6090a23 PP |
112 | def test_logging_level(self): |
113 | class MySink(bt2._UserSinkComponent): | |
6a91742b | 114 | def _user_consume(self): |
a01b452b SM |
115 | pass |
116 | ||
770538dd PP |
117 | comp = self._create_comp(MySink, 'yaes', bt2.LoggingLevel.WARNING) |
118 | self.assertEqual(comp.logging_level, bt2.LoggingLevel.WARNING) | |
e6090a23 | 119 | |
811644b8 PP |
120 | def test_class(self): |
121 | class MySink(bt2._UserSinkComponent): | |
6a91742b | 122 | def _user_consume(self): |
a01b452b SM |
123 | pass |
124 | ||
811644b8 | 125 | comp = self._create_comp(MySink) |
e8ac1aae | 126 | self.assertEqual(comp.cls, MySink) |
811644b8 PP |
127 | |
128 | def test_addr(self): | |
129 | class MySink(bt2._UserSinkComponent): | |
6a91742b | 130 | def _user_consume(self): |
a01b452b SM |
131 | pass |
132 | ||
811644b8 PP |
133 | comp = self._create_comp(MySink) |
134 | self.assertIsInstance(comp.addr, int) | |
135 | self.assertNotEqual(comp.addr, 0) |