Debian Codegraph @

test/plugins/manager/test_imports.py

raw
1 import os.path
2 import pkgutil
3 from unittest import TestCase, TestSuite
4
5
6 class TestImports(TestCase):
7 def __init__(self, mod_name, import_error):
8 name = f"test_{mod_name.replace('.', '_')}_import"
9
10 def run():
11 try:
12 __import__(mod_name)
13 except ImportError as e:
14 self.assertIsNotNone(import_error)
15 self.assertEqual(e.msg, import_error)
16
17 setattr(self, name, run)
18 super().__init__(name)
19
20
21 def load_tests(*_args):
22 expected_exceptions = {
23 "blueman.plugins.manager.PulseAudioProfile": "Could not load pulseaudio shared library",
24 }
25
26 test_cases = TestSuite()
27 home, subpath = os.path.dirname(__file__).rsplit("/test/", 1)
28 for package in pkgutil.iter_modules([f"{home}/blueman/{subpath}"], f"blueman.{subpath.replace('/', '.')}."):
29 test_cases.addTest(TestImports(package.name, expected_exceptions.get(package.name)))
30
31 assert test_cases.countTestCases() > 0
32
33 return test_cases