Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gutzbenj committed Jun 4, 2021
1 parent f174bc3 commit 5a4b182
Show file tree
Hide file tree
Showing 21 changed files with 261 additions and 180 deletions.
26 changes: 0 additions & 26 deletions THIRD_PARTY_NOTICES
Original file line number Diff line number Diff line change
Expand Up @@ -5907,32 +5907,6 @@ Copyright (C) 2008-2011 INADA Naoki <songofacandy@gmail.com>



munch
2.5.0
MIT License
Rotem Yaari
https://github.com/Infinidat/munch
Copyright (c) 2010 David Schoonover

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


mypy-extensions
0.4.3
MIT License
Expand Down
1 change: 1 addition & 0 deletions docs/usage/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Command Line Interface
--language=<language> Output language. [Default: en]
--version Show version information
--tidy Tidy DataFrame
--humanize Humanize parameters
--si-units Convert to SI units
--pretty Pretty json with indent 4
--debug Enable debug messages
Expand Down
21 changes: 1 addition & 20 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ pandas = "^1.2"
numpy = "^1.19.5"
scipy = "^1.5.2"
cachetools = "^4.1.1"
munch = "^2.5.0"
dateparser = "^1.0.0"
beautifulsoup4 = "^4.9.1"
requests = "^2.24.0"
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ measurement==3.2.0
mistune==0.8.4; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.6"
mock==4.0.3; python_version >= "3.6"
mpmath==1.2.1; python_version >= "3.6"
munch==2.5.0
mypy-extensions==0.4.3; python_version >= "3.6"
nbconvert==5.6.1; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.6"
nbdime==3.1.0; python_version >= "3.6"
Expand Down
4 changes: 2 additions & 2 deletions tests/provider/dwd/observation/test_api_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def test_dwd_observation_data_parameter():

assert request.parameter == [
(
DwdObservationDatasetTree.DAILY.PRECIPITATION_MORE.PRECIPITATION_HEIGHT, # Noqa: E501, B950
DwdObservationDataset.PRECIPITATION_MORE,
DwdObservationDatasetTree.DAILY.CLIMATE_SUMMARY.PRECIPITATION_HEIGHT, # Noqa: E501, B950
DwdObservationDataset.CLIMATE_SUMMARY,
)
]

Expand Down
8 changes: 4 additions & 4 deletions tests/provider/dwd/observation/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
DwdObservationDataset.CLIMATE_SUMMARY,
),
(
DwdObservationDatasetTree.DAILY.PRECIPITATION_MORE.PRECIPITATION_HEIGHT,
DwdObservationDataset.PRECIPITATION_MORE,
DwdObservationDatasetTree.DAILY.CLIMATE_SUMMARY.PRECIPITATION_HEIGHT,
DwdObservationDataset.CLIMATE_SUMMARY,
),
(
DwdObservationDatasetTree.DAILY.PRECIPITATION_MORE.PRECIPITATION_FORM,
DwdObservationDataset.PRECIPITATION_MORE,
DwdObservationDatasetTree.DAILY.CLIMATE_SUMMARY.PRECIPITATION_FORM,
DwdObservationDataset.CLIMATE_SUMMARY,
),
]

Expand Down
47 changes: 39 additions & 8 deletions tests/ui/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,7 @@ def invoke_wetterdienst_stations_geo(provider, kind, setting, fmt="json"):

def invoke_wetterdienst_values_static(provider, kind, setting, station, fmt="json"):
runner = CliRunner()
print(
f"values --provider={provider} --kind={kind} "
f"{setting} --station={station} --format={fmt}"
)

result = runner.invoke(
cli,
f"values --provider={provider} --kind={kind} "
Expand Down Expand Up @@ -207,6 +204,40 @@ def invoke_wetterdienst_values_geo(provider, kind, setting, fmt="json"):
return result


def test_no_provider():
runner = CliRunner()

result = runner.invoke(cli, "stations --provider=abc --kind=abc")

assert (
"Error: Invalid value for '--provider': invalid choice: abc." in result.output
)


def test_no_kind():
runner = CliRunner()

result = runner.invoke(cli, "stations --provider=dwd --kind=abc")

assert "Invalid value for '--kind': invalid choice: abc." in result.output


def test_data_range(capsys):
runner = CliRunner()

result = runner.invoke(
cli,
"values --provider=eccc --kind=observation --parameter=precipitation_height "
"--resolution=daily --name=toronto",
)

assert isinstance(result.exception, TypeError)
assert (
"Combination of provider ECCC and kind OBSERVATION requires start and end date"
in str(result.exception)
)


@pytest.mark.parametrize(
"provider,kind,setting,station_id,station_name",
SETTINGS_STATIONS,
Expand Down Expand Up @@ -277,8 +308,8 @@ def test_cli_stations_excel(
provider, kind, setting, station_id, station_name, tmpdir_factory
):

filename = tmpdir_factory.mktemp("data").join("stations.xlsx")
# filename = "stations.xlsx"
# filename = tmpdir_factory.mktemp("data").join("stations.xlsx")
filename = "stations.xlsx"

_ = invoke_wetterdienst_stations_export(
provider=provider,
Expand Down Expand Up @@ -384,8 +415,8 @@ def test_cli_values_excel(
provider, kind, setting, station_id, station_name, tmpdir_factory
):

filename = tmpdir_factory.mktemp("data").join("values.xlsx")
# filename = "values.xlsx"
# filename = tmpdir_factory.mktemp("data").join("values.xlsx")
filename = "values.xlsx"

_ = invoke_wetterdienst_values_export(
provider=provider,
Expand Down
81 changes: 58 additions & 23 deletions tests/ui/test_restapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,57 @@ def test_robots():
assert response.status_code == 200


def test_no_provider():
response = client.get(
"/restapi/stations",
params={
"provider": "abc",
"kind": "abc",
"parameter": "kl",
"resolution": "daily",
"period": "recent",
"all": "true",
},
)

assert "Choose provider and kind from /restapi/coverage" in response.text


def test_no_kind():
response = client.get(
"/restapi/stations",
params={
"provider": "dwd",
"kind": "abc",
"parameter": "kl",
"resolution": "daily",
"period": "recent",
"all": "true",
},
)

assert "Choose provider and kind from /restapi/coverage" in response.text


def test_data_range(capsys):
response = client.get(
"/restapi/values",
params={
"provider": "eccc",
"kind": "observation",
"parameter": "precipitation_height",
"resolution": "daily",
"period": "historical",
"name": "toronto",
},
)

assert (
"Combination of provider ECCC and kind OBSERVATION requires start and end date"
in response.text
)


def test_dwd_stations_basic():

response = client.get(
Expand Down Expand Up @@ -120,10 +171,13 @@ def test_dwd_values_no_station():
},
)

assert response.status_code == 400
assert response.json() == {
"detail": "Query arguments 'parameter', 'resolution' and 'date' are required"
}
assert response.status_code == 200
assert (
"'Give one of the parameters: all (boolean), station (string), "
"name (string), coordinates (float,float) and rank (integer), "
"coordinates (float,float) and distance (float), "
"bbox (left float, bottom float, right float, top float)'" in response.text
)


def test_dwd_values_no_parameter():
Expand Down Expand Up @@ -164,25 +218,6 @@ def test_dwd_values_no_resolution():
}


def test_dwd_values_no_period():

response = client.get(
"/restapi/values",
params={
"provider": "dwd",
"kind": "observation",
"stations": "01048,4411",
"parameter": "kl",
"resolution": "daily",
},
)

assert response.status_code == 400
assert response.json() == {
"detail": "Query arguments 'parameter', 'resolution' and 'date' are required"
}


@pytest.mark.sql
def test_dwd_values_sql_tabular(dicts_are_same):

Expand Down
14 changes: 8 additions & 6 deletions wetterdienst/core/scalar/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from wetterdienst.core.scalar.result import StationsResult
from wetterdienst.exceptions import InvalidEnumeration, StartDateEndDateError
from wetterdienst.metadata.columns import Columns
from wetterdienst.metadata.datarange import DataRange
from wetterdienst.metadata.kind import Kind
from wetterdienst.metadata.period import Period, PeriodType
from wetterdienst.metadata.provider import Provider
Expand Down Expand Up @@ -58,12 +59,6 @@ def _resolution_type(self) -> ResolutionType:
""" Resolution type, multi, fixed, ..."""
pass

# TODO: implement for source with dynamic resolution
@staticmethod
def _determine_resolution(dates: pd.Series) -> Resolution:
""" Function to determine resolution from a pandas Series of dates """
pass

@property
def frequency(self) -> Frequency:
"""Frequency for the given resolution, used to create a full date range for
Expand All @@ -89,6 +84,13 @@ def _parameter_base(self) -> Enum:
DWDObservationParameter"""
pass

@property
@abstractmethod
def _data_range(self) -> DataRange:
"""State whether data from this provider is given in fixed data chunks
or has to be defined over start and end date"""
pass

@property
@abstractmethod
def _has_datasets(self) -> bool:
Expand Down
1 change: 0 additions & 1 deletion wetterdienst/core/scalar/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def __init__(
) -> None:
# TODO: add more attributes from ScalarStations class
self.stations = stations

self.df = df
self._kwargs = kwargs

Expand Down
Loading

0 comments on commit 5a4b182

Please sign in to comment.