tests: Move data files to a common directory
[babeltrace.git] / tests / bindings / python / bt2 / test_plugin.py
CommitLineData
811644b8 1import unittest
811644b8
PP
2import bt2
3import bt2.plugin
4import os
5
6
7_TEST_PLUGIN_PLUGINS_PATH = os.environ['TEST_PLUGIN_PLUGINS_PATH']
8
9
10class PluginSetTestCase(unittest.TestCase):
11 def test_create(self):
12 pset = bt2.find_plugins(_TEST_PLUGIN_PLUGINS_PATH)
13 self.assertTrue(len(pset) >= 3)
14
15 def test_getitem(self):
16 pset = bt2.find_plugins(_TEST_PLUGIN_PLUGINS_PATH)
17 self.assertTrue(pset[0].path.startswith(_TEST_PLUGIN_PLUGINS_PATH))
18
19 def test_iter(self):
20 pset = bt2.find_plugins(_TEST_PLUGIN_PLUGINS_PATH)
21 names = set()
22
23 for plugin in pset:
24 names.add(plugin.name)
25
26 self.assertTrue('ctf' in names)
27 self.assertTrue('utils' in names)
28 self.assertTrue('text' in names)
29
30
31class FindPluginsTestCase(unittest.TestCase):
32 def test_find_none(self):
33 pset = bt2.find_plugins('/this/does/not/exist/246703df-cb85-46d5-8406-5e8dc4a88b41')
34 self.assertIsNone(pset)
35
36 def test_find_dir(self):
37 pset = bt2.find_plugins(_TEST_PLUGIN_PLUGINS_PATH)
38 self.assertTrue(len(pset) >= 3)
39
ab1bca6c
SM
40 def test_find_file(self):
41 path = os.path.join(_TEST_PLUGIN_PLUGINS_PATH, 'utils', '.libs', 'babeltrace-plugin-utils.so')
42 pset = bt2.find_plugins(path)
43 self.assertTrue(len(pset) == 1)
44
811644b8
PP
45
46class FindPluginTestCase(unittest.TestCase):
47 def test_find_none(self):
48 plugin = bt2.find_plugin('this-does-not-exist-246703df-cb85-46d5-8406-5e8dc4a88b41')
49 self.assertIsNone(plugin)
50
51 def test_find_existing(self):
52 plugin = bt2.find_plugin('ctf')
53 self.assertIsInstance(plugin, bt2.plugin._Plugin)
54
55
56class PluginTestCase(unittest.TestCase):
57 def setUp(self):
58 self._plugin = bt2.find_plugin('ctf')
59
60 def tearDown(self):
61 del self._plugin
62
63 def test_name(self):
64 self.assertEqual(self._plugin.name, 'ctf')
65
66 def test_path(self):
9769184f
MJ
67 plugin_path = os.path.normcase(self._plugin.path)
68 plugin_path_env = os.path.normcase(_TEST_PLUGIN_PLUGINS_PATH)
69 self.assertTrue(plugin_path.startswith(plugin_path_env))
811644b8
PP
70
71 def test_author(self):
72 self.assertTrue('Philippe Proulx' in self._plugin.author)
73
74 def test_license(self):
75 self.assertTrue('MIT' in self._plugin.license)
76
77 def test_description(self):
78 self.assertTrue('CTF source and sink support' in self._plugin.description)
79
80 def test_version(self):
81 self.assertIsNone(self._plugin.version)
82
83 def test_source_comp_classes_len(self):
84 self.assertEqual(len(self._plugin.source_component_classes), 2)
85
86 def test_source_comp_classes_getitem(self):
87 self.assertEqual(self._plugin.source_component_classes['fs'].name, 'fs')
88
89 def test_source_comp_classes_getitem_invalid(self):
90 with self.assertRaises(KeyError):
91 self._plugin.source_component_classes['lol']
92
93 def test_source_comp_classes_iter(self):
94 plugins = {}
95
96 for cc_name, cc in self._plugin.source_component_classes.items():
97 plugins[cc_name] = cc
98
99 self.assertTrue('fs' in plugins)
100 self.assertTrue('lttng-live' in plugins)
101 self.assertEqual(plugins['fs'].name, 'fs')
102 self.assertEqual(plugins['lttng-live'].name, 'lttng-live')
103
104 def test_filter_comp_classes_len(self):
105 plugin = bt2.find_plugin('utils')
106 self.assertEqual(len(plugin.filter_component_classes), 2)
107
108 def test_sink_comp_classes_len(self):
109 self.assertEqual(len(self._plugin.sink_component_classes), 1)
This page took 0.034313 seconds and 4 git commands to generate.