feat(wallpaper_changer): run unit and integration tests, integration test dir
This commit is contained in:
1 parent
7f729330c7
commit
e891d00ef9
2 files changed
+52
No files matched your search
@@ -0,0 +1,51 @@
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
from serverlibrary import setup_logging
|
||||
|
||||
|
||||
TESTS_DIR = Path(__file__).resolve().parent
|
||||
PROJECT_DIR = TESTS_DIR.parent
|
||||
SOURCE_DIR = PROJECT_DIR / "src"
|
||||
|
||||
if str(SOURCE_DIR) not in sys.path:
|
||||
sys.path.insert(0, str(SOURCE_DIR))
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description="Run wallpaper changer tests.")
|
||||
parser.add_argument(
|
||||
"suite",
|
||||
nargs="?",
|
||||
choices=("all", "unit", "integration"),
|
||||
default="all",
|
||||
help="test suite to run (default: all)",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
suite_names = (
|
||||
("unit", "integration") if args.suite == "all" else (args.suite,)
|
||||
)
|
||||
loader = unittest.TestLoader()
|
||||
runner = unittest.TextTestRunner(verbosity=2)
|
||||
successful = True
|
||||
setup_logging("ERROR", logfile="test.log")
|
||||
for suite_name in suite_names:
|
||||
suite_dir = TESTS_DIR / suite_name
|
||||
if not suite_dir.is_dir():
|
||||
parser.error(f"test directory does not exist: {suite_dir}")
|
||||
|
||||
print(f"\nRunning {suite_name} tests", flush=True)
|
||||
suite = loader.discover(
|
||||
start_dir=str(suite_dir),
|
||||
top_level_dir=str(suite_dir),
|
||||
)
|
||||
successful = runner.run(suite).wasSuccessful() and successful
|
||||
|
||||
return 0 if successful else 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in new issue
Block a user