Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Divide up integration tests #224

Merged
merged 28 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
04b43a8
refactor tests, and only run integration tests on `main`
peterdudfield Nov 18, 2024
2a5b9fb
set test dir in step 1
peterdudfield Nov 18, 2024
c4bf3a8
add runs-on
peterdudfield Nov 18, 2024
ec8490c
divide out workflows
peterdudfield Nov 18, 2024
9691a3e
format
peterdudfield Nov 18, 2024
16d51ab
tidy
peterdudfield Nov 18, 2024
edf02a0
fix
peterdudfield Nov 18, 2024
d3ea54b
use tests dir
peterdudfield Nov 18, 2024
7da6ce1
add comment
peterdudfield Nov 18, 2024
095c669
change check to repo owner
peterdudfield Nov 18, 2024
1b6bae9
tidy
peterdudfield Nov 18, 2024
09733dd
change to !- pull request
peterdudfield Nov 18, 2024
4072c97
update comment
peterdudfield Nov 18, 2024
0d348e9
echo
peterdudfield Nov 18, 2024
3837333
use github output
peterdudfield Nov 18, 2024
7c2475d
run second job if push
peterdudfield Nov 18, 2024
28b5674
format
peterdudfield Nov 18, 2024
14530d9
pytest.mark.integration
peterdudfield Nov 18, 2024
f1ff28e
add timeout
peterdudfield Nov 19, 2024
89877e5
Merge commit '69d92afb847d1abdcc8c7d2b1dc44661c0d9240b' into divide-u…
peterdudfield Nov 19, 2024
d90723e
Merge branch 'main' into divide-up-integration-tests
zakwatts Jan 23, 2025
822c1d4
remove timeout from merge
zakwatts Jan 24, 2025
9bd80f5
turn normalised error into percent
zakwatts Jan 24, 2025
6d2f7f1
limit metrics to 3sf
zakwatts Jan 24, 2025
54a0bff
update site used in test_evaluation script to give non nan result
zakwatts Jan 24, 2025
8ea97ba
add pytest.ini file to mark integration tests
zakwatts Jan 24, 2025
df662f3
update forecast test with no ts
zakwatts Jan 24, 2025
6786a4c
update forecast test with no ts spelling
zakwatts Jan 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,28 @@ on:
- cron: "0 12 * * 1"
pull_request_target:
types: [opened, synchronize, reopened, ready_for_review]

jobs:
call-run-python-tests:
call-run-python-tests-unit:
uses: openclimatefix/.github/.github/workflows/python-test.yml@issue/pip-all
with:
# pytest-cov looks at this folder
pytest_cov_dir: "quartz_solar_forecast"
os_list: '["ubuntu-latest"]'
python-version: "['3.11']"
extra_commands: echo "HF_TOKEN=${{ vars.HF_TOKEN }}" > .env
pytest_numcpus: '1'
test_dir: tests/unit

call-run-python-tests-all:
# only run on push, not external PR
uses: openclimatefix/.github/.github/workflows/python-test.yml@issue/pip-all
if: github.event_name == 'push'
with:
# pytest-cov looks at this folder
pytest_cov_dir: "quartz_solar_forecast"
os_list: '["ubuntu-latest"]'
python-version: "['3.11']"
extra_commands: echo "HF_TOKEN=${{ vars.HF_TOKEN }}" > .env
pytest_numcpus: '1'
test_dir: tests
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
markers =
integration: marks tests as integration tests
4 changes: 2 additions & 2 deletions quartz_solar_forecast/eval/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def metrics(results_df: pd.DataFrame, pv_metadata: pd.DataFrame, include_night:
.mean(),
4,
)
print(f"MAE: {mae} kw, normalized {mae_normalized} %")
print(f"MAE: {mae} kw, normalized {100*mae_normalized} %")

# calculate metrics over the different horizons hours
# find all unique horizon_hours
Expand Down Expand Up @@ -74,7 +74,7 @@ def metrics(results_df: pd.DataFrame, pv_metadata: pd.DataFrame, include_night:
)

print(
f"MAE for horizon {horizon_group}: {mae} +- {1.96*sem}. mae_normalized: {100*mae_normalized} %"
f"MAE for horizon {horizon_group}: {mae} +- {1.96*sem:.3g}. mae_normalized: {100*mae_normalized:.3g} %"
)

# TODO add more metrics using ocf_ml_metrics
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from quartz_solar_forecast.evaluation import run_eval
import tempfile
import pandas as pd
import pytest


@pytest.mark.integration
def test_run_eval():

# create a fake dataframe
Expand All @@ -15,7 +17,7 @@ def test_run_eval():
"pv_id",
"timestamp",
],
data=[[8215, "2021-01-26 01:15:00"], [8215, "2021-01-30 16:30:00"]],
data=[[7593, "2021-08-21 12:00:00"], [7593, "2021-10-04 20:00:00"]],
)

testset_filename = tmpdirname + "/test_dataset.csv"
Expand Down
2 changes: 2 additions & 0 deletions tests/eval/test_nwp.py → tests/integration/eval/test_nwp.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from quartz_solar_forecast.eval.nwp import get_nwp
import pandas as pd
import pytest


# can take ~ 1 minute to run
@pytest.mark.integration
def test_get_nwp():
# make test dataset file
test_set_df = pd.DataFrame(
Expand Down
4 changes: 3 additions & 1 deletion tests/eval/test_pv.py → tests/integration/eval/test_pv.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from quartz_solar_forecast.eval.pv import get_pv_truth, get_pv_metadata
import pandas as pd
import pytest


@pytest.mark.integration
def test_get_pv_metadata():
test_set_df = pd.DataFrame(
[
Expand All @@ -16,6 +17,7 @@ def test_get_pv_metadata():
assert "latitude" in metadata_df.columns


@pytest.mark.integration
def test_get_pv():
# make test dataset file
test_set_df = pd.DataFrame(
Expand Down
29 changes: 0 additions & 29 deletions tests/test_forecast_no_ts.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
28 changes: 28 additions & 0 deletions tests/unit/test_forecast_no_ts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import pandas as pd
from quartz_solar_forecast.forecast import run_forecast
from quartz_solar_forecast.pydantic_models import PVSite


def test_run_forecast_no_ts():
# make input data
site = PVSite(latitude=51.75, longitude=-1.25, capacity_kwp=1.25)

current_ts = pd.Timestamp.now()

# run gradient boosting model with no ts
predictions_df = run_forecast(site=site, model="gb")
# check current ts agrees with dataset
assert predictions_df.index.min() >= current_ts - pd.Timedelta(hours=1)

print(predictions_df)
print(f"Current time: {current_ts}")
print(f"Max: {predictions_df['power_kw'].max()}")

# run xgb model with no ts
predictions_df = run_forecast(site=site, model="xgb")
# check current ts agrees with dataset
assert predictions_df.index.min() >= current_ts - pd.Timedelta(hours=1)

print(predictions_df)
print(f"Current time: {current_ts}")
print(f"Max: {predictions_df['power_kw'].max()}")
File renamed without changes.
File renamed without changes.
Loading