Fix: cygwin does not honour LD_LIBRARY_PATH
[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']
811644b8
PP
26
27
28class PluginSetTestCase(unittest.TestCase):
29 def test_create(self):
30 pset = bt2.find_plugins(_TEST_PLUGIN_PLUGINS_PATH)
31 self.assertTrue(len(pset) >= 3)
32
33 def test_getitem(self):
34 pset = bt2.find_plugins(_TEST_PLUGIN_PLUGINS_PATH)
35 self.assertTrue(pset[0].path.startswith(_TEST_PLUGIN_PLUGINS_PATH))
36
37 def test_iter(self):
38 pset = bt2.find_plugins(_TEST_PLUGIN_PLUGINS_PATH)
39 names = set()
40
41 for plugin in pset:
42 names.add(plugin.name)
43
44 self.assertTrue('ctf' in names)
45 self.assertTrue('utils' in names)
46 self.assertTrue('text' in names)
47
48
49class FindPluginsTestCase(unittest.TestCase):
9736d991
PP
50 def test_find_nonexistent_dir(self):
51 with self.assertRaises(bt2.Error):
52 bt2.find_plugins('/this/does/not/exist/246703df-cb85-46d5-8406-5e8dc4a88b41')
53
54 def test_find_none_existing_dir(self):
55 plugins = bt2.find_plugins(_TEST_PLUGIN_PLUGINS_PATH, recurse=False)
56 self.assertIsNone(plugins)
811644b8
PP
57
58 def test_find_dir(self):
59 pset = bt2.find_plugins(_TEST_PLUGIN_PLUGINS_PATH)
60 self.assertTrue(len(pset) >= 3)
61
ab1bca6c
SM
62 def test_find_file(self):
63 path = os.path.join(_TEST_PLUGIN_PLUGINS_PATH, 'utils', '.libs', 'babeltrace-plugin-utils.so')
64 pset = bt2.find_plugins(path)
65 self.assertTrue(len(pset) == 1)
66
811644b8
PP
67
68class FindPluginTestCase(unittest.TestCase):
69 def test_find_none(self):
70 plugin = bt2.find_plugin('this-does-not-exist-246703df-cb85-46d5-8406-5e8dc4a88b41')
71 self.assertIsNone(plugin)
72
73 def test_find_existing(self):
74 plugin = bt2.find_plugin('ctf')
75 self.assertIsInstance(plugin, bt2.plugin._Plugin)
76
77
78class PluginTestCase(unittest.TestCase):
79 def setUp(self):
80 self._plugin = bt2.find_plugin('ctf')
81
82 def tearDown(self):
83 del self._plugin
84
85 def test_name(self):
86 self.assertEqual(self._plugin.name, 'ctf')
87
88 def test_path(self):
9769184f
MJ
89 plugin_path = os.path.normcase(self._plugin.path)
90 plugin_path_env = os.path.normcase(_TEST_PLUGIN_PLUGINS_PATH)
91 self.assertTrue(plugin_path.startswith(plugin_path_env))
811644b8
PP
92
93 def test_author(self):
94 self.assertTrue('Philippe Proulx' in self._plugin.author)
95
96 def test_license(self):
97 self.assertTrue('MIT' in self._plugin.license)
98
99 def test_description(self):
100 self.assertTrue('CTF source and sink support' in self._plugin.description)
101
102 def test_version(self):
103 self.assertIsNone(self._plugin.version)
104
105 def test_source_comp_classes_len(self):
106 self.assertEqual(len(self._plugin.source_component_classes), 2)
107
108 def test_source_comp_classes_getitem(self):
109 self.assertEqual(self._plugin.source_component_classes['fs'].name, 'fs')
110
111 def test_source_comp_classes_getitem_invalid(self):
112 with self.assertRaises(KeyError):
113 self._plugin.source_component_classes['lol']
114
115 def test_source_comp_classes_iter(self):
116 plugins = {}
117
118 for cc_name, cc in self._plugin.source_component_classes.items():
119 plugins[cc_name] = cc
120
121 self.assertTrue('fs' in plugins)
122 self.assertTrue('lttng-live' in plugins)
123 self.assertEqual(plugins['fs'].name, 'fs')
124 self.assertEqual(plugins['lttng-live'].name, 'lttng-live')
125
126 def test_filter_comp_classes_len(self):
127 plugin = bt2.find_plugin('utils')
128 self.assertEqual(len(plugin.filter_component_classes), 2)
129
130 def test_sink_comp_classes_len(self):
131 self.assertEqual(len(self._plugin.sink_component_classes), 1)
This page took 0.038374 seconds and 4 git commands to generate.