2096d84b2301e49d88a00c0cab443fea05e5ed85
[babeltrace.git] / tests / bindings / python / bt2 / test_plugin.py
1 #
2 # Copyright (C) 2019 EfficiOS Inc.
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; only version 2
7 # of the License.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 #
18
19 import unittest
20 import bt2
21 import bt2.plugin
22 import os
23
24
25 _TEST_PLUGIN_PLUGINS_PATH = os.environ['BT_PLUGINS_PATH']
26 _TEST_PLUGIN_PLUGIN_EXTENSION_BY_OS = {'cygwin': 'dll', 'mingw': 'dll'}
27
28
29 class PluginSetTestCase(unittest.TestCase):
30 def test_create(self):
31 pset = bt2.find_plugins(_TEST_PLUGIN_PLUGINS_PATH)
32 self.assertTrue(len(pset) >= 3)
33
34 def test_getitem(self):
35 pset = bt2.find_plugins(_TEST_PLUGIN_PLUGINS_PATH)
36 self.assertTrue(pset[0].path.startswith(_TEST_PLUGIN_PLUGINS_PATH))
37
38 def test_iter(self):
39 pset = bt2.find_plugins(_TEST_PLUGIN_PLUGINS_PATH)
40 names = set()
41
42 for plugin in pset:
43 names.add(plugin.name)
44
45 self.assertTrue('ctf' in names)
46 self.assertTrue('utils' in names)
47 self.assertTrue('text' in names)
48
49
50 class FindPluginsTestCase(unittest.TestCase):
51 def test_find_nonexistent_dir(self):
52 with self.assertRaises(bt2.Error):
53 bt2.find_plugins('/this/does/not/exist/246703df-cb85-46d5-8406-5e8dc4a88b41')
54
55 def test_find_none_existing_dir(self):
56 plugins = bt2.find_plugins(_TEST_PLUGIN_PLUGINS_PATH, recurse=False)
57 self.assertIsNone(plugins)
58
59 def test_find_dir(self):
60 pset = bt2.find_plugins(_TEST_PLUGIN_PLUGINS_PATH)
61 self.assertTrue(len(pset) >= 3)
62
63 def test_find_file(self):
64 extension = _TEST_PLUGIN_PLUGIN_EXTENSION_BY_OS.get(os.environ['BT_OS_TYPE'], 'so')
65 plugin_name = 'babeltrace-plugin-utils.{}'.format(extension)
66 path = os.path.join(_TEST_PLUGIN_PLUGINS_PATH, 'utils', '.libs', plugin_name)
67 pset = bt2.find_plugins(path)
68 self.assertTrue(len(pset) == 1)
69
70
71 class FindPluginTestCase(unittest.TestCase):
72 def test_find_none(self):
73 plugin = bt2.find_plugin('this-does-not-exist-246703df-cb85-46d5-8406-5e8dc4a88b41')
74 self.assertIsNone(plugin)
75
76 def test_find_existing(self):
77 plugin = bt2.find_plugin('ctf')
78 self.assertIsInstance(plugin, bt2.plugin._Plugin)
79
80
81 class PluginTestCase(unittest.TestCase):
82 def setUp(self):
83 self._plugin = bt2.find_plugin('ctf')
84
85 def tearDown(self):
86 del self._plugin
87
88 def test_name(self):
89 self.assertEqual(self._plugin.name, 'ctf')
90
91 def test_path(self):
92 plugin_path = os.path.normcase(self._plugin.path)
93 plugin_path_env = os.path.normcase(_TEST_PLUGIN_PLUGINS_PATH)
94 self.assertTrue(plugin_path.startswith(plugin_path_env))
95
96 def test_author(self):
97 self.assertTrue('Philippe Proulx' in self._plugin.author)
98
99 def test_license(self):
100 self.assertTrue('MIT' in self._plugin.license)
101
102 def test_description(self):
103 self.assertTrue('CTF source and sink support' in self._plugin.description)
104
105 def test_version(self):
106 self.assertIsNone(self._plugin.version)
107
108 def test_source_comp_classes_len(self):
109 self.assertEqual(len(self._plugin.source_component_classes), 2)
110
111 def test_source_comp_classes_getitem(self):
112 self.assertEqual(self._plugin.source_component_classes['fs'].name, 'fs')
113
114 def test_source_comp_classes_getitem_invalid(self):
115 with self.assertRaises(KeyError):
116 self._plugin.source_component_classes['lol']
117
118 def test_source_comp_classes_iter(self):
119 plugins = {}
120
121 for cc_name, cc in self._plugin.source_component_classes.items():
122 plugins[cc_name] = cc
123
124 self.assertTrue('fs' in plugins)
125 self.assertTrue('lttng-live' in plugins)
126 self.assertEqual(plugins['fs'].name, 'fs')
127 self.assertEqual(plugins['lttng-live'].name, 'lttng-live')
128
129 def test_filter_comp_classes_len(self):
130 plugin = bt2.find_plugin('utils')
131 self.assertEqual(len(plugin.filter_component_classes), 2)
132
133 def test_sink_comp_classes_len(self):
134 self.assertEqual(len(self._plugin.sink_component_classes), 1)
This page took 0.032469 seconds and 3 git commands to generate.