From 20de64bd37f442eaa969bd1d76fd6f891cd51378 Mon Sep 17 00:00:00 2001 From: James Fulton Date: Wed, 13 Dec 2023 13:15:18 +0000 Subject: [PATCH] fix tests --- pvnet_app/data.py | 4 +++- tests/conftest.py | 7 +++---- tests/test_app.py | 36 ++---------------------------------- 3 files changed, 8 insertions(+), 39 deletions(-) diff --git a/pvnet_app/data.py b/pvnet_app/data.py index fc8eee3..a85794e 100644 --- a/pvnet_app/data.py +++ b/pvnet_app/data.py @@ -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(): diff --git a/tests/conftest.py b/tests/conftest.py index 4b23f3f..ed8b6a5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 diff --git a/tests/test_app.py b/tests/test_app.py index 9e6fc96..8b3c3fd 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -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 @@ -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" @@ -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() \ No newline at end of file