Skip to content

Commit dc543cf

Browse files
committed
fix(test): Correct forecast/all horizon test
1 parent ce346a9 commit dc543cf

5 files changed

Lines changed: 86 additions & 31 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ dev = [
5656
"types-grpcio>=1.0.0.20251009",
5757
"sqlalchemy-stubs>=0.4",
5858
"psycopg2-binary>=2.9.11",
59-
"freezegun>=1.5.5",
6059
"ty>=0.0.25",
6160
"pyinstrument>=5.1.2",
61+
"time-machine[dateutil]>=3.2.0",
6262
]
6363

6464
[tool.uv.sources]
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import datetime as dt
22

3-
from freezegun import freeze_time
3+
import time_machine
44

55
from quartz_api.internal.backends.utils import get_window
66

77

8+
@time_machine.travel(dt.datetime(2023, 1, 1), tick=False)
89
def test_get_window_defaults() -> None:
9-
with freeze_time("2023-01-01"):
10-
start, end = get_window()
11-
assert start == dt.datetime(2022, 12, 30, tzinfo=dt.UTC)
12-
assert end == dt.datetime(2023, 1, 3, tzinfo=dt.UTC)
10+
start, end = get_window()
11+
assert start == dt.datetime(2022, 12, 30, tzinfo=dt.UTC)
12+
assert end == dt.datetime(2023, 1, 3, tzinfo=dt.UTC)

src/quartz_api/tests/integration/conftest.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,10 @@ async def gsp_locations(dp_client: service_pb2_grpc.DataPlatformDataServiceStub)
123123
"""Make national location."""
124124
# add location gsp 1 to 10
125125
location_uuids = []
126+
gsp_id_map.clear()
126127
for i in range(1, 11):
127-
metadata = Struct(fields={"gsp_id": Value(number_value=i)})
128+
metadata = Struct()
129+
metadata.update({"gsp_id": i})
128130
create_location_request = make_location(
129131
name=f"gsp_{i}",
130132
gsp_id=i,
@@ -134,7 +136,6 @@ async def gsp_locations(dp_client: service_pb2_grpc.DataPlatformDataServiceStub)
134136
res = await dp_client.CreateLocation(create_location_request)
135137
location_uuids.append(res.location_uuid)
136138

137-
gsp_id_map.clear()
138139
gsp_id_map[i] = models.Location(
139140
uuid=UUID(res.location_uuid),
140141
metadata={"gsp_id": i},
@@ -153,7 +154,8 @@ async def national_location(
153154
) -> messages_pb2.CreateLocationResponse:
154155
"""Make national location."""
155156
# add location gsp 0
156-
metadata = Struct(fields={"gsp_id": Value(number_value=0)})
157+
metadata = Struct()
158+
metadata.update({"gsp_id": 0})
157159
create_location_request = make_location(name="uk", gsp_id=0, metadata=metadata)
158160
create_location_response = await dp_client.CreateLocation(create_location_request)
159161

src/quartz_api/tests/integration/uk_national/test_app.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import datetime as dt
2+
13
import pandas as pd
24
import pytest
35
from fastapi_cache import FastAPICache
4-
6+
import time_machine
57

68
# 1. Does the app start up, and can we use health
79
@pytest.mark.asyncio(loop_scope="session")
@@ -41,14 +43,20 @@ async def test_national_forecast_horizon_minutes(
4143
4244
We are testing for forecast_horizon of 120 minutes
4345
"""
46+
# make_national_forecast_values makes forecasts from now floored to 30 minutes
47+
# in half hour intervals back to -7 hours ago. Each forecast is 4.5 hours of 30-minute
48+
# seperated values. This is a total of 24 unique timestamps. With a horizon of 120,
49+
# we should lose four of these.
50+
future_time = dt.datetime.now(tz=dt.UTC) + dt.timedelta(minutes=120, milliseconds=-1)
51+
with time_machine.travel(future_time, tick=False):
52+
response = await api_client_uk_national.get(
53+
"/v0/solar/GB/national/forecast?forecast_horizon_minutes=120"
54+
)
4455

45-
response = await api_client_uk_national.get(
46-
"/v0/solar/GB/national/forecast?forecast_horizon_minutes=120",
47-
)
4856
assert response.status_code == 200
4957
data = response.json()
5058
assert isinstance(data, list)
51-
assert len(data) == 16
59+
assert len(data) == 20
5260

5361

5462
# 2.2 Test the National Forecast, include metadata
@@ -350,8 +358,8 @@ async def test_gsp_forecast_all_for_one_timestamp_compact(
350358
async def test_gsp_pvlive_all(
351359
api_client_uk_national,
352360
gsp_locations, # noqa arg001
353-
make_forecasters, # noqa arg001
354-
make_gsp_forecast_values, # noqa arg001
361+
make_observers, # noqa arg001
362+
make_gsp_observation_values, # noqa arg001
355363
) -> None:
356364
"""Test a sample endpoint for UK National forecast data."""
357365

uv.lock

Lines changed: 60 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)