Debian Codegraph @

test/plugins/applet/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.applet.GameControllerWakelock": "This is not an X11 screen",
24 "blueman.plugins.applet.KillSwitch": "Hardware kill switch not found",
25 "blueman.plugins.applet.NMDUNSupport": "NM python bindings not found.",
26 "blueman.plugins.applet.NMPANSupport": "NM python bindings not found.",
27 }
28
29 test_cases = TestSuite()
30 home, subpath = os.path.dirname(__file__).rsplit("/test/", 1)
31 for package in pkgutil.iter_modules([f"{home}/blueman/{subpath}"], f"blueman.{subpath.replace('/', '.')}."):
32 test_cases.addTest(TestImports(package.name, expected_exceptions.get(package.name)))
33
34 assert test_cases.countTestCases() > 0
35
36 return test_cases