| 1 |
#!/usr/bin/python3 |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright 2021 Mike Fährmann |
| 5 |
# |
| 6 |
# This program is free software; you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License version 2 as |
| 8 |
# published by the Free Software Foundation. |
| 9 |
|
| 10 |
import os |
| 11 |
import sys |
| 12 |
import unittest |
| 13 |
|
| 14 |
TEST_DIRECTORY = "test" |
| 15 |
|
| 16 |
sys.path.insert(0, TEST_DIRECTORY) |
| 17 |
|
| 18 |
if len(sys.argv) <= 1: |
| 19 |
TESTS = [ |
| 20 |
file.rpartition(".")[0] |
| 21 |
for file in os.listdir(TEST_DIRECTORY) |
| 22 |
if file.startswith("test_") and file != "test_results.py" |
| 23 |
] |
| 24 |
else: |
| 25 |
TESTS = [ |
| 26 |
name if name.startswith("test_") else "test_" + name |
| 27 |
for name in sys.argv[1:] |
| 28 |
] |
| 29 |
|
| 30 |
|
| 31 |
suite = unittest.TestSuite() |
| 32 |
|
| 33 |
for test in TESTS: |
| 34 |
try: |
| 35 |
module = __import__(test) |
| 36 |
except ImportError: |
| 37 |
print("unable to import", test) |
| 38 |
else: |
| 39 |
tests = unittest.defaultTestLoader.loadTestsFromModule(module) |
| 40 |
suite.addTests(tests) |
| 41 |
|
| 42 |
if __name__ == "__main__": |
| 43 |
result = unittest.TextTestRunner(verbosity=2).run(suite) |
| 44 |
if result.errors or result.failures: |
| 45 |
sys.exit(1) |