bt2: check for _graph_is_configured method in user sink classes
[babeltrace.git] / tests / bindings / python / bt2 / test_component_class.py
index e1d6b6652405f3a9a83b1e077a778c15c5a85190..cece1a56b39aed8e1fa7a218f12dfa65720674b0 100644 (file)
@@ -1,33 +1,49 @@
-from bt2 import values
+#
+# 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
 
 
-@unittest.skip("this is broken")
 class UserComponentClassTestCase(unittest.TestCase):
     def _test_no_init(self, cls):
         with self.assertRaises(bt2.Error):
             cls()
 
     def test_no_init_source(self):
-        class MyIter(bt2._UserNotificationIterator):
+        class MyIter(bt2._UserMessageIterator):
             def __next__(self):
                 raise bt2.Stop
 
         class MySource(bt2._UserSourceComponent,
-                       notification_iterator_class=MyIter):
+                       message_iterator_class=MyIter):
             pass
 
         self._test_no_init(MySource)
 
     def test_no_init_filter(self):
-        class MyIter(bt2._UserNotificationIterator):
+        class MyIter(bt2._UserMessageIterator):
             def __next__(self):
                 raise bt2.Stop
 
         class MyFilter(bt2._UserFilterComponent,
-                       notification_iterator_class=MyIter):
+                       message_iterator_class=MyIter):
             pass
 
         self._test_no_init(MyFilter)
@@ -37,27 +53,30 @@ class UserComponentClassTestCase(unittest.TestCase):
             def _consume(self):
                 pass
 
+            def _graph_is_configured(self):
+                pass
+
         self._test_no_init(MySink)
 
-    def test_incomplete_source_no_notif_iter_cls(self):
-        class MyIter(bt2._UserNotificationIterator):
+    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_notif_iter_cls_type(self):
-        class MyIter(bt2._UserNotificationIterator):
+    def test_incomplete_source_wrong_msg_iter_cls_type(self):
+        class MyIter(bt2._UserMessageIterator):
             pass
 
         with self.assertRaises(bt2.IncompleteUserClass):
             class MySource(bt2._UserSourceComponent,
-                           notification_iterator_class=int):
+                           message_iterator_class=int):
                 pass
 
-    def test_incomplete_filter_no_notif_iter_cls(self):
-        class MyIter(bt2._UserNotificationIterator):
+    def test_incomplete_filter_no_msg_iter_cls(self):
+        class MyIter(bt2._UserMessageIterator):
             pass
 
         with self.assertRaises(bt2.IncompleteUserClass):
@@ -65,7 +84,7 @@ class UserComponentClassTestCase(unittest.TestCase):
                 pass
 
     def test_incomplete_sink_no_consume_method(self):
-        class MyIter(bt2._UserNotificationIterator):
+        class MyIter(bt2._UserMessageIterator):
             pass
 
         with self.assertRaises(bt2.IncompleteUserClass):
@@ -73,19 +92,19 @@ class UserComponentClassTestCase(unittest.TestCase):
                 pass
 
     def test_minimal_source(self):
-        class MyIter(bt2._UserNotificationIterator):
+        class MyIter(bt2._UserMessageIterator):
             pass
 
         class MySource(bt2._UserSourceComponent,
-                       notification_iterator_class=MyIter):
+                       message_iterator_class=MyIter):
             pass
 
     def test_minimal_filter(self):
-        class MyIter(bt2._UserNotificationIterator):
+        class MyIter(bt2._UserMessageIterator):
             pass
 
         class MyFilter(bt2._UserFilterComponent,
-                       notification_iterator_class=MyIter):
+                       message_iterator_class=MyIter):
             pass
 
     def test_minimal_sink(self):
@@ -93,11 +112,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):
@@ -105,6 +130,9 @@ 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):
@@ -113,6 +141,9 @@ class UserComponentClassTestCase(unittest.TestCase):
                 def _consume(self):
                     pass
 
+                def _graph_is_configured(self):
+                    pass
+
     def test_description(self):
         class MySink(bt2._UserSinkComponent):
             """
@@ -128,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):
@@ -138,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):
@@ -153,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):
@@ -160,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)
 
@@ -168,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)
 
@@ -176,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):
@@ -188,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):
@@ -200,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
@@ -213,13 +268,50 @@ 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
@@ -236,8 +328,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 {
@@ -269,10 +364,12 @@ class UserComponentClassTestCase(unittest.TestCase):
             def _consume(self):
                 pass
 
+            def _graph_is_configured(self):
+                pass
+
         self.assertEqual(MySink, MySink)
 
 
-@unittest.skip("this is broken")
 class GenericComponentClassTestCase(unittest.TestCase):
     def setUp(self):
         class MySink(bt2._UserSinkComponent):
@@ -284,14 +381,17 @@ class GenericComponentClassTestCase(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 [obj, params, 23]
 
         self._py_comp_cls = MySink
         graph = bt2.Graph()
         comp = graph.add_component(MySink, 'salut')
-        self._comp_cls = comp.component_class
+        self._comp_cls = comp.cls
         self.assertTrue(issubclass(type(self._comp_cls),
                                    bt2.component._GenericComponentClass))
 
This page took 0.029035 seconds and 4 git commands to generate.