Skip to content

Commit e9e43b3

Browse files
authored
Merge pull request #37 from tisnik/stub-for-unit-tests
Stub for unit tests
2 parents d7b130e + 6a5ce54 commit e9e43b3

4 files changed

Lines changed: 44 additions & 2 deletions

File tree

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1+
ARTIFACT_DIR := $(if $(ARTIFACT_DIR),$(ARTIFACT_DIR),tests/test_results)
12
PATH_TO_PLANTUML := ~/bin
23

34

45
run: ## Run the service locally
56
python src/lightspeed-stack.py
67

8+
test-unit: ## Run the unit tests
9+
@echo "Running unit tests..."
10+
@echo "Reports will be written to ${ARTIFACT_DIR}"
11+
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
12+
13+
test-integration: ## Run integration tests tests
14+
@echo "Running integration tests..."
15+
@echo "Reports will be written to ${ARTIFACT_DIR}"
16+
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
17+
718
check-types: ## Checks type hints in sources
819
MYPYPATH=src pdm run mypy --namespace-packages --explicit-package-bases --strict --disallow-untyped-calls --disallow-untyped-defs --disallow-incomplete-defs .
920

pyproject.toml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,17 @@ distribution = true
2222

2323
[dependency-groups]
2424
dev = [
25-
"black>=25.1.0"
26-
]
25+
"black>=25.1.0",
26+
"pytest>=8.3.2",
27+
"pytest-cov>=5.0.0",
28+
]
2729

2830
[tool.pdm.scripts]
2931
start = "pdm run make run"
32+
test-unit = "pdm run make test-unit"
33+
test-integration = "pdm run make test-integration"
34+
35+
[tool.pytest.ini_options]
36+
pythonpath = [
37+
"src"
38+
]

tests/unit/test_configuration.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""Unit tests for functions defined in src/configuration.py."""
2+
3+
from src.configuration import configuration
4+
5+
6+
def test_default_configuration():
7+
cfg = configuration
8+
assert cfg is not None

tests/unit/test_log.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""Unit tests for functions defined in src/log.py."""
2+
3+
from src.log import get_logger
4+
5+
6+
def test_get_logger():
7+
"""Check the function to retrieve logger."""
8+
logger_name = "foo"
9+
logger = get_logger(logger_name)
10+
assert logger is not None
11+
assert logger.name == logger_name
12+
13+
# at least one handler need to be set
14+
assert len(logger.handlers) >= 1

0 commit comments

Comments
 (0)