Skip to content

Commit 355c0ca

Browse files
committed
update tests
1 parent f23c66d commit 355c0ca

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

src/india_api/internal/inputs/indiadb/conftest.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
from datetime import datetime, timedelta
55

6+
import pandas as pd
67
import pytest
78
from pvsite_datamodel.sqlmodels import Base, ForecastSQL, ForecastValueSQL, GenerationSQL, SiteSQL
89
from pvsite_datamodel.read.user import get_user_by_email
@@ -144,17 +145,12 @@ def make_fake_forecast_values(db_session, sites, model_name):
144145
forecast_values = []
145146
forecast_version: str = "0.0.0"
146147

147-
num_forecasts = 10
148-
num_values_per_forecast = 11
148+
num_forecasts = 12 # 2 hours in 10 minute blocks
149+
num_values_per_forecast = 11 # 2.5 hours in 15 minute blocks, including init time
150+
# Total forecast range should be 4.5 hours, which is 18 values
149151

150-
now = datetime.utcnow()
151-
rounded_now_30_mins = now.replace(microsecond=0,second=0)
152-
if now.minute >= 30:
153-
rounded_now_30_mins = rounded_now_30_mins.replace(minute=30)
154-
else:
155-
rounded_now_30_mins = rounded_now_30_mins.replace(minute=0)
156-
157-
timestamps = [rounded_now_30_mins - timedelta(minutes=15 * i) for i in range(num_forecasts)]
152+
init_time = datetime.utcnow() - timedelta(hours=2)
153+
timestamps = [init_time + timedelta(minutes=10 * i) for i in range(num_forecasts)]
158154

159155
# To make things trickier we make a second forecast at the same for one of the timestamps.
160156
timestamps = timestamps + timestamps[-1:]
@@ -168,6 +164,9 @@ def make_fake_forecast_values(db_session, sites, model_name):
168164
site_uuid=site.site_uuid, forecast_version=forecast_version, timestamp_utc=timestamp
169165
)
170166

167+
timestamp = pd.Timestamp(timestamp)
168+
timestamp = timestamp.floor('15min')
169+
171170
db_session.add(forecast)
172171
db_session.commit()
173172

src/india_api/internal/inputs/indiadb/test_csv.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ def test_format_csv_and_created_time(self, client, forecast_values_wind) -> None
7171
assert result[0]["Time"].dtype == "object"
7272
assert result[0]["PowerMW"].dtype == "float64"
7373

74+
assert len(result[0]) == 10 # only future, 2.5 hours from now
75+
7476

7577
# TODO add DA test
7678

src/india_api/internal/inputs/indiadb/test_indiadb.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ def test_get_predicted_wind_power_production_for_location(
2828
) -> None:
2929
locID = "testID"
3030
result = client.get_predicted_wind_power_production_for_location(locID)
31+
print(result)
3132

32-
assert len(result) == 110
33+
assert len(result) == 19 # 8 backwards, 10 forwards, 1 now
3334
for record in result:
3435
assert isinstance(record, PredictedPower)
3536

@@ -46,7 +47,7 @@ def test_get_predicted_solar_power_production_for_location(
4647
locID = "testID"
4748
result = client.get_predicted_solar_power_production_for_location(locID)
4849

49-
assert len(result) == 110
50+
assert len(result) == 19 # 8 backwards, 10 forwards, 1 now
5051
for record in result:
5152
assert isinstance(record, PredictedPower)
5253

0 commit comments

Comments
 (0)