diff --git a/Makefile b/Makefile index 073b5888..c720aeab 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,20 @@ +ARTIFACT_DIR := $(if $(ARTIFACT_DIR),$(ARTIFACT_DIR),tests/test_results) PATH_TO_PLANTUML := ~/bin run: ## Run the service locally python src/lightspeed-stack.py +test-unit: ## Run the unit tests + @echo "Running unit tests..." + @echo "Reports will be written to ${ARTIFACT_DIR}" + COVERAGE_FILE="${ARTIFACT_DIR}/.coverage.unit" pdm run pytest tests/unit --cov=src --cov-report term-missing --cov-report "json:${ARTIFACT_DIR}/coverage_unit.json" --junit-xml="${ARTIFACT_DIR}/junit_unit.xml" --cov-fail-under=60 + +test-integration: ## Run integration tests tests + @echo "Running integration tests..." + @echo "Reports will be written to ${ARTIFACT_DIR}" + COVERAGE_FILE="${ARTIFACT_DIR}/.coverage.integration" pdm run pytest tests/integration --cov=src --cov-report term-missing --cov-report "json:${ARTIFACT_DIR}/coverage_integration.json" --junit-xml="${ARTIFACT_DIR}/junit_integration.xml" --cov-fail-under=60 + check-types: ## Checks type hints in sources MYPYPATH=src pdm run mypy --namespace-packages --explicit-package-bases --strict --disallow-untyped-calls --disallow-untyped-defs --disallow-incomplete-defs . diff --git a/pyproject.toml b/pyproject.toml index 1f503300..080c531d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,8 +22,17 @@ distribution = true [dependency-groups] dev = [ - "black>=25.1.0" - ] + "black>=25.1.0", + "pytest>=8.3.2", + "pytest-cov>=5.0.0", +] [tool.pdm.scripts] start = "pdm run make run" +test-unit = "pdm run make test-unit" +test-integration = "pdm run make test-integration" + +[tool.pytest.ini_options] +pythonpath = [ + "src" +] diff --git a/tests/unit/test_configuration.py b/tests/unit/test_configuration.py new file mode 100644 index 00000000..9b80a9e5 --- /dev/null +++ b/tests/unit/test_configuration.py @@ -0,0 +1,8 @@ +"""Unit tests for functions defined in src/configuration.py.""" + +from src.configuration import configuration + + +def test_default_configuration(): + cfg = configuration + assert cfg is not None diff --git a/tests/unit/test_log.py b/tests/unit/test_log.py new file mode 100644 index 00000000..c0b84966 --- /dev/null +++ b/tests/unit/test_log.py @@ -0,0 +1,14 @@ +"""Unit tests for functions defined in src/log.py.""" + +from src.log import get_logger + + +def test_get_logger(): + """Check the function to retrieve logger.""" + logger_name = "foo" + logger = get_logger(logger_name) + assert logger is not None + assert logger.name == logger_name + + # at least one handler need to be set + assert len(logger.handlers) >= 1