2 # Copyright (C) 2019 EfficiOS Inc.
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
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.
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.
25 _TEST_PLUGIN_PLUGINS_PATH
= os
.environ
['TEST_PLUGIN_PLUGINS_PATH']
28 class PluginSetTestCase(unittest
.TestCase
):
29 def test_create(self
):
30 pset
= bt2
.find_plugins(_TEST_PLUGIN_PLUGINS_PATH
)
31 self
.assertTrue(len(pset
) >= 3)
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
))
38 pset
= bt2
.find_plugins(_TEST_PLUGIN_PLUGINS_PATH
)
42 names
.add(plugin
.name
)
44 self
.assertTrue('ctf' in names
)
45 self
.assertTrue('utils' in names
)
46 self
.assertTrue('text' in names
)
49 class FindPluginsTestCase(unittest
.TestCase
):
50 def test_find_none(self
):
51 pset
= bt2
.find_plugins('/this/does/not/exist/246703df-cb85-46d5-8406-5e8dc4a88b41')
52 self
.assertIsNone(pset
)
54 def test_find_dir(self
):
55 pset
= bt2
.find_plugins(_TEST_PLUGIN_PLUGINS_PATH
)
56 self
.assertTrue(len(pset
) >= 3)
58 def test_find_file(self
):
59 path
= os
.path
.join(_TEST_PLUGIN_PLUGINS_PATH
, 'utils', '.libs', 'babeltrace-plugin-utils.so')
60 pset
= bt2
.find_plugins(path
)
61 self
.assertTrue(len(pset
) == 1)
64 class FindPluginTestCase(unittest
.TestCase
):
65 def test_find_none(self
):
66 plugin
= bt2
.find_plugin('this-does-not-exist-246703df-cb85-46d5-8406-5e8dc4a88b41')
67 self
.assertIsNone(plugin
)
69 def test_find_existing(self
):
70 plugin
= bt2
.find_plugin('ctf')
71 self
.assertIsInstance(plugin
, bt2
.plugin
._Plugin
)
74 class PluginTestCase(unittest
.TestCase
):
76 self
._plugin
= bt2
.find_plugin('ctf')
82 self
.assertEqual(self
._plugin
.name
, 'ctf')
85 plugin_path
= os
.path
.normcase(self
._plugin
.path
)
86 plugin_path_env
= os
.path
.normcase(_TEST_PLUGIN_PLUGINS_PATH
)
87 self
.assertTrue(plugin_path
.startswith(plugin_path_env
))
89 def test_author(self
):
90 self
.assertTrue('Philippe Proulx' in self
._plugin
.author
)
92 def test_license(self
):
93 self
.assertTrue('MIT' in self
._plugin
.license
)
95 def test_description(self
):
96 self
.assertTrue('CTF source and sink support' in self
._plugin
.description
)
98 def test_version(self
):
99 self
.assertIsNone(self
._plugin
.version
)
101 def test_source_comp_classes_len(self
):
102 self
.assertEqual(len(self
._plugin
.source_component_classes
), 2)
104 def test_source_comp_classes_getitem(self
):
105 self
.assertEqual(self
._plugin
.source_component_classes
['fs'].name
, 'fs')
107 def test_source_comp_classes_getitem_invalid(self
):
108 with self
.assertRaises(KeyError):
109 self
._plugin
.source_component_classes
['lol']
111 def test_source_comp_classes_iter(self
):
114 for cc_name
, cc
in self
._plugin
.source_component_classes
.items():
115 plugins
[cc_name
] = cc
117 self
.assertTrue('fs' in plugins
)
118 self
.assertTrue('lttng-live' in plugins
)
119 self
.assertEqual(plugins
['fs'].name
, 'fs')
120 self
.assertEqual(plugins
['lttng-live'].name
, 'lttng-live')
122 def test_filter_comp_classes_len(self
):
123 plugin
= bt2
.find_plugin('utils')
124 self
.assertEqual(len(plugin
.filter_component_classes
), 2)
126 def test_sink_comp_classes_len(self
):
127 self
.assertEqual(len(self
._plugin
.sink_component_classes
), 1)