+ def setUp(self):
+ # A source CC from a plugin.
+ self._dmesg_cc = bt2.find_plugin('text').source_component_classes['dmesg']
+ assert self._dmesg_cc is not None
+
+ # A filter CC from a plugin.
+ self._muxer_cc = bt2.find_plugin('utils').filter_component_classes['muxer']
+ assert self._muxer_cc is not None
+
+ # A sink CC from a plugin.
+ self._pretty_cc = bt2.find_plugin('text').sink_component_classes['pretty']
+ assert self._pretty_cc is not None
+
+ def test_create_source_from_name(self):
+ spec = bt2.ComponentSpec.from_named_plugin_and_component_class('text', 'dmesg')
+ self.assertEqual(spec.component_class.name, 'dmesg')
+
+ def test_create_source_from_plugin(self):
+ spec = bt2.ComponentSpec(self._dmesg_cc)
+ self.assertEqual(spec.component_class.name, 'dmesg')
+
+ def test_create_source_from_user(self):
+ spec = bt2.ComponentSpec(_SomeSource)
+ self.assertEqual(spec.component_class.name, '_SomeSource')
+
+ def test_create_filter_from_name(self):
+ spec = bt2.ComponentSpec.from_named_plugin_and_component_class('utils', 'muxer')
+ self.assertEqual(spec.component_class.name, 'muxer')
+
+ def test_create_filter_from_object(self):
+ spec = bt2.ComponentSpec(self._muxer_cc)
+ self.assertEqual(spec.component_class.name, 'muxer')
+
+ def test_create_sink_from_name(self):
+ with self.assertRaisesRegex(
+ KeyError,
+ 'source or filter component class `pretty` not found in plugin `text`',
+ ):
+ bt2.ComponentSpec.from_named_plugin_and_component_class('text', 'pretty')
+
+ def test_create_sink_from_object(self):
+ with self.assertRaisesRegex(
+ TypeError, "'_SinkComponentClass' is not a source or filter component class"
+ ):
+ bt2.ComponentSpec(self._pretty_cc)
+
+ def test_create_from_object_with_params(self):
+ spec = bt2.ComponentSpec(self._dmesg_cc, {'salut': 23})
+ self.assertEqual(spec.params['salut'], 23)
+
+ def test_create_from_name_with_params(self):
+ spec = bt2.ComponentSpec.from_named_plugin_and_component_class(
+ 'text', 'dmesg', {'salut': 23}
+ )
+ self.assertEqual(spec.params['salut'], 23)