bt2: prepend `_user` to overridable protected methods
[babeltrace.git] / tests / bindings / python / bt2 / test_component.py
CommitLineData
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 19from bt2 import value
811644b8
PP
20import unittest
21import copy
22import bt2
23
24
25class 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
6a91742b 40 def _user_consume(self):
a01b452b
SM
41 pass
42
811644b8
PP
43 comp = self._create_comp(MySink, 'yaes')
44
e6090a23
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
6a91742b 50 def _user_consume(self):
a01b452b
SM
51 pass
52
e6090a23
PP
53 comp = self._create_comp(MySink, 'yaes', bt2.LoggingLevel.INFO)
54
811644b8
PP
55 def test_class(self):
56 class MySink(bt2._UserSinkComponent):
57 def __init__(comp_self, params):
e8ac1aae 58 self.assertEqual(comp_self.cls, MySink)
811644b8 59
6a91742b 60 def _user_consume(self):
a01b452b
SM
61 pass
62
811644b8
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
6a91742b 71 def _user_consume(self):
a01b452b
SM
72 pass
73
811644b8
PP
74 self._create_comp(MySink)
75
76 def test_finalize(self):
77 finalized = False
78
79 class MySink(bt2._UserSinkComponent):
6a91742b 80 def _user_consume(self):
a01b452b
SM
81 pass
82
6a91742b 83 def _user_finalize(comp_self):
811644b8
PP
84 nonlocal finalized
85 finalized = True
86
87 graph = bt2.Graph()
894a8df5 88 comp = graph.add_component(MySink, 'lel')
1c9ed2ff 89
811644b8
PP
90 del graph
91 del comp
92 self.assertTrue(finalized)
93
94
95class GenericComponentTestCase(unittest.TestCase):
96 @staticmethod
e6090a23 97 def _create_comp(comp_cls, name=None, log_level=bt2.LoggingLevel.NONE):
811644b8
PP
98 graph = bt2.Graph()
99
100 if name is None:
101 name = 'comp'
102
e6090a23 103 return graph.add_component(comp_cls, name, logging_level=log_level)
811644b8
PP
104
105 def test_name(self):
106 class MySink(bt2._UserSinkComponent):
6a91742b 107 def _user_consume(self):
a01b452b
SM
108 pass
109
811644b8
PP
110 comp = self._create_comp(MySink, 'yaes')
111 self.assertEqual(comp.name, 'yaes')
112
e6090a23
PP
113 def test_logging_level(self):
114 class MySink(bt2._UserSinkComponent):
6a91742b 115 def _user_consume(self):
a01b452b
SM
116 pass
117
770538dd
PP
118 comp = self._create_comp(MySink, 'yaes', bt2.LoggingLevel.WARNING)
119 self.assertEqual(comp.logging_level, bt2.LoggingLevel.WARNING)
e6090a23 120
811644b8
PP
121 def test_class(self):
122 class MySink(bt2._UserSinkComponent):
6a91742b 123 def _user_consume(self):
a01b452b
SM
124 pass
125
811644b8 126 comp = self._create_comp(MySink)
e8ac1aae 127 self.assertEqual(comp.cls, MySink)
811644b8
PP
128
129 def test_addr(self):
130 class MySink(bt2._UserSinkComponent):
6a91742b 131 def _user_consume(self):
a01b452b
SM
132 pass
133
811644b8
PP
134 comp = self._create_comp(MySink)
135 self.assertIsInstance(comp.addr, int)
136 self.assertNotEqual(comp.addr, 0)
This page took 0.04242 seconds and 4 git commands to generate.