tests: rename BT_OS_TYPE to BT_TESTS_OS_TYPE
[babeltrace.git] / tests / bindings / python / bt2 / test_plugin.py
CommitLineData
0235b0db 1# SPDX-License-Identifier: GPL-2.0-only
d2d857a8
MJ
2#
3# Copyright (C) 2019 EfficiOS Inc.
4#
d2d857a8 5
811644b8 6import unittest
811644b8 7import bt2
811644b8
PP
8import os
9
10
644e0364 11_TEST_PLUGIN_PLUGINS_PATH = os.environ['BT_PLUGINS_PATH']
d4b72099 12_TEST_PLUGIN_PLUGIN_EXTENSION_BY_OS = {'cygwin': 'dll', 'mingw': 'dll'}
811644b8
PP
13
14
15class PluginSetTestCase(unittest.TestCase):
16 def test_create(self):
577fa92f 17 pset = bt2.find_plugins_in_path(_TEST_PLUGIN_PLUGINS_PATH)
811644b8
PP
18 self.assertTrue(len(pset) >= 3)
19
20 def test_getitem(self):
577fa92f 21 pset = bt2.find_plugins_in_path(_TEST_PLUGIN_PLUGINS_PATH)
811644b8
PP
22 self.assertTrue(pset[0].path.startswith(_TEST_PLUGIN_PLUGINS_PATH))
23
24 def test_iter(self):
577fa92f 25 pset = bt2.find_plugins_in_path(_TEST_PLUGIN_PLUGINS_PATH)
811644b8
PP
26 names = set()
27
28 for plugin in pset:
29 names.add(plugin.name)
30
31 self.assertTrue('ctf' in names)
32 self.assertTrue('utils' in names)
33 self.assertTrue('text' in names)
34
35
36class FindPluginsTestCase(unittest.TestCase):
9736d991 37 def test_find_nonexistent_dir(self):
ce4923b0 38 with self.assertRaises(ValueError):
577fa92f 39 bt2.find_plugins_in_path(
cfbd7cf3
FD
40 '/this/does/not/exist/246703df-cb85-46d5-8406-5e8dc4a88b41'
41 )
9736d991
PP
42
43 def test_find_none_existing_dir(self):
577fa92f 44 plugins = bt2.find_plugins_in_path(_TEST_PLUGIN_PLUGINS_PATH, recurse=False)
9736d991 45 self.assertIsNone(plugins)
811644b8
PP
46
47 def test_find_dir(self):
577fa92f 48 pset = bt2.find_plugins_in_path(_TEST_PLUGIN_PLUGINS_PATH)
811644b8
PP
49 self.assertTrue(len(pset) >= 3)
50
ab1bca6c 51 def test_find_file(self):
cfbd7cf3 52 extension = _TEST_PLUGIN_PLUGIN_EXTENSION_BY_OS.get(
a0baab4a 53 os.environ['BT_TESTS_OS_TYPE'], 'so'
cfbd7cf3 54 )
d4b72099
JR
55 plugin_name = 'babeltrace-plugin-utils.{}'.format(extension)
56 path = os.path.join(_TEST_PLUGIN_PLUGINS_PATH, 'utils', '.libs', plugin_name)
577fa92f 57 pset = bt2.find_plugins_in_path(path)
ab1bca6c
SM
58 self.assertTrue(len(pset) == 1)
59
811644b8
PP
60
61class FindPluginTestCase(unittest.TestCase):
62 def test_find_none(self):
cfbd7cf3
FD
63 plugin = bt2.find_plugin(
64 'this-does-not-exist-246703df-cb85-46d5-8406-5e8dc4a88b41'
65 )
811644b8
PP
66 self.assertIsNone(plugin)
67
68 def test_find_existing(self):
577fa92f 69 plugin = bt2.find_plugin('ctf', find_in_user_dir=False, find_in_sys_dir=False)
082db648 70 self.assertIsNotNone(plugin)
811644b8
PP
71
72
73class PluginTestCase(unittest.TestCase):
74 def setUp(self):
1045f82b
PP
75 self._plugin = bt2.find_plugin(
76 'ctf', find_in_user_dir=False, find_in_sys_dir=False
77 )
811644b8
PP
78
79 def tearDown(self):
80 del self._plugin
81
82 def test_name(self):
83 self.assertEqual(self._plugin.name, 'ctf')
84
85 def test_path(self):
824cfbd8
JR
86 plugin_path = os.path.abspath(os.path.normcase(self._plugin.path))
87 plugin_path_env = os.path.abspath(os.path.normcase(_TEST_PLUGIN_PLUGINS_PATH))
9769184f 88 self.assertTrue(plugin_path.startswith(plugin_path_env))
811644b8
PP
89
90 def test_author(self):
602d20a2 91 self.assertEqual(self._plugin.author, 'EfficiOS <https://www.efficios.com/>')
811644b8
PP
92
93 def test_license(self):
602d20a2 94 self.assertEqual(self._plugin.license, 'MIT')
811644b8
PP
95
96 def test_description(self):
602d20a2 97 self.assertEqual(self._plugin.description, 'CTF input and output')
811644b8
PP
98
99 def test_version(self):
100 self.assertIsNone(self._plugin.version)
101
102 def test_source_comp_classes_len(self):
103 self.assertEqual(len(self._plugin.source_component_classes), 2)
104
105 def test_source_comp_classes_getitem(self):
106 self.assertEqual(self._plugin.source_component_classes['fs'].name, 'fs')
107
108 def test_source_comp_classes_getitem_invalid(self):
109 with self.assertRaises(KeyError):
110 self._plugin.source_component_classes['lol']
111
112 def test_source_comp_classes_iter(self):
113 plugins = {}
114
115 for cc_name, cc in self._plugin.source_component_classes.items():
116 plugins[cc_name] = cc
117
118 self.assertTrue('fs' in plugins)
119 self.assertTrue('lttng-live' in plugins)
120 self.assertEqual(plugins['fs'].name, 'fs')
121 self.assertEqual(plugins['lttng-live'].name, 'lttng-live')
122
123 def test_filter_comp_classes_len(self):
1045f82b 124 plugin = bt2.find_plugin('utils', find_in_user_dir=False, find_in_sys_dir=False)
811644b8
PP
125 self.assertEqual(len(plugin.filter_component_classes), 2)
126
127 def test_sink_comp_classes_len(self):
128 self.assertEqual(len(self._plugin.sink_component_classes), 1)
d14ddbba
SM
129
130
131if __name__ == '__main__':
132 unittest.main()
This page took 0.060445 seconds and 4 git commands to generate.