lib/plugin/plugin.c: do not use G_MODULE_BIND_LOCAL for Python plugin provider
[babeltrace.git] / tests / bindings / python / bt2 / test_comp_notif_iter.py
index b13294af62e10ca2117a7faccb7fb7146333d277..70afebe9528820f692b6280882c6b164764a8f31 100644 (file)
@@ -122,13 +122,52 @@ class GenCompClassTestCase(unittest.TestCase):
 
     def test_attr_description(self):
         class MySink(bt2.UserSinkComponent):
-            'hello'
+            '''This is the description.
+
+            This is the help.
+
+            This too:
+
+                * And this.
+                * And also that.
+
+            Voilà.
+            '''
+
+            def _consume(self):
+                pass
+
+        sink = MySink()
+        self.assertEqual(sink.component_class.description,
+                         'This is the description.')
+
+    def test_attr_help(self):
+        class MySink(bt2.UserSinkComponent):
+            '''This is the description.
+
+            This is the help.
+
+            This too:
+
+                * And this.
+                * And also that.
+
+            Voilà.
+            '''
 
             def _consume(self):
                 pass
 
         sink = MySink()
-        self.assertEqual(sink.component_class.description, 'hello')
+        expected_help = '''This is the help.
+
+This too:
+
+    * And this.
+    * And also that.
+
+Voilà.'''
+        self.assertEqual(sink.component_class.help, expected_help)
 
     def test_instantiate(self):
         class MySink(bt2.UserSinkComponent):
@@ -173,12 +212,136 @@ class UserCompClassTestCase(unittest.TestCase):
 
     def test_attr_description(self):
         class MySink(bt2.UserSinkComponent):
-            'here is your description'
+            '''This is the description.
+
+            This is the help.
+
+            This too:
+
+                * And this.
+                * And also that.
+
+            Voilà.
+            '''
+
+            def _consume(self):
+                pass
+
+        self.assertEqual(MySink.description, 'This is the description.')
+
+    def test_attr_help(self):
+        class MySink(bt2.UserSinkComponent):
+            '''This is the description.
+
+            This is the help.
+
+            This too:
+
+                * And this.
+                * And also that.
+
+            Voilà.
+            '''
+
+            def _consume(self):
+                pass
+
+        expected_help = '''This is the help.
+
+This too:
+
+    * And this.
+    * And also that.
+
+Voilà.'''
+        self.assertEqual(MySink.help, expected_help)
+
+    def test_query_missing(self):
+        class MySink(bt2.UserSinkComponent):
+            def _consume(self):
+                pass
+
+        with self.assertRaises(bt2.Error):
+            MySink.query('salut')
+
+    def test_query_raises(self):
+        class MySink(bt2.UserSinkComponent):
+            def _consume(self):
+                pass
+
+            @staticmethod
+            def _query(obj, params):
+                raise ValueError
+
+        with self.assertRaises(bt2.Error):
+            MySink.query('salut')
+
+    def test_query_gets_none_params(self):
+        class MySink(bt2.UserSinkComponent):
+            def _consume(self):
+                pass
+
+            @staticmethod
+            def _query(obj, params):
+                nonlocal recv_params
+                recv_params = params
+
+        recv_params = NotImplemented
+        MySink.query('allo', None)
+        self.assertIsNone(recv_params)
+
+    def test_query_gets_same_params(self):
+        class MySink(bt2.UserSinkComponent):
+            def _consume(self):
+                pass
+
+            @staticmethod
+            def _query(obj, params):
+                nonlocal recv_params
+                recv_params = params
+
+        recv_params = NotImplemented
+        params = bt2.create_value(23)
+        MySink.query('allo', params)
+        self.assertEqual(recv_params.addr, params.addr)
+
+    def test_query_obj(self):
+        class MySink(bt2.UserSinkComponent):
+            def _consume(self):
+                pass
+
+            @staticmethod
+            def _query(obj, params):
+                nonlocal recv_obj
+                recv_obj = obj
+
+        recv_obj = None
+        MySink.query('salut')
+        self.assertEqual(recv_obj, 'salut')
+
+    def test_query_returns_none(self):
+        class MySink(bt2.UserSinkComponent):
+            def _consume(self):
+                pass
 
+            @staticmethod
+            def _query(obj, params):
+                pass
+
+        self.assertIsNone(MySink.query('allo', 177))
+
+    def test_query_returns_params(self):
+        class MySink(bt2.UserSinkComponent):
             def _consume(self):
                 pass
 
-        self.assertEqual(MySink.description, 'here is your description')
+            @staticmethod
+            def _query(obj, params):
+                return {'obj': obj, 'params': params}
+
+        results = MySink.query('hello', (45, 'lol'))
+        self.assertEqual(results['obj'], 'hello')
+        self.assertEqual(results['params'], (45, 'lol'))
 
     def test_init(self):
         class MySink(bt2.UserSinkComponent):
This page took 0.02709 seconds and 4 git commands to generate.