+ 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,
+ "'_SinkComponentClassConst' 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)
+
+ def test_create_from_object_with_path_params(self):
+ spec = spec = bt2.ComponentSpec(self._dmesg_cc, "a path")
+ self.assertEqual(spec.params["inputs"], ["a path"])
+
+ def test_create_from_name_with_path_params(self):
+ spec = spec = bt2.ComponentSpec.from_named_plugin_and_component_class(
+ "text", "dmesg", "a path"
+ )
+ self.assertEqual(spec.params["inputs"], ["a path"])
+
+ def test_create_wrong_comp_class_type(self):
+ with self.assertRaisesRegex(
+ TypeError, "'int' is not a source or filter component class"
+ ):
+ bt2.ComponentSpec(18)
+
+ def test_create_from_name_wrong_plugin_name_type(self):
+ with self.assertRaisesRegex(TypeError, "'int' is not a 'str' object"):
+ bt2.ComponentSpec.from_named_plugin_and_component_class(23, "compcls")
+
+ def test_create_from_name_non_existent_plugin(self):
+ with self.assertRaisesRegex(
+ ValueError, "no such plugin: this_plugin_does_not_exist"
+ ):
+ bt2.ComponentSpec.from_named_plugin_and_component_class(
+ "this_plugin_does_not_exist", "compcls"
+ )
+
+ def test_create_from_name_wrong_component_class_name_type(self):
+ with self.assertRaisesRegex(TypeError, "'int' is not a 'str' object"):
+ bt2.ComponentSpec.from_named_plugin_and_component_class("utils", 190)