X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=tests%2Fbindings%2Fpython%2Fbt2%2Ftest_component.py;h=71808fa52dbb77f901df94e2fcf40701f7638f23;hb=f5567ea88d172767b34373bc6e402da8bfd85ef8;hp=69e5617b33808245ea0502f327fd699b1248da81;hpb=a01b452be2f3ec30264a06cb1e3da09a5fe124e9;p=babeltrace.git diff --git a/tests/bindings/python/bt2/test_component.py b/tests/bindings/python/bt2/test_component.py index 69e5617b..71808fa5 100644 --- a/tests/bindings/python/bt2/test_component.py +++ b/tests/bindings/python/bt2/test_component.py @@ -1,25 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0-only # # 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 copy import bt2 +from bt2 import component as bt2_component class UserComponentTestCase(unittest.TestCase): @@ -28,59 +14,57 @@ class UserComponentTestCase(unittest.TestCase): graph = bt2.Graph() if name is None: - name = 'comp' + name = "comp" return graph.add_component(comp_cls, name, logging_level=log_level) def test_name(self): class MySink(bt2._UserSinkComponent): - def __init__(comp_self, params): - self.assertEqual(comp_self.name, 'yaes') - - def _consume(self): - pass + def __init__(comp_self, config, params, obj): + self.assertEqual(comp_self.name, "yaes") - def _graph_is_configured(self): + def _user_consume(self): pass - comp = self._create_comp(MySink, 'yaes') + self._create_comp(MySink, "yaes") def test_logging_level(self): class MySink(bt2._UserSinkComponent): - def __init__(comp_self, params): + def __init__(comp_self, config, params, obj): self.assertEqual(comp_self.logging_level, bt2.LoggingLevel.INFO) - def _consume(self): + def _user_consume(self): pass - def _graph_is_configured(self): + self._create_comp(MySink, "yaes", bt2.LoggingLevel.INFO) + + def test_graph_mip_version(self): + class MySink(bt2._UserSinkComponent): + def __init__(comp_self, config, params, obj): + self.assertEqual(comp_self._graph_mip_version, 0) + + def _user_consume(self): pass - comp = self._create_comp(MySink, 'yaes', bt2.LoggingLevel.INFO) + self._create_comp(MySink, "yaes", bt2.LoggingLevel.INFO) def test_class(self): class MySink(bt2._UserSinkComponent): - def __init__(comp_self, params): + def __init__(comp_self, config, params, obj): self.assertEqual(comp_self.cls, MySink) - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass self._create_comp(MySink) def test_addr(self): class MySink(bt2._UserSinkComponent): - def __init__(comp_self, params): + def __init__(comp_self, config, params, obj): self.assertIsInstance(comp_self.addr, int) self.assertNotEqual(comp_self.addr, 0) - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass self._create_comp(MySink) @@ -89,23 +73,57 @@ class UserComponentTestCase(unittest.TestCase): finalized = False class MySink(bt2._UserSinkComponent): - def _consume(self): + def _user_consume(self): pass - def _graph_is_configured(self): - pass - - def _finalize(comp_self): + def _user_finalize(comp_self): nonlocal finalized finalized = True graph = bt2.Graph() - comp = graph.add_component(MySink, 'lel') + comp = graph.add_component(MySink, "lel") del graph del comp self.assertTrue(finalized) + def test_source_component_config(self): + class MySource( + bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator + ): + def __init__(comp_self, config, params, obj): + nonlocal cfg_type + cfg_type = type(config) + + cfg_type = None + self._create_comp(MySource) + self.assertIs(cfg_type, bt2_component._UserSourceComponentConfiguration) + + def test_filter_component_config(self): + class MyFilter( + bt2._UserFilterComponent, message_iterator_class=bt2._UserMessageIterator + ): + def __init__(comp_self, config, params, obj): + nonlocal cfg_type + cfg_type = type(config) + + cfg_type = None + self._create_comp(MyFilter) + self.assertIs(cfg_type, bt2_component._UserFilterComponentConfiguration) + + def test_sink_component_config(self): + class MySink(bt2._UserSinkComponent): + def __init__(comp_self, config, params, obj): + nonlocal cfg_type + cfg_type = type(config) + + def _user_consume(self): + pass + + cfg_type = None + self._create_comp(MySink) + self.assertIs(cfg_type, bt2_component._UserSinkComponentConfiguration) + class GenericComponentTestCase(unittest.TestCase): @staticmethod @@ -113,38 +131,29 @@ class GenericComponentTestCase(unittest.TestCase): graph = bt2.Graph() if name is None: - name = 'comp' + name = "comp" return graph.add_component(comp_cls, name, logging_level=log_level) def test_name(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass - comp = self._create_comp(MySink, 'yaes') - self.assertEqual(comp.name, 'yaes') + comp = self._create_comp(MySink, "yaes") + self.assertEqual(comp.name, "yaes") def test_logging_level(self): class MySink(bt2._UserSinkComponent): - def _consume(self): + def _user_consume(self): pass - def _graph_is_configured(self): - pass - - comp = self._create_comp(MySink, 'yaes', bt2.LoggingLevel.WARNING) + comp = self._create_comp(MySink, "yaes", bt2.LoggingLevel.WARNING) self.assertEqual(comp.logging_level, bt2.LoggingLevel.WARNING) def test_class(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass comp = self._create_comp(MySink) @@ -152,12 +161,13 @@ class GenericComponentTestCase(unittest.TestCase): def test_addr(self): class MySink(bt2._UserSinkComponent): - def _consume(self): - pass - - def _graph_is_configured(self): + def _user_consume(self): pass comp = self._create_comp(MySink) self.assertIsInstance(comp.addr, int) self.assertNotEqual(comp.addr, 0) + + +if __name__ == "__main__": + unittest.main()