bt2: prepend `_user` to overridable protected methods
[babeltrace.git] / tests / bindings / python / bt2 / test_component.py
CommitLineData
32d2d479
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
ae0bfae8 19from bt2 import value
f6a5e476
PP
20import unittest
21import copy
22import bt2
23
24
25class UserComponentTestCase(unittest.TestCase):
26 @staticmethod
9bc3e785 27 def _create_comp(comp_cls, name=None, log_level=bt2.LoggingLevel.NONE):
f6a5e476
PP
28 graph = bt2.Graph()
29
30 if name is None:
31 name = 'comp'
32
9bc3e785 33 return graph.add_component(comp_cls, name, logging_level=log_level)
f6a5e476
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
819d0ae7 40 def _user_consume(self):
8a08af82
SM
41 pass
42
f6a5e476
PP
43 comp = self._create_comp(MySink, 'yaes')
44
9bc3e785
PP
45 def test_logging_level(self):
46 class MySink(bt2._UserSinkComponent):
47 def __init__(comp_self, params):
48 self.assertEqual(comp_self.logging_level, bt2.LoggingLevel.INFO)
49
819d0ae7 50 def _user_consume(self):
8a08af82
SM
51 pass
52
9bc3e785
PP
53 comp = self._create_comp(MySink, 'yaes', bt2.LoggingLevel.INFO)
54
f6a5e476
PP
55 def test_class(self):
56 class MySink(bt2._UserSinkComponent):
57 def __init__(comp_self, params):
c88be1c8 58 self.assertEqual(comp_self.cls, MySink)
f6a5e476 59
819d0ae7 60 def _user_consume(self):
8a08af82
SM
61 pass
62
f6a5e476
PP
63 self._create_comp(MySink)
64
65 def test_addr(self):
66 class MySink(bt2._UserSinkComponent):
67 def __init__(comp_self, params):
68 self.assertIsInstance(comp_self.addr, int)
69 self.assertNotEqual(comp_self.addr, 0)
70
819d0ae7 71 def _user_consume(self):
8a08af82
SM
72 pass
73
f6a5e476
PP
74 self._create_comp(MySink)
75
76 def test_finalize(self):
77 finalized = False
78
79 class MySink(bt2._UserSinkComponent):
819d0ae7 80 def _user_consume(self):
8a08af82
SM
81 pass
82
819d0ae7 83 def _user_finalize(comp_self):
f6a5e476
PP
84 nonlocal finalized
85 finalized = True
86
87 graph = bt2.Graph()
bc5c9924 88 comp = graph.add_component(MySink, 'lel')
e34fb94a 89
f6a5e476
PP
90 del graph
91 del comp
92 self.assertTrue(finalized)
93
94
95class GenericComponentTestCase(unittest.TestCase):
96 @staticmethod
9bc3e785 97 def _create_comp(comp_cls, name=None, log_level=bt2.LoggingLevel.NONE):
f6a5e476
PP
98 graph = bt2.Graph()
99
100 if name is None:
101 name = 'comp'
102
9bc3e785 103 return graph.add_component(comp_cls, name, logging_level=log_level)
f6a5e476
PP
104
105 def test_name(self):
106 class MySink(bt2._UserSinkComponent):
819d0ae7 107 def _user_consume(self):
8a08af82
SM
108 pass
109
f6a5e476
PP
110 comp = self._create_comp(MySink, 'yaes')
111 self.assertEqual(comp.name, 'yaes')
112
9bc3e785
PP
113 def test_logging_level(self):
114 class MySink(bt2._UserSinkComponent):
819d0ae7 115 def _user_consume(self):
8a08af82
SM
116 pass
117
e9d0e821
PP
118 comp = self._create_comp(MySink, 'yaes', bt2.LoggingLevel.WARNING)
119 self.assertEqual(comp.logging_level, bt2.LoggingLevel.WARNING)
9bc3e785 120
f6a5e476
PP
121 def test_class(self):
122 class MySink(bt2._UserSinkComponent):
819d0ae7 123 def _user_consume(self):
8a08af82
SM
124 pass
125
f6a5e476 126 comp = self._create_comp(MySink)
c88be1c8 127 self.assertEqual(comp.cls, MySink)
f6a5e476
PP
128
129 def test_addr(self):
130 class MySink(bt2._UserSinkComponent):
819d0ae7 131 def _user_consume(self):
8a08af82
SM
132 pass
133
f6a5e476
PP
134 comp = self._create_comp(MySink)
135 self.assertIsInstance(comp.addr, int)
136 self.assertNotEqual(comp.addr, 0)
This page took 0.042738 seconds and 4 git commands to generate.