bt2: make bt2 add graph listener wrappers append error causes
[babeltrace.git] / tests / bindings / python / bt2 / test_plugin.py
CommitLineData
d2d857a8
MJ
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
811644b8 19import unittest
811644b8
PP
20import bt2
21import bt2.plugin
22import os
23
24
644e0364 25_TEST_PLUGIN_PLUGINS_PATH = os.environ['BT_PLUGINS_PATH']
d4b72099 26_TEST_PLUGIN_PLUGIN_EXTENSION_BY_OS = {'cygwin': 'dll', 'mingw': 'dll'}
811644b8
PP
27
28
29class 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
50class FindPluginsTestCase(unittest.TestCase):
9736d991
PP
51 def test_find_nonexistent_dir(self):
52 with self.assertRaises(bt2.Error):
cfbd7cf3
FD
53 bt2.find_plugins(
54 '/this/does/not/exist/246703df-cb85-46d5-8406-5e8dc4a88b41'
55 )
9736d991
PP
56
57 def test_find_none_existing_dir(self):
58 plugins = bt2.find_plugins(_TEST_PLUGIN_PLUGINS_PATH, recurse=False)
59 self.assertIsNone(plugins)
811644b8
PP
60
61 def test_find_dir(self):
62 pset = bt2.find_plugins(_TEST_PLUGIN_PLUGINS_PATH)
63 self.assertTrue(len(pset) >= 3)
64
ab1bca6c 65 def test_find_file(self):
cfbd7cf3
FD
66 extension = _TEST_PLUGIN_PLUGIN_EXTENSION_BY_OS.get(
67 os.environ['BT_OS_TYPE'], 'so'
68 )
d4b72099
JR
69 plugin_name = 'babeltrace-plugin-utils.{}'.format(extension)
70 path = os.path.join(_TEST_PLUGIN_PLUGINS_PATH, 'utils', '.libs', plugin_name)
ab1bca6c
SM
71 pset = bt2.find_plugins(path)
72 self.assertTrue(len(pset) == 1)
73
811644b8
PP
74
75class FindPluginTestCase(unittest.TestCase):
76 def test_find_none(self):
cfbd7cf3
FD
77 plugin = bt2.find_plugin(
78 'this-does-not-exist-246703df-cb85-46d5-8406-5e8dc4a88b41'
79 )
811644b8
PP
80 self.assertIsNone(plugin)
81
82 def test_find_existing(self):
83 plugin = bt2.find_plugin('ctf')
84 self.assertIsInstance(plugin, bt2.plugin._Plugin)
85
86
87class PluginTestCase(unittest.TestCase):
88 def setUp(self):
89 self._plugin = bt2.find_plugin('ctf')
90
91 def tearDown(self):
92 del self._plugin
93
94 def test_name(self):
95 self.assertEqual(self._plugin.name, 'ctf')
96
97 def test_path(self):
824cfbd8
JR
98 plugin_path = os.path.abspath(os.path.normcase(self._plugin.path))
99 plugin_path_env = os.path.abspath(os.path.normcase(_TEST_PLUGIN_PLUGINS_PATH))
9769184f 100 self.assertTrue(plugin_path.startswith(plugin_path_env))
811644b8
PP
101
102 def test_author(self):
103 self.assertTrue('Philippe Proulx' in self._plugin.author)
104
105 def test_license(self):
106 self.assertTrue('MIT' in self._plugin.license)
107
108 def test_description(self):
109 self.assertTrue('CTF source and sink support' in self._plugin.description)
110
111 def test_version(self):
112 self.assertIsNone(self._plugin.version)
113
114 def test_source_comp_classes_len(self):
115 self.assertEqual(len(self._plugin.source_component_classes), 2)
116
117 def test_source_comp_classes_getitem(self):
118 self.assertEqual(self._plugin.source_component_classes['fs'].name, 'fs')
119
120 def test_source_comp_classes_getitem_invalid(self):
121 with self.assertRaises(KeyError):
122 self._plugin.source_component_classes['lol']
123
124 def test_source_comp_classes_iter(self):
125 plugins = {}
126
127 for cc_name, cc in self._plugin.source_component_classes.items():
128 plugins[cc_name] = cc
129
130 self.assertTrue('fs' in plugins)
131 self.assertTrue('lttng-live' in plugins)
132 self.assertEqual(plugins['fs'].name, 'fs')
133 self.assertEqual(plugins['lttng-live'].name, 'lttng-live')
134
135 def test_filter_comp_classes_len(self):
136 plugin = bt2.find_plugin('utils')
137 self.assertEqual(len(plugin.filter_component_classes), 2)
138
139 def test_sink_comp_classes_len(self):
140 self.assertEqual(len(self._plugin.sink_component_classes), 1)
This page took 0.03979 seconds and 4 git commands to generate.