-
-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathtest.py
More file actions
40 lines (35 loc) · 1.29 KB
/
test.py
File metadata and controls
40 lines (35 loc) · 1.29 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
import sys
import unittest
from pathlib import Path
from importlib import import_module
from calibre.utils.run_tests import run_cli # type: ignore
def get_test_suite(filenames=[]):
suite = unittest.TestSuite()
patterns = ['test_*.py']
if len(filenames) > 0:
patterns = []
for filename in filenames:
patterns.append(filename)
for pattern in patterns:
for path in Path('tests').rglob(pattern):
module_name = '.'.join(path.with_suffix('').parts)
test_module = import_module(
f'calibre_plugins.ebook_translator.{module_name}')
suite.addTests(
unittest.defaultTestLoader.loadTestsFromModule(test_module))
return suite
if __name__ == '__main__':
filenames, methods = [], []
for arg in sys.argv[1:]:
if Path(arg).suffix == '.py':
filenames.append(arg)
else:
methods.append(arg)
patterns = [f'*{m}' for m in methods] if len(methods) > 0 else None
unittest.defaultTestLoader.testNamePatterns = patterns
suite = get_test_suite(filenames)
# runner = unittest.TextTestRunner(verbosity=1, failfast=True)
# result = runner.run(suite)
# if not result.wasSuccessful():
# exit(1)
run_cli(suite, verbosity=4, buffer=False)