-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(coverage): add test infrastructure and coverage config
- Add test infrastructure with pytest configuration and fixtures - Configure code coverage settings in .coveragerc - Move StrEnum from typing.py to models.py - Add Makefile with common development tasks
- Loading branch information
Showing
11 changed files
with
179 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[run] | ||
branch = True | ||
omit = | ||
kassalappy/cli.py | ||
|
||
[report] | ||
exclude_lines = | ||
pragma: no cover | ||
def __repr__ | ||
def __str__ | ||
def __rich_console__ | ||
if __name__ == .__main__.: | ||
if TYPE_CHECKING |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
run := poetry run | ||
|
||
.PHONY: test | ||
test: | ||
$(run) pytest tests/ $(ARGS) | ||
|
||
.PHONY: test-coverage | ||
test-coverage: | ||
$(run) pytest tests/ --cov-report term-missing --cov=kassalappy $(ARGS) | ||
|
||
.PHONY: coverage | ||
coverage: | ||
$(run) coverage html | ||
|
||
.PHONY: format | ||
format: | ||
$(run) ruff format kassalappy | ||
|
||
.PHONY: format-check | ||
format-check: | ||
$(run) ruff --check kassalappy | ||
|
||
.PHONY: setup | ||
setup: | ||
poetry install | ||
|
||
.PHONY: update | ||
update: | ||
poetry update | ||
|
||
.PHONY: repl | ||
repl: | ||
$(run) python | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"""kassalappy tests.""" | ||
|
||
import pytest | ||
|
||
pytestmark = pytest.mark.asyncio(loop_scope="package") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
from typing import Callable | ||
|
||
from aiohttp import ClientSession | ||
|
||
import pytest | ||
|
||
from kassalappy import Kassalapp | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
@pytest.fixture | ||
async def kassalapp_client(default_access_token) -> Callable[..., Kassalapp]: | ||
"""Return Politikontroller Client.""" | ||
|
||
def _kassalapp_client( | ||
access_token: str | None = None, | ||
session: ClientSession | None = None, | ||
) -> Kassalapp: | ||
token = access_token if access_token is not None else default_access_token | ||
return Kassalapp(access_token=token, websession=session) | ||
|
||
return _kassalapp_client | ||
|
||
|
||
@pytest.fixture | ||
def default_access_token(): | ||
return "baba" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"data":{"status":"ok"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
|
||
import orjson | ||
|
||
FIXTURE_DIR = Path(__file__).parent / "fixtures" | ||
|
||
|
||
def load_fixture(name: str) -> str: | ||
"""Load a fixture.""" | ||
path = FIXTURE_DIR / f"{name}.json" | ||
if not path.exists(): # pragma: no cover | ||
raise FileNotFoundError(f"Fixture {name} not found") | ||
return path.read_text(encoding="utf-8") | ||
|
||
|
||
def load_fixture_json(name: str) -> dict | list: | ||
"""Load a fixture as JSON.""" | ||
data = load_fixture(name) | ||
return orjson.loads(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# This extends our general Ruff rules specifically for tests | ||
extend = "../pyproject.toml" | ||
|
||
lint.extend-select = [ | ||
"PT", # Use @pytest.fixture without parentheses | ||
] | ||
|
||
lint.extend-ignore = [ | ||
"S101", | ||
"S106", | ||
"S108", | ||
"SLF001", | ||
"TCH002", | ||
"PLR2004", | ||
] | ||
|
||
lint.pylint.max-branches = 13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""Tests for NrkPodcastAPI.""" | ||
|
||
from __future__ import annotations | ||
|
||
import logging | ||
|
||
from aiohttp import ClientSession | ||
from aiohttp.web_response import json_response | ||
from aresponses import Response, ResponsesMockServer | ||
|
||
from kassalappy.models import StatusResponse | ||
from .helpers import load_fixture_json | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
async def test_health(aresponses: ResponsesMockServer, kassalapp_client): | ||
aresponses.add( | ||
response=json_response(load_fixture_json("health")), | ||
) | ||
async with ClientSession() as session: | ||
client = kassalapp_client(session=session) | ||
result = await client.healthy() | ||
assert isinstance(result, StatusResponse) | ||
assert result.status == "ok" |