Skip to content

Commit

Permalink
Simplify strang unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mgcth committed Apr 1, 2024
1 parent e8a72be commit 7193fe4
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 257 deletions.
4 changes: 2 additions & 2 deletions src/smhi/strang.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def get_point(
strange point model
Raises:
TypeError: wrong type of latitude and/or longitude
ValueError: wrong value of latitude and/or longitude
NotImplementedError: parameter not supported
"""
strang_parameter = self._available_parameters[parameter]
Expand All @@ -103,7 +103,7 @@ def get_point(
)

if longitude is None or latitude is None:
raise TypeError("Wrong type of latitude and/or longitude provided.")
raise ValueError("Wrong value of latitude and/or longitude provided.")

time_from = self._parse_datetime(time_from, strang_parameter)
time_to = self._parse_datetime(time_to, strang_parameter)
Expand Down
File renamed without changes.
16 changes: 16 additions & 0 deletions tests/fixtures/strang/multipoint.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Accept-Ranges: bytes
Access-Control-Allow-Origin: *
Age: 0
Connection: keep-alive
Content-Encoding: gzip
Last-Modified: Mon, 01 Apr 2024 06:33:28 GMT
Transfer-Encoding: chunked
Vary: Accept-Encoding
Via: 1.1 varnish (Varnish/6.6)
X-Varnish: 688983281
X-hits: 0
content-type: application/json
date: Mon, 01 Apr 2024 06:33:24 GMT
x-request-id: 4da0931b-275b-40d9-8825-fcf125593427

[{"lat":71.139084,"lon":-9.659227,"value":51183.4},{"lat":71.1481,"lon":-9.589094,"value":50022.0}]
3 changes: 3 additions & 0 deletions tests/fixtures/strang/multipoint_data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
,lat,lon,value
0,71.139084,-9.659227,51183.4
1,71.1481,-9.589094,50022.0
16 changes: 16 additions & 0 deletions tests/fixtures/strang/point.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Accept-Ranges: bytes
Access-Control-Allow-Origin: *
Age: 0
Connection: keep-alive
Content-Encoding: gzip
Content-Length: 174
Last-Modified: Mon, 01 Apr 2024 06:33:05 GMT
Vary: Accept-Encoding
Via: 1.1 varnish (Varnish/6.6)
X-Varnish: 683722598
X-hits: 0
content-type: application/json
date: Mon, 01 Apr 2024 06:33:05 GMT
x-request-id: 77143621-33fa-43e2-a548-1556ad2984e0

[{"date_time":"2020-02-01T00:00:00Z","value":0.0},{"date_time":"2020-02-01T01:00:00Z","value":0.0}]
3 changes: 3 additions & 0 deletions tests/fixtures/strang/point_data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
date_time,value
2020-02-01 00:00:00+00:00,0.0
2020-02-01 01:00:00+00:00,0.0
8 changes: 4 additions & 4 deletions tests/integration/test_integration_strang.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def get_point(file=None):
@pytest.fixture
def get_multipoint():
df = pd.read_csv(
"tests/fixtures/strang/STRANG_RESULT_MULTIPOINT_2020_01_01_MONTHLY_10.csv",
"tests/fixtures/strang/strang_result_multipoint_2020_01_01_monthly_10.csv",
index_col=0,
)

Expand All @@ -35,7 +35,7 @@ class TestIntegrationStrang:
"2020-01-02",
"hourly",
get_point(
"tests/fixtures/strang/STRANG_RESULT_HOURLY_2020_01_01_2020_01_02.csv"
"tests/fixtures/strang/strang_result_hourly_2020_01_01_2020_01_02.csv"
),
),
(
Expand All @@ -46,7 +46,7 @@ class TestIntegrationStrang:
"2020-01-02",
"daily",
get_point(
"tests/fixtures/strang/STRANG_RESULT_DAILY_2020_01_01_2020_01_02.csv"
"tests/fixtures/strang/strang_result_daily_2020_01_01_2020_01_02.csv"
),
),
(
Expand All @@ -57,7 +57,7 @@ class TestIntegrationStrang:
"2020-02-01",
"monthly",
get_point(
"tests/fixtures/strang/STRANG_RESULT_MONTHLY_2020_01_01_2020_02_01.csv"
"tests/fixtures/strang/strang_result_monthly_2020_01_01_2020_02_01.csv"
),
),
(58, 16, 118, None, None, None, get_point()),
Expand Down
16 changes: 0 additions & 16 deletions tests/unit/test_unit_mesan.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import arrow
import pandas as pd
import pytest
from pydantic import BaseModel, ConfigDict
from smhi.constants import MESAN_LEVELS_UNIT, MESAN_PARAMETER_DESCRIPTIONS
from smhi.mesan import Mesan
from smhi.models.mesan_model import MesanGeometry, MesanParameterItem, MesanParameters
Expand Down Expand Up @@ -40,21 +39,6 @@
)


class MockMesanPointData(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True)

approved_time: str
reference_time: str
level_unit: str


class MockMesanMultiPointData(BaseModel):
parameter: str
approved_time: str
reference_time: str
valid_time: str


@pytest.fixture
def setup_point():
"""Read in Point response."""
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_unit_metobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def setup_data(setup_periods):
mocked_response = get_response("tests/fixtures/metobs/data.txt", encode=True)
mocked_model = MetobsData.model_validate_json(mocked_response.content)
mocked_csv_data = MockResponse(
200, None, get_data("tests/fixtures/metobs/data_csv.csv", "data")
200, None, get_data("tests/fixtures/metobs/data.csv", "data")
)

mocked_station = pd.read_csv("tests/fixtures/metobs/data_station.csv", index_col=0)
Expand Down
Loading

0 comments on commit 7193fe4

Please sign in to comment.