Skip to content

Commit

Permalink
Add some integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Jun 2, 2020
1 parent 58f1a26 commit 40537f8
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ setup-virtualenv:
release: bumpversion push sdist pypi-upload


# ----
# Test
# ----
test: install-tests
$(pytest)


# ===============
# Utility targets
# ===============
Expand All @@ -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.
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pytest
pytest==5.4.3
black
85 changes: 84 additions & 1 deletion tests/test_dwdweather.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest

from datetime import datetime
from dwdweather.core import DwdWeather


Expand All @@ -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

0 comments on commit 40537f8

Please sign in to comment.