-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
424 additions
and
0 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,76 @@ | ||
--- | ||
name: Testing | ||
|
||
# yamllint disable-line rule:truthy | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
env: | ||
DEFAULT_PYTHON: "3.11" | ||
|
||
jobs: | ||
pytest: | ||
name: Python ${{ matrix.python }} | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python: ["3.11", "3.12"] | ||
steps: | ||
- name: ⤵️ Check out code from GitHub | ||
uses: actions/[email protected] | ||
- name: 🏗 Set up Poetry | ||
run: pipx install poetry | ||
- name: 🏗 Set up Python ${{ matrix.python }} | ||
id: python | ||
uses: actions/[email protected] | ||
with: | ||
python-version: ${{ matrix.python }} | ||
cache: "poetry" | ||
- name: 🏗 Install workflow dependencies | ||
run: | | ||
poetry config virtualenvs.create true | ||
poetry config virtualenvs.in-project true | ||
- name: 🏗 Install dependencies | ||
run: poetry install --no-interaction | ||
- name: 🚀 Run pytest | ||
run: poetry run pytest --cov aiotankerkoenig tests | ||
- name: ⬆️ Upload coverage artifact | ||
uses: actions/[email protected] | ||
with: | ||
name: coverage-${{ matrix.python }} | ||
path: .coverage | ||
|
||
coverage: | ||
runs-on: ubuntu-latest | ||
needs: pytest | ||
steps: | ||
- name: ⤵️ Check out code from GitHub | ||
uses: actions/[email protected] | ||
with: | ||
fetch-depth: 0 | ||
- name: ⬇️ Download coverage data | ||
uses: actions/[email protected] | ||
- name: 🏗 Set up Poetry | ||
run: pipx install poetry | ||
- name: 🏗 Set up Python ${{ env.DEFAULT_PYTHON }} | ||
id: python | ||
uses: actions/[email protected] | ||
with: | ||
python-version: ${{ env.DEFAULT_PYTHON }} | ||
cache: "poetry" | ||
- name: 🏗 Install workflow dependencies | ||
run: | | ||
poetry config virtualenvs.create true | ||
poetry config virtualenvs.in-project true | ||
- name: 🏗 Install dependencies | ||
run: poetry install --no-interaction | ||
- name: 🚀 Process coverage results | ||
run: | | ||
poetry run coverage combine coverage*/.coverage* | ||
poetry run coverage xml -i | ||
- name: 🚀 Upload coverage report | ||
uses: codecov/[email protected] |
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,8 @@ | ||
"""Helpers for the tests.""" | ||
from pathlib import Path | ||
|
||
|
||
def load_fixture(filename: str) -> str: | ||
"""Load a fixture.""" | ||
path = Path(__file__).parent / "fixtures" / filename | ||
return path.read_text() |
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,16 @@ | ||
# serializer version: 1 | ||
# name: test_nearby_stations | ||
list([ | ||
Station(id='4fd02fd5-0a4c-46b3-a9b9-a488a62454be', name='AVIA Tankstelle', house_number='115', place='Apen', post_code=26689, street='Hauptstra\\u00dfe', lat=53.22333, lng=7.812575, brand='AVIA', diesel=1.669, e10=1.689, e5=1.749, is_open=True, overrides=None, whole_day=None, state=None, opening_times=None, distance=0.9), | ||
Station(id='0f20f3c7-4ee0-4a9a-7d36-39d309a6ca94', name='Heinrich Albers OHG', house_number='455', place='Apen-Augustfehn', post_code=26689, street='Hauptstr.', lat=53.21672, lng=7.76265, brand='', diesel=1.659, e10=1.679, e5=1.739, is_open=True, overrides=None, whole_day=None, state=None, opening_times=None, distance=2.5), | ||
Station(id='5a27e942-38b4-5e83-adb8-cd396c99e0ab', name='Apen', house_number='8', place='Apen', post_code=26689, street='Dampfhammerstr.', lat=53.24424362183, lng=7.77206611633, brand='Hoyer', diesel=1.649, e10=None, e5=None, is_open=True, overrides=None, whole_day=None, state=None, opening_times=None, distance=3.3), | ||
]) | ||
# --- | ||
# name: test_prices | ||
dict({ | ||
'4fd02fd5-0a4c-46b3-a9b9-a488a62454be': PriceInfo(status=<Status.OPEN: 'open'>, e5=1.739, e10=1.679, diesel=1.669), | ||
}) | ||
# --- | ||
# name: test_station_details | ||
Station(id='abc123-0a4c-12cc-a9b9-a488a62454be', name='AVIA Tankstelle', house_number='115', place='Exampletown', post_code=26689, street='Mainstreet', lat=53.1, lng=7.8, brand='AVIA', diesel=1.669, e10=1.689, e5=1.749, is_open=True, overrides=[], whole_day=False, state=None, opening_times=None, distance=None) | ||
# --- |
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 @@ | ||
"""Fixtures for aioelectricitymaps tests.""" | ||
from typing import AsyncGenerator, Generator | ||
|
||
import aiohttp | ||
from aioresponses import aioresponses | ||
import pytest | ||
|
||
from aiotankerkoenig import Tankerkoenig | ||
|
||
|
||
@pytest.fixture(name="tankerkoenig_client") | ||
async def client() -> AsyncGenerator[Tankerkoenig, None]: | ||
"""Return a Spotify client.""" | ||
async with aiohttp.ClientSession() as session, Tankerkoenig( | ||
session=session, | ||
api_key="abc123", | ||
) as tankerkoenig_client: | ||
yield tankerkoenig_client | ||
|
||
|
||
@pytest.fixture(name="responses") | ||
def aioresponses_fixture() -> Generator[aioresponses, None, None]: | ||
"""Return aioresponses fixture.""" | ||
with aioresponses() as mocked_responses: | ||
yield mocked_responses |
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,32 @@ | ||
{ | ||
"data": "MTS-K", | ||
"license": "CC BY 4.0 - https://creativecommons.tankerkoenig.de", | ||
"ok": true, | ||
"station": { | ||
"brand": "AVIA", | ||
"diesel": 1.669, | ||
"e10": 1.689, | ||
"e5": 1.749, | ||
"houseNumber": "115", | ||
"id": "abc123-0a4c-12cc-a9b9-a488a62454be", | ||
"isOpen": true, | ||
"lat": 53.1, | ||
"lng": 7.8, | ||
"name": "AVIA Tankstelle", | ||
"openingTimes": [ | ||
{ "end": "21:00:00", "start": "06:00:00", "text": "Mo-Fr" }, | ||
{ | ||
"end": "20:00:00", | ||
"start": "08:00:00", | ||
"text": "Samstag, Sonntag, Feiertag" | ||
} | ||
], | ||
"overrides": [], | ||
"place": "Exampletown", | ||
"postCode": 26689, | ||
"state": null, | ||
"street": "Mainstreet", | ||
"wholeDay": false | ||
}, | ||
"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,56 @@ | ||
{ | ||
"ok": true, | ||
"license": "CC BY 4.0 - https://creativecommons.tankerkoenig.de", | ||
"data": "MTS-K", | ||
"status": "ok", | ||
"stations": [ | ||
{ | ||
"id": "4fd02fd5-0a4c-46b3-a9b9-a488a62454be", | ||
"name": "AVIA Tankstelle", | ||
"brand": "AVIA", | ||
"street": "Hauptstra\\u00dfe", | ||
"place": "Apen", | ||
"lat": 53.22333, | ||
"lng": 7.812575, | ||
"dist": 0.9, | ||
"diesel": 1.669, | ||
"e5": 1.749, | ||
"e10": 1.689, | ||
"isOpen": true, | ||
"houseNumber": "115", | ||
"postCode": 26689 | ||
}, | ||
{ | ||
"id": "0f20f3c7-4ee0-4a9a-7d36-39d309a6ca94", | ||
"name": "Heinrich Albers OHG", | ||
"brand": "", | ||
"street": "Hauptstr.", | ||
"place": "Apen-Augustfehn", | ||
"lat": 53.21672, | ||
"lng": 7.76265, | ||
"dist": 2.5, | ||
"diesel": 1.659, | ||
"e5": 1.739, | ||
"e10": 1.679, | ||
"isOpen": true, | ||
"houseNumber": "455", | ||
"postCode": 26689 | ||
}, | ||
{ | ||
"id": "5a27e942-38b4-5e83-adb8-cd396c99e0ab", | ||
"name": "Apen", | ||
"brand": "Hoyer", | ||
"street": "Dampfhammerstr.", | ||
"place": "Apen", | ||
"lat": 53.24424362183, | ||
"lng": 7.77206611633, | ||
"dist": 3.3, | ||
"diesel": 1.649, | ||
"e5": null, | ||
"e10": null, | ||
"isOpen": true, | ||
"houseNumber": "8", | ||
"postCode": 26689 | ||
} | ||
] | ||
} |
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 @@ | ||
{ | ||
"ok": true, | ||
"license": "CC BY 4.0 - https://creativecommons.tankerkoenig.de", | ||
"data": "MTS-K", | ||
"prices": { | ||
"4fd02fd5-0a4c-46b3-a9b9-a488a62454be": { | ||
"status": "open", | ||
"e5": 1.739, | ||
"e10": 1.679, | ||
"diesel": 1.669 | ||
} | ||
} | ||
} |
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,15 @@ | ||
# This extend our general Ruff rules specifically for tests | ||
extend = "../pyproject.toml" | ||
|
||
extend-select = [ | ||
"PT", # Use @pytest.fixture without parentheses | ||
] | ||
|
||
extend-ignore = [ | ||
"S101", # Use of assert detected. As these are tests... | ||
"S105", # Detection of passwords... | ||
"S106", # Detection of passwords... | ||
"SLF001", # Tests will access private/protected members... | ||
"TCH002", # pytest doesn't like this one... | ||
"PLR0913", # we're overwriting function that has many arguments | ||
] |
Oops, something went wrong.