Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dfulu committed Dec 13, 2023
1 parent d696371 commit 20de64b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 39 deletions.
4 changes: 3 additions & 1 deletion pvnet_app/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ def preprocess_sat_data(t0):
logger.info(f"Latest 15-minute timestamp is {latest_time_15} for t0 time {t0}.")

logger.debug("Resampling 15 minute data to 5 mins")
ds_sat_15.resample(time="5T").interpolate("linear").to_zarr(sat_path)
#ds_sat_15.resample(time="5T").interpolate("linear").to_zarr(sat_path)
ds_sat_15.attrs["source"] = "15-minute"
ds_sat_15.to_zarr(sat_path)


def download_nwp_data():
Expand Down
7 changes: 3 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,11 @@ def sat_5_data():

@pytest.fixture()
def sat_5_data_delayed(sat_5_data):
sat_5_delayed = sat_5_data.copy(deep=True)

# Set the most recent timestamp to 2 - 2.5 hours ago
t_most_recent = time_before_present(timedelta(hours=2)).floor(timedelta(minutes=30))
offset = sat_5_delayed.time.max().values - t_most_recent
sat_5_delayed.time.values[:] = sat_5_delayed.time.values - offset
offset = sat_5_data.time.max().values - t_most_recent
sat_5_delayed = sat_5_data.copy(deep=True)
sat_5_delayed["time"] = sat_5_data.time.values - offset
return sat_5_delayed


Expand Down
36 changes: 2 additions & 34 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)


def _test_app(db_session, nwp_data, sat_5_data, sat_15_data, gsp_yields_and_systems, me_latest):
def test_app(db_session, nwp_data, sat_5_data, gsp_yields_and_systems, me_latest):
# Environment variable DB_URL is set in engine_url, which is called by db_session
# set NWP_ZARR_PATH
# save nwp_data to temporary file, and set NWP_ZARR_PATH
Expand All @@ -32,13 +32,6 @@ def _test_app(db_session, nwp_data, sat_5_data, sat_15_data, gsp_yields_and_syst
store = zarr.storage.ZipStore(temp_sat_path, mode="x")
sat_5_data.to_zarr(store)
store.close()

# Maybe save the 15-minute data too
if sat_15_data is not None:
temp_sat_path = os.environ["SATELLITE_ZARR_PATH"].replace("sat.zarr", "sat_15.zarr")
store = zarr.storage.ZipStore(temp_sat_path, mode="x")
sat_15_data.to_zarr(store)
store.close()

# Set model version
os.environ["SAVE_GSP_SUM"] = "True"
Expand All @@ -65,29 +58,4 @@ def _test_app(db_session, nwp_data, sat_5_data, sat_15_data, gsp_yields_and_syst

# Clean up
db_session.query(ForecastSQL).delete()
db_session.commit()


def test_app_5(db_session, nwp_data, sat_5_data, gsp_yields_and_systems, me_latest):

_test_app(
db_session=db_session,
nwp_data=nwp_data,
sat_5_data=sat_5_data,
sat_15_data=None,
gsp_yields_and_systems=gsp_yields_and_systems,
me_latest=me_latest
)


def test_app_15(
db_session, nwp_data, sat_5_data_delayed, sat_15_data, gsp_yields_and_systems, me_latest
):
_test_app(
db_session=db_session,
nwp_data=nwp_data,
sat_5_data=sat_5_data_delayed,
sat_15_data=sat_15_data,
gsp_yields_and_systems=gsp_yields_and_systems,
me_latest=me_latest
)
db_session.commit()

0 comments on commit 20de64b

Please sign in to comment.