Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdudfield committed Dec 6, 2024
1 parent a30cef2 commit 5d0f54c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tests/test_app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from click.testing import CliRunner
from datetime import datetime, timedelta
from nowcasting_datamodel.models.gsp import GSPYieldSQL, Location, LocationSQL
from nowcasting_datamodel.models.models import national_gb_label

Expand Down Expand Up @@ -105,8 +106,8 @@ def test_app_day_after_national_only(db_connection, input_data_last_updated_sql)
gsp_yields = session.query(GSPYieldSQL).all()
assert len(gsp_yields) == 1 * 49 # 1 gsps with 48 half hour settlement periods + midnight


@freeze_time("2024-09-16 12:00:00")
tomorrow_date = (datetime.today() + timedelta(days=1)).date()
@freeze_time(tomorrow_date)
def test_app_day_after_gsp_only(db_connection, input_data_last_updated_sql):
runner = CliRunner()
response = runner.invoke(
Expand Down
50 changes: 50 additions & 0 deletions tests/test_nighttime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from gspconsumer.nitghtime import make_night_time_zeros
from datetime import datetime
from nowcasting_datamodel.models.gsp import LocationSQL, GSPYieldSQL
import pandas as pd


from nowcasting_datamodel.read.read import get_location

def test_make_night_time_zeros_wrong_regime():

start = datetime(2021, 1, 1)
end = datetime(2021, 1, 2)
gsp = LocationSQL(gsp_id=1)
gsp_yield_df = pd.DataFrame()
regime = "wrong"

result = make_night_time_zeros(start, end, gsp, gsp_yield_df, regime)

assert result.equals(gsp_yield_df)

def test_make_night_time_zeros(db_session):
start = datetime(2021, 1, 1)
end = datetime(2021, 1, 2)
gsp = get_location(session=db_session, gsp_id=1)
gsp.last_gsp_yield = None
gsp_yield_df = pd.DataFrame()
regime = "in-day"

result = make_night_time_zeros(start, end, gsp, gsp_yield_df, regime)

# there should be around 18 hours of darkness which is 28 half hour intervals
# sun set is ~16:00 and sun rise is ~8:00 for
assert len(result) == 36
assert result["generation_mw"].sum() == 0


def test_make_night_time_zeros_with_last_gsp_yield(db_session):
start = datetime(2021, 1, 1)
end = datetime(2021, 1, 2)
gsp = get_location(session=db_session, gsp_id=1)
gsp.last_gsp_yield = GSPYieldSQL(solar_generation_kw=1000, capacity_mwp=1.1, pvlive_updated_utc=start)
gsp_yield_df = pd.DataFrame()
regime = "in-day"

result = make_night_time_zeros(start, end, gsp, gsp_yield_df, regime)

assert len(result) == 36
assert result["generation_mw"].sum() == 0
assert result["capacity_mwp"][0] == 1.1

0 comments on commit 5d0f54c

Please sign in to comment.