+#
+# Copyright (C) 2019 EfficiOS Inc.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; only version 2
+# of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+
from bt2 import value
import unittest
import bt2
class UserComponentClassTestCase(unittest.TestCase):
def _test_no_init(self, cls):
- with self.assertRaises(bt2.Error):
+ with self.assertRaises(RuntimeError):
cls()
def test_no_init_source(self):
def __next__(self):
raise bt2.Stop
- class MySource(bt2._UserSourceComponent,
- message_iterator_class=MyIter):
+ class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter):
pass
self._test_no_init(MySource)
def __next__(self):
raise bt2.Stop
- class MyFilter(bt2._UserFilterComponent,
- message_iterator_class=MyIter):
+ class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyIter):
pass
self._test_no_init(MyFilter)
def _consume(self):
pass
+ def _graph_is_configured(self):
+ pass
+
self._test_no_init(MySink)
def test_incomplete_source_no_msg_iter_cls(self):
pass
with self.assertRaises(bt2.IncompleteUserClass):
+
class MySource(bt2._UserSourceComponent):
pass
pass
with self.assertRaises(bt2.IncompleteUserClass):
- class MySource(bt2._UserSourceComponent,
- message_iterator_class=int):
+
+ class MySource(bt2._UserSourceComponent, message_iterator_class=int):
pass
def test_incomplete_filter_no_msg_iter_cls(self):
pass
with self.assertRaises(bt2.IncompleteUserClass):
+
class MyFilter(bt2._UserFilterComponent):
pass
pass
with self.assertRaises(bt2.IncompleteUserClass):
+
class MySink(bt2._UserSinkComponent):
pass
class MyIter(bt2._UserMessageIterator):
pass
- class MySource(bt2._UserSourceComponent,
- message_iterator_class=MyIter):
+ class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter):
pass
def test_minimal_filter(self):
class MyIter(bt2._UserMessageIterator):
pass
- class MyFilter(bt2._UserFilterComponent,
- message_iterator_class=MyIter):
+ class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyIter):
pass
def test_minimal_sink(self):
def _consume(self):
pass
+ def _graph_is_configured(self):
+ pass
+
def test_default_name(self):
class MySink(bt2._UserSinkComponent):
def _consume(self):
pass
+ def _graph_is_configured(self):
+ pass
+
self.assertEqual(MySink.name, 'MySink')
def test_custom_name(self):
def _consume(self):
pass
+ def _graph_is_configured(self):
+ pass
+
self.assertEqual(MySink.name, 'salut')
def test_invalid_custom_name(self):
with self.assertRaises(TypeError):
+
class MySink(bt2._UserSinkComponent, name=23):
def _consume(self):
pass
+ def _graph_is_configured(self):
+ pass
+
def test_description(self):
class MySink(bt2._UserSinkComponent):
"""
def _consume(self):
pass
+ def _graph_is_configured(self):
+ pass
+
self.assertEqual(MySink.description, 'The description.')
def test_empty_description(self):
def _consume(self):
pass
+ def _graph_is_configured(self):
+ pass
+
self.assertIsNone(MySink.description)
def test_help(self):
def _consume(self):
pass
+ def _graph_is_configured(self):
+ pass
+
self.assertEqual(MySink.help, 'The help\ntext is\nhere.')
def test_addr(self):
def _consume(self):
pass
+ def _graph_is_configured(self):
+ pass
+
self.assertIsInstance(MySink.addr, int)
self.assertNotEqual(MySink.addr, 0)
def _consume(self):
pass
+ def _graph_is_configured(self):
+ pass
+
with self.assertRaises(bt2.Error):
bt2.QueryExecutor().query(MySink, 'obj', 23)
def _consume(self):
pass
+ def _graph_is_configured(self):
+ pass
+
@classmethod
- def _query(cls, query_exec, obj, params):
+ def _query(cls, query_exec, obj, params, log_level):
raise ValueError
with self.assertRaises(bt2.Error):
def _consume(self):
pass
+ def _graph_is_configured(self):
+ pass
+
@classmethod
- def _query(cls, query_exec, obj, params):
+ def _query(cls, query_exec, obj, params, log_level):
return ...
with self.assertRaises(bt2.Error):
def _consume(self):
pass
+ def _graph_is_configured(self):
+ pass
+
@classmethod
- def _query(cls, query_exec, obj, params):
+ def _query(cls, query_exec, obj, params, log_level):
nonlocal query_params
query_params = params
return None
self.assertIsNone(res)
del query_params
+ def test_query_logging_level(self):
+ class MySink(bt2._UserSinkComponent):
+ def _consume(self):
+ pass
+
+ def _graph_is_configured(self):
+ pass
+
+ @classmethod
+ def _query(cls, query_exec, obj, params, log_level):
+ nonlocal query_log_level
+ query_log_level = log_level
+
+ query_log_level = None
+ res = bt2.QueryExecutor().query(MySink, 'obj', None, bt2.LoggingLevel.WARNING)
+ self.assertEqual(query_log_level, bt2.LoggingLevel.WARNING)
+ del query_log_level
+
+ def test_query_returns_none(self):
+ class MySink(bt2._UserSinkComponent):
+ def _consume(self):
+ pass
+
+ def _graph_is_configured(self):
+ pass
+
+ @staticmethod
+ def _query(query_exec, obj, params, log_level):
+ return
+
+ res = bt2.QueryExecutor().query(MySink, 'obj', None)
+ self.assertIsNone(res)
+
def test_query_simple(self):
class MySink(bt2._UserSinkComponent):
def _consume(self):
pass
+ def _graph_is_configured(self):
+ pass
+
@classmethod
- def _query(cls, query_exec, obj, params):
+ def _query(cls, query_exec, obj, params, log_level):
nonlocal query_params
query_params = params
return 17.5
def _consume(self):
pass
+ def _graph_is_configured(self):
+ pass
+
@classmethod
- def _query(cls, query_exec, obj, params):
+ def _query(cls, query_exec, obj, params, log_level):
nonlocal query_params
query_params = params
- return {
- 'null': None,
- 'bt2': 'BT2',
- }
+ return {'null': None, 'bt2': 'BT2'}
query_params = None
params = {
'array': ['coucou', 23, None],
- 'other_map': {
- 'yes': 'yeah',
- '19': 19,
- 'minus 1.5': -1.5,
- },
+ 'other_map': {'yes': 'yeah', '19': 19, 'minus 1.5': -1.5},
'null': None,
}
res = bt2.QueryExecutor().query(MySink, 'obj', params)
self.assertEqual(query_params, params)
- self.assertEqual(res, {
- 'null': None,
- 'bt2': 'BT2',
- })
+ self.assertEqual(res, {'null': None, 'bt2': 'BT2'})
del query_params
def test_eq(self):
def _consume(self):
pass
+ def _graph_is_configured(self):
+ pass
+
self.assertEqual(MySink, MySink)
The help.
'''
+
def _consume(self):
pass
+ def _graph_is_configured(self):
+ pass
+
@classmethod
- def _query(cls, query_exec, obj, params):
+ def _query(cls, query_exec, obj, params, log_level):
return [obj, params, 23]
self._py_comp_cls = MySink
graph = bt2.Graph()
comp = graph.add_component(MySink, 'salut')
- self._comp_cls = comp.component_class
- self.assertTrue(issubclass(type(self._comp_cls),
- bt2.component._GenericComponentClass))
+ self._comp_cls = comp.cls
+ self.assertTrue(
+ issubclass(type(self._comp_cls), bt2.component._GenericComponentClass)
+ )
def tearDown(self):
del self._py_comp_cls
self.assertEqual(self._py_comp_cls, self._comp_cls)
def test_query(self):
- res = bt2.QueryExecutor().query(self._comp_cls, 'an object',
- {'yes': 'no', 'book': -17})
+ res = bt2.QueryExecutor().query(
+ self._comp_cls, 'an object', {'yes': 'no', 'book': -17}
+ )
expected = ['an object', {'yes': 'no', 'book': -17}, 23]
self.assertEqual(res, expected)