+# 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
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)
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):
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):
"""
class ComponentClassTestCase(unittest.TestCase):
def setUp(self):
class MySink(bt2._UserSinkComponent):
- '''
+ """
The description.
The help.
- '''
+ """
def _user_consume(self):
pass
graph = bt2.Graph()
comp = graph.add_component(MySink, 'salut')
self._comp_cls = comp.cls
- self.assertTrue(issubclass(type(self._comp_cls), bt2._SinkComponentClassConst))
+ self.assertIs(type(self._comp_cls), bt2._SinkComponentClassConst)
def tearDown(self):
del self._py_comp_cls
).query()
expected = ['an object', {'yes': 'no', 'book': -17}, 23]
self.assertEqual(res, expected)
+
+
+if __name__ == '__main__':
+ unittest.main()