-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathtest_import.py
27 lines (21 loc) · 982 Bytes
/
test_import.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import os
import pkgutil
import subprocess
import sys
from pathlib import Path
from typing import List
from unittest import TestCase
from parameterized import parameterized
_PROJECT_ROOT = Path(__file__).parent.parent
def scan_modules_recursively(module_name: str = "samtranslator") -> List[str]:
all_modules: List[str] = [module_name]
for submodule in pkgutil.iter_modules([os.path.join(_PROJECT_ROOT, module_name.replace(".", os.path.sep))]):
submodule_name = module_name + "." + submodule.name
all_modules += scan_modules_recursively(submodule_name)
return all_modules
class TestImport(TestCase):
@parameterized.expand([(module_path,) for module_path in scan_modules_recursively()])
def test_import(self, module_path: str):
pipe = subprocess.Popen([sys.executable, "-c", f"import {module_path}"], stderr=subprocess.PIPE)
_, stderr = pipe.communicate()
self.assertEqual(pipe.returncode, 0, stderr.decode("utf-8"))