X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=tests%2Fbindings%2Fpython%2Fbt2%2Ftest_component_class.py;h=08b0c02be1177be878381f937b2396f309000de9;hb=ffecc00e2725dea0af6a7e0cfb10a95b8f56ee68;hp=98fc91dbb9b7f8de675a95a59e71f66b40542fbd;hpb=57081273d1191fc79edc101af619fab96b72460d;p=babeltrace.git diff --git a/tests/bindings/python/bt2/test_component_class.py b/tests/bindings/python/bt2/test_component_class.py index 98fc91db..08b0c02b 100644 --- a/tests/bindings/python/bt2/test_component_class.py +++ b/tests/bindings/python/bt2/test_component_class.py @@ -1,20 +1,7 @@ +# 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. -# import unittest import bt2 @@ -26,21 +13,17 @@ class UserComponentClassTestCase(unittest.TestCase): cls() def test_no_init_source(self): - class MyIter(bt2._UserMessageIterator): - def __next__(self): - raise bt2.Stop - - class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): + class MySource( + bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator + ): pass self._test_no_init(MySource) def test_no_init_filter(self): - class MyIter(bt2._UserMessageIterator): - def __next__(self): - raise bt2.Stop - - class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyIter): + class MyFilter( + bt2._UserFilterComponent, message_iterator_class=bt2._UserMessageIterator + ): pass self._test_no_init(MyFilter) @@ -53,53 +36,39 @@ class UserComponentClassTestCase(unittest.TestCase): self._test_no_init(MySink) def test_incomplete_source_no_msg_iter_cls(self): - class MyIter(bt2._UserMessageIterator): - pass - with self.assertRaises(bt2._IncompleteUserClass): class MySource(bt2._UserSourceComponent): pass def test_incomplete_source_wrong_msg_iter_cls_type(self): - class MyIter(bt2._UserMessageIterator): - pass - with self.assertRaises(bt2._IncompleteUserClass): class MySource(bt2._UserSourceComponent, message_iterator_class=int): pass def test_incomplete_filter_no_msg_iter_cls(self): - class MyIter(bt2._UserMessageIterator): - pass - with self.assertRaises(bt2._IncompleteUserClass): class MyFilter(bt2._UserFilterComponent): pass def test_incomplete_sink_no_consume_method(self): - class MyIter(bt2._UserMessageIterator): - pass - with self.assertRaises(bt2._IncompleteUserClass): class MySink(bt2._UserSinkComponent): pass def test_minimal_source(self): - class MyIter(bt2._UserMessageIterator): - pass - - class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): + class MySource( + bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator + ): 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=bt2._UserMessageIterator + ): pass def test_minimal_sink(self): @@ -145,16 +114,38 @@ class UserComponentClassTestCase(unittest.TestCase): self.assertEqual(MySink.description, 'The description.') - def test_empty_description(self): + def test_empty_description_no_lines(self): class MySink(bt2._UserSinkComponent): + # fmt: off + """""" + # fmt: on + + def _user_consume(self): + pass + + self.assertIsNone(MySink.description) + + def test_empty_description_no_contents(self): + class MySink(bt2._UserSinkComponent): + # fmt: off """ """ + # fmt: on def _user_consume(self): pass self.assertIsNone(MySink.description) + def test_empty_description_single_line(self): + class MySink(bt2._UserSinkComponent): + """my description""" + + def _user_consume(self): + pass + + self.assertEqual(MySink.description, "my description") + def test_help(self): class MySink(bt2._UserSinkComponent): """ @@ -309,11 +300,11 @@ class UserComponentClassTestCase(unittest.TestCase): class ComponentClassTestCase(unittest.TestCase): def setUp(self): class MySink(bt2._UserSinkComponent): - ''' + """ The description. The help. - ''' + """ def _user_consume(self): pass @@ -326,7 +317,7 @@ class ComponentClassTestCase(unittest.TestCase): graph = bt2.Graph() comp = graph.add_component(MySink, 'salut') self._comp_cls = comp.cls - self.assertTrue(issubclass(type(self._comp_cls), bt2._SinkComponentClass)) + self.assertIs(type(self._comp_cls), bt2._SinkComponentClassConst) def tearDown(self): del self._py_comp_cls @@ -358,3 +349,7 @@ class ComponentClassTestCase(unittest.TestCase): ).query() expected = ['an object', {'yes': 'no', 'book': -17}, 23] self.assertEqual(res, expected) + + +if __name__ == '__main__': + unittest.main()