From 40537f88d8311f4f0e9c0e8560d00721a46f6afb Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Tue, 2 Jun 2020 23:49:42 +0200 Subject: [PATCH] Add some integration tests --- CHANGES.rst | 1 + Makefile | 11 ++++++ pytest.ini | 2 +- requirements-dev.txt | 2 +- tests/test_dwdweather.py | 85 +++++++++++++++++++++++++++++++++++++++- 5 files changed, 98 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index a510f2d..12417d4 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -8,6 +8,7 @@ in progress This also drops support for Python 2. - Naming things - Update knowledgebase, adjust some field names +- Add some integration tests 2020-05-30 0.12.1 diff --git a/Makefile b/Makefile index b448ad7..cc9ddd0 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,13 @@ setup-virtualenv: release: bumpversion push sdist pypi-upload +# ---- +# Test +# ---- +test: install-tests + $(pytest) + + # =============== # Utility targets # =============== @@ -50,3 +57,7 @@ install-doctools: setup-virtualenv install-releasetools: setup-virtualenv @$(pip) install --quiet --requirement requirements-release.txt --upgrade + +install-tests: setup-virtualenv + @$(pip) install --quiet --requirement requirements-dev.txt --upgrade + @$(pip) install --quiet -e. diff --git a/pytest.ini b/pytest.ini index e1da724..a688679 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,5 +1,5 @@ [pytest] -addopts = --verbose --log-cli-level=DEBUG +addopts = --verbose --verbose --log-cli-level=DEBUG # https://docs.pytest.org/en/latest/warnings.html filterwarnings = diff --git a/requirements-dev.txt b/requirements-dev.txt index 9bb2a15..3af8861 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,2 +1,2 @@ -pytest +pytest==5.4.3 black diff --git a/tests/test_dwdweather.py b/tests/test_dwdweather.py index 321f814..88bfee7 100644 --- a/tests/test_dwdweather.py +++ b/tests/test_dwdweather.py @@ -1,5 +1,5 @@ import pytest - +from datetime import datetime from dwdweather.core import DwdWeather @@ -16,3 +16,86 @@ def test_dwdclass_init(resolution): Test class can be initialized with plausible resolutions. """ dw = DwdWeather(resolution=resolution) + + +def test_hourly_recent_base(): + # hourly, 2020-06-01T08, Aachen + dw = DwdWeather(resolution='hourly') + result = dw.query(44, datetime(2020, 6, 1, 8)) + assert result['datetime'] == 2020060108 + assert result['station_id'] == 44 + assert result['air_temperature_200'] == 15.3 + assert result['relative_humidity_200'] == 54.0 + assert result['soil_temperature_002'] is None + assert result['soil_temperature_005'] == 21.0 + assert result['soil_temperature_010'] == 17.7 + assert result['soil_temperature_020'] == 16.5 + assert result['soil_temperature_050'] == 16.3 + assert result['soil_temperature_100'] == 13.3 + assert result['sun_duration'] == 60.0 + assert result['precipitation_height'] == 0 + assert result['precipitation_fallen'] == 0 + assert result['precipitation_form'] is None + + +def test_hourly_recent_more(): + # hourly, 2020-06-01T08 + dw = DwdWeather(resolution='hourly') + result = dw.query(96, datetime(2020, 6, 1, 8)) + assert result['datetime'] == 2020060108 + assert result['station_id'] == 96 + assert result['air_temperature_200'] == 18.4 + assert result['relative_humidity_200'] == 49.0 + assert result['soil_temperature_002'] is None + assert result['soil_temperature_005'] == 19.3 + assert result['soil_temperature_010'] == 16.7 + assert result['soil_temperature_020'] == 16.1 + assert result['soil_temperature_050'] == 16.6 + assert result['soil_temperature_100'] == 14.8 + assert result['pressure_normalized'] == 1025.0 + assert result['pressure_station'] == 1018.9 + assert result['visibility_source'] == "P" + assert result['visibility_value'] == 39870 + assert result['wind_direction'] == 50 + assert result['wind_speed'] == 2.2 + assert result['cloudiness_source'] == "P" + assert result['cloudiness_total_cover'] == 0 + + +def test_hourly_recent_solar(): + # hourly, 2020-05-19T08, Zugspitze + dw = DwdWeather(resolution='hourly') + result = dw.query(5792, datetime(2020, 5, 19, 8)) + assert result['datetime'] == 2020051908 + assert result['station_id'] == 5792 + assert result['solar_dhi'] is None + assert result['solar_ghi'] == 256.0 + assert result['solar_atmosphere'] == 83.0 + assert result['solar_sunshine'] == 60 + assert result['solar_zenith'] == 50.37 + + +def test_10_minutes_recent_base(): + # 10 minutes, 2020-06-01T08:00, Aachen + dw = DwdWeather(resolution='10_minutes') + result = dw.query(44, datetime(2020, 6, 1, 8, 0)) + assert result['datetime'] == 202006010800 + assert result['station_id'] == 44 + assert result['air_temperature_005'] == 21.2 + assert result['air_temperature_200'] == 16.0 + assert result['relative_humidity_200'] == 52.3 + assert result['dewpoint_temperature_200'] == 6.2 + assert result['solar_sunshine'] == 0.167 + + +def test_10_minutes_recent_more(): + # 10 minutes, 2020-06-01T08:00, Zugspitze + dw = DwdWeather(resolution='10_minutes') + result = dw.query(5792, datetime(2020, 6, 1, 8, 0)) + assert result['datetime'] == 202006010800 + assert result['station_id'] == 5792 + assert result['pressure_station'] == 713.3 + assert result['solar_dhi'] == 46.2 + assert result['solar_ghi'] == 46.8 + assert result['solar_atmosphere'] == 13.4 + assert result['solar_sunshine'] == 0.167