Apply black code formatter on all Python code
[babeltrace.git] / tests / bindings / python / bt2 / test_component_class.py
index 432cc8a6271ceabf0d5f7ca5de201aaa8227c9a6..857d15270dd3312dc5ee56960daa75d31499a57c 100644 (file)
@@ -1,3 +1,21 @@
+#
+# 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
@@ -13,8 +31,7 @@ class UserComponentClassTestCase(unittest.TestCase):
             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)
@@ -24,8 +41,7 @@ class UserComponentClassTestCase(unittest.TestCase):
             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)
@@ -35,6 +51,9 @@ class UserComponentClassTestCase(unittest.TestCase):
             def _consume(self):
                 pass
 
+            def _graph_is_configured(self):
+                pass
+
         self._test_no_init(MySink)
 
     def test_incomplete_source_no_msg_iter_cls(self):
@@ -42,6 +61,7 @@ class UserComponentClassTestCase(unittest.TestCase):
             pass
 
         with self.assertRaises(bt2.IncompleteUserClass):
+
             class MySource(bt2._UserSourceComponent):
                 pass
 
@@ -50,8 +70,8 @@ class UserComponentClassTestCase(unittest.TestCase):
             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):
@@ -59,6 +79,7 @@ class UserComponentClassTestCase(unittest.TestCase):
             pass
 
         with self.assertRaises(bt2.IncompleteUserClass):
+
             class MyFilter(bt2._UserFilterComponent):
                 pass
 
@@ -67,6 +88,7 @@ class UserComponentClassTestCase(unittest.TestCase):
             pass
 
         with self.assertRaises(bt2.IncompleteUserClass):
+
             class MySink(bt2._UserSinkComponent):
                 pass
 
@@ -74,16 +96,14 @@ class UserComponentClassTestCase(unittest.TestCase):
         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):
@@ -91,11 +111,17 @@ class UserComponentClassTestCase(unittest.TestCase):
             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):
@@ -103,14 +129,21 @@ class UserComponentClassTestCase(unittest.TestCase):
             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):
             """
@@ -126,6 +159,9 @@ class UserComponentClassTestCase(unittest.TestCase):
             def _consume(self):
                 pass
 
+            def _graph_is_configured(self):
+                pass
+
         self.assertEqual(MySink.description, 'The description.')
 
     def test_empty_description(self):
@@ -136,6 +172,9 @@ class UserComponentClassTestCase(unittest.TestCase):
             def _consume(self):
                 pass
 
+            def _graph_is_configured(self):
+                pass
+
         self.assertIsNone(MySink.description)
 
     def test_help(self):
@@ -151,6 +190,9 @@ class UserComponentClassTestCase(unittest.TestCase):
             def _consume(self):
                 pass
 
+            def _graph_is_configured(self):
+                pass
+
         self.assertEqual(MySink.help, 'The help\ntext is\nhere.')
 
     def test_addr(self):
@@ -158,6 +200,9 @@ class UserComponentClassTestCase(unittest.TestCase):
             def _consume(self):
                 pass
 
+            def _graph_is_configured(self):
+                pass
+
         self.assertIsInstance(MySink.addr, int)
         self.assertNotEqual(MySink.addr, 0)
 
@@ -166,6 +211,9 @@ class UserComponentClassTestCase(unittest.TestCase):
             def _consume(self):
                 pass
 
+            def _graph_is_configured(self):
+                pass
+
         with self.assertRaises(bt2.Error):
             bt2.QueryExecutor().query(MySink, 'obj', 23)
 
@@ -174,8 +222,11 @@ class UserComponentClassTestCase(unittest.TestCase):
             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):
@@ -186,8 +237,11 @@ class UserComponentClassTestCase(unittest.TestCase):
             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):
@@ -198,8 +252,11 @@ class UserComponentClassTestCase(unittest.TestCase):
             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
@@ -211,13 +268,49 @@ class UserComponentClassTestCase(unittest.TestCase):
         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
@@ -234,32 +327,25 @@ class UserComponentClassTestCase(unittest.TestCase):
             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):
@@ -267,6 +353,9 @@ class UserComponentClassTestCase(unittest.TestCase):
             def _consume(self):
                 pass
 
+            def _graph_is_configured(self):
+                pass
+
         self.assertEqual(MySink, MySink)
 
 
@@ -278,19 +367,24 @@ class GenericComponentClassTestCase(unittest.TestCase):
 
             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
@@ -317,7 +411,8 @@ class GenericComponentClassTestCase(unittest.TestCase):
         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)
This page took 0.027555 seconds and 4 git commands to generate.