From e891d00ef92376d23dc1e7f104b17512bea449e6 Mon Sep 17 00:00:00 2001 From: Lucas Vivo Date: Fri, 13 Nov 2026 10:58:38 +0100 Subject: [PATCH] feat(wallpaper_changer): run unit and integration tests, integration test dir --- .../tests/integration/__init__.py | 1 + wallpaper_changer/tests/run_tests.py | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 wallpaper_changer/tests/integration/__init__.py create mode 100644 wallpaper_changer/tests/run_tests.py diff --git a/wallpaper_changer/tests/integration/__init__.py b/wallpaper_changer/tests/integration/__init__.py new file mode 100644 index 0000000..4cd8d48 --- /dev/null +++ b/wallpaper_changer/tests/integration/__init__.py @@ -0,0 +1 @@ +"""Integration tests for wallpaper changer.""" diff --git a/wallpaper_changer/tests/run_tests.py b/wallpaper_changer/tests/run_tests.py new file mode 100644 index 0000000..5cd2c01 --- /dev/null +++ b/wallpaper_changer/tests/run_tests.py @@ -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())