| 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.main.NetworkManager": "NM python bindings not found.", |
| 24 |
"blueman.main.PulseAudioUtils": "Could not load pulseaudio shared library", |
| 25 |
} |
| 26 |
|
| 27 |
test_cases = TestSuite() |
| 28 |
home, subpath = os.path.dirname(__file__).rsplit("/test/", 1) |
| 29 |
for package in pkgutil.iter_modules([f"{home}/blueman/{subpath}"], f"blueman.{subpath.replace('/', '.')}."): |
| 30 |
test_cases.addTest(TestImports(package.name, expected_exceptions.get(package.name))) |
| 31 |
|
| 32 |
assert test_cases.countTestCases() > 0 |
| 33 |
|
| 34 |
return test_cases |