forked from earthobservations/wetterdienst
-
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.
Finish implementation of new methods plus testing
- Loading branch information
Showing
6 changed files
with
200 additions
and
81 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
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 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 |
---|---|---|
@@ -1,52 +1,23 @@ | ||
from io import StringIO | ||
from shutil import rmtree | ||
""" Tests for parse_dwd_data function """ | ||
from typing import Union | ||
from io import StringIO, BytesIO | ||
from pathlib import Path | ||
import pandas as pd | ||
|
||
from python_dwd import parse_dwd_data | ||
from python_dwd.parsing_data.parse_data_from_files import parse_dwd_data | ||
|
||
fixtures_dir = Path(__file__, "../..").resolve().absolute() / "fixtures" | ||
|
||
|
||
def test_parse_dwd_data(): | ||
filename = "tageswerte_KL_00001_19370101_19860630_hist.zip" | ||
|
||
file = pd.read_json(fixtures_dir / "FIXED_STATIONDATA.JSON") | ||
file_in_bytes = StringIO() | ||
file.to_csv(file_in_bytes, sep=";") | ||
station_data_original = pd.read_json(fixtures_dir / "FIXED_STATIONDATA.JSON") | ||
file_in_bytes: Union[StringIO, BytesIO] = StringIO() | ||
station_data_original.to_csv(file_in_bytes, sep=";") | ||
file_in_bytes.seek(0) | ||
|
||
station_data = parse_dwd_data( | ||
filenames_and_files=[(filename, file_in_bytes)]) | ||
|
||
stationdata_local = parse_dwd_data( | ||
filenames_and_files=[(filename, file_in_bytes)], | ||
prefer_local=True, | ||
folder=Path(__file__).parent.absolute() / "dwd_data" | ||
) | ||
|
||
# 1. Compare freshly loaded data with data read from hdf and assure it's identical | ||
assert stationdata_online.equals(stationdata_local) | ||
|
||
# 2. Check functioning for filename only, that is used for parameter definition to parse data from local hdf file | ||
assert stationdata_online.equals( | ||
parse_dwd_data( | ||
filenames_and_files=[filename], | ||
prefer_local=True, | ||
folder=Path(__file__).parent.absolute() / "dwd_data", | ||
write_file=False | ||
) | ||
) | ||
|
||
# 3. Check for only giving filename but no valid filepath | ||
assert parse_dwd_data( | ||
filenames_and_files=[filename], | ||
prefer_local=True, | ||
folder="wrong/folder/name", | ||
write_file=False | ||
).empty | ||
|
||
rmtree(Path(Path(__file__).parent.absolute() / "dwd_data")) | ||
|
||
# To ensure files are deleted with the above execution | ||
assert True | ||
station_data.equals(station_data_original) |
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
Oops, something went wrong.