bt2: check for _graph_is_configured method in user sink classes
[babeltrace.git] / tests / bindings / python / bt2 / test_component.py
index a01404e4c074345d828bcb158b042e42b9dc903a..69e5617b33808245ea0502f327fd699b1248da81 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 copy
@@ -6,13 +24,13 @@ import bt2
 
 class UserComponentTestCase(unittest.TestCase):
     @staticmethod
-    def _create_comp(comp_cls, name=None):
+    def _create_comp(comp_cls, name=None, log_level=bt2.LoggingLevel.NONE):
         graph = bt2.Graph()
 
         if name is None:
             name = 'comp'
 
-        return graph.add_component(comp_cls, name)
+        return graph.add_component(comp_cls, name, logging_level=log_level)
 
     def test_name(self):
         class MySink(bt2._UserSinkComponent):
@@ -22,8 +40,24 @@ class UserComponentTestCase(unittest.TestCase):
             def _consume(self):
                 pass
 
+            def _graph_is_configured(self):
+                pass
+
         comp = self._create_comp(MySink, 'yaes')
 
+    def test_logging_level(self):
+        class MySink(bt2._UserSinkComponent):
+            def __init__(comp_self, params):
+                self.assertEqual(comp_self.logging_level, bt2.LoggingLevel.INFO)
+
+            def _consume(self):
+                pass
+
+            def _graph_is_configured(self):
+                pass
+
+        comp = self._create_comp(MySink, 'yaes', bt2.LoggingLevel.INFO)
+
     def test_class(self):
         class MySink(bt2._UserSinkComponent):
             def __init__(comp_self, params):
@@ -32,6 +66,9 @@ class UserComponentTestCase(unittest.TestCase):
             def _consume(self):
                 pass
 
+            def _graph_is_configured(self):
+                pass
+
         self._create_comp(MySink)
 
     def test_addr(self):
@@ -43,6 +80,9 @@ class UserComponentTestCase(unittest.TestCase):
             def _consume(self):
                 pass
 
+            def _graph_is_configured(self):
+                pass
+
         self._create_comp(MySink)
 
     def test_finalize(self):
@@ -52,6 +92,9 @@ class UserComponentTestCase(unittest.TestCase):
             def _consume(self):
                 pass
 
+            def _graph_is_configured(self):
+                pass
+
             def _finalize(comp_self):
                 nonlocal finalized
                 finalized = True
@@ -66,27 +109,44 @@ class UserComponentTestCase(unittest.TestCase):
 
 class GenericComponentTestCase(unittest.TestCase):
     @staticmethod
-    def _create_comp(comp_cls, name=None):
+    def _create_comp(comp_cls, name=None, log_level=bt2.LoggingLevel.NONE):
         graph = bt2.Graph()
 
         if name is None:
             name = 'comp'
 
-        return graph.add_component(comp_cls, name)
+        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):
+                pass
+
         comp = self._create_comp(MySink, 'yaes')
         self.assertEqual(comp.name, 'yaes')
 
+    def test_logging_level(self):
+        class MySink(bt2._UserSinkComponent):
+            def _consume(self):
+                pass
+
+            def _graph_is_configured(self):
+                pass
+
+        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):
+                pass
+
         comp = self._create_comp(MySink)
         self.assertEqual(comp.cls, MySink)
 
@@ -95,6 +155,9 @@ class GenericComponentTestCase(unittest.TestCase):
             def _consume(self):
                 pass
 
+            def _graph_is_configured(self):
+                pass
+
         comp = self._create_comp(MySink)
         self.assertIsInstance(comp.addr, int)
         self.assertNotEqual(comp.addr, 0)
This page took 0.02608 seconds and 4 git commands to generate.