Remove `skip-string-normalization` in Python formatter config
[babeltrace.git] / tests / bindings / python / bt2 / test_plugin.py
1 # SPDX-License-Identifier: GPL-2.0-only
2 #
3 # Copyright (C) 2019 EfficiOS Inc.
4 #
5
6 import unittest
7 import bt2
8 import os
9
10
11 _TEST_PLUGIN_PLUGINS_PATH = os.environ["BT_PLUGINS_PATH"]
12 _TEST_PLUGIN_PLUGIN_EXTENSION_BY_OS = {"cygwin": "dll", "mingw": "dll"}
13
14
15 class PluginSetTestCase(unittest.TestCase):
16 def test_create(self):
17 pset = bt2.find_plugins_in_path(_TEST_PLUGIN_PLUGINS_PATH)
18 self.assertTrue(len(pset) >= 3)
19
20 def test_getitem(self):
21 pset = bt2.find_plugins_in_path(_TEST_PLUGIN_PLUGINS_PATH)
22 self.assertTrue(pset[0].path.startswith(_TEST_PLUGIN_PLUGINS_PATH))
23
24 def test_iter(self):
25 pset = bt2.find_plugins_in_path(_TEST_PLUGIN_PLUGINS_PATH)
26 names = set()
27
28 for plugin in pset:
29 names.add(plugin.name)
30
31 self.assertTrue("ctf" in names)
32 self.assertTrue("utils" in names)
33 self.assertTrue("text" in names)
34
35
36 class FindPluginsTestCase(unittest.TestCase):
37 def test_find_nonexistent_dir(self):
38 with self.assertRaises(ValueError):
39 bt2.find_plugins_in_path(
40 "/this/does/not/exist/246703df-cb85-46d5-8406-5e8dc4a88b41"
41 )
42
43 def test_find_none_existing_dir(self):
44 plugins = bt2.find_plugins_in_path(_TEST_PLUGIN_PLUGINS_PATH, recurse=False)
45 self.assertIsNone(plugins)
46
47 def test_find_dir(self):
48 pset = bt2.find_plugins_in_path(_TEST_PLUGIN_PLUGINS_PATH)
49 self.assertTrue(len(pset) >= 3)
50
51 def test_find_file(self):
52 extension = _TEST_PLUGIN_PLUGIN_EXTENSION_BY_OS.get(
53 os.environ["BT_TESTS_OS_TYPE"], "so"
54 )
55 plugin_name = "babeltrace-plugin-utils.{}".format(extension)
56 path = os.path.join(_TEST_PLUGIN_PLUGINS_PATH, "utils", ".libs", plugin_name)
57 pset = bt2.find_plugins_in_path(path)
58 self.assertTrue(len(pset) == 1)
59
60
61 class FindPluginTestCase(unittest.TestCase):
62 def test_find_none(self):
63 plugin = bt2.find_plugin(
64 "this-does-not-exist-246703df-cb85-46d5-8406-5e8dc4a88b41"
65 )
66 self.assertIsNone(plugin)
67
68 def test_find_existing(self):
69 plugin = bt2.find_plugin("ctf", find_in_user_dir=False, find_in_sys_dir=False)
70 self.assertIsNotNone(plugin)
71
72
73 class PluginTestCase(unittest.TestCase):
74 def setUp(self):
75 self._plugin = bt2.find_plugin(
76 "ctf", find_in_user_dir=False, find_in_sys_dir=False
77 )
78
79 def tearDown(self):
80 del self._plugin
81
82 def test_name(self):
83 self.assertEqual(self._plugin.name, "ctf")
84
85 def test_path(self):
86 plugin_path = os.path.abspath(os.path.normcase(self._plugin.path))
87 plugin_path_env = os.path.abspath(os.path.normcase(_TEST_PLUGIN_PLUGINS_PATH))
88 self.assertTrue(plugin_path.startswith(plugin_path_env))
89
90 def test_author(self):
91 self.assertEqual(self._plugin.author, "EfficiOS <https://www.efficios.com/>")
92
93 def test_license(self):
94 self.assertEqual(self._plugin.license, "MIT")
95
96 def test_description(self):
97 self.assertEqual(self._plugin.description, "CTF input and output")
98
99 def test_version(self):
100 self.assertIsNone(self._plugin.version)
101
102 def test_source_comp_classes_len(self):
103 self.assertEqual(len(self._plugin.source_component_classes), 2)
104
105 def test_source_comp_classes_getitem(self):
106 self.assertEqual(self._plugin.source_component_classes["fs"].name, "fs")
107
108 def test_source_comp_classes_getitem_invalid(self):
109 with self.assertRaises(KeyError):
110 self._plugin.source_component_classes["lol"]
111
112 def test_source_comp_classes_iter(self):
113 plugins = {}
114
115 for cc_name, cc in self._plugin.source_component_classes.items():
116 plugins[cc_name] = cc
117
118 self.assertTrue("fs" in plugins)
119 self.assertTrue("lttng-live" in plugins)
120 self.assertEqual(plugins["fs"].name, "fs")
121 self.assertEqual(plugins["lttng-live"].name, "lttng-live")
122
123 def test_filter_comp_classes_len(self):
124 plugin = bt2.find_plugin("utils", find_in_user_dir=False, find_in_sys_dir=False)
125 self.assertEqual(len(plugin.filter_component_classes), 2)
126
127 def test_sink_comp_classes_len(self):
128 self.assertEqual(len(self._plugin.sink_component_classes), 1)
129
130
131 if __name__ == "__main__":
132 unittest.main()
This page took 0.032348 seconds and 4 git commands to generate.