Skip to content

Commit 6d0e697

Browse files
Divide up integration tests (#224)
* refactor tests, and only run integration tests on `main` * set test dir in step 1 * add runs-on * divide out workflows * format * tidy * fix * use tests dir * add comment * change check to repo owner * tidy * change to !- pull request * update comment * echo * use github output * run second job if push * format * pytest.mark.integration * add timeout * remove timeout from merge * turn normalised error into percent * limit metrics to 3sf * update site used in test_evaluation script to give non nan result * add pytest.ini file to mark integration tests * update forecast test with no ts * update forecast test with no ts spelling --------- Co-authored-by: Megawattz <[email protected]>
1 parent d00f5a8 commit 6d0e697

18 files changed

+57
-34
lines changed

.github/workflows/pytest.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,28 @@ on:
88
- cron: "0 12 * * 1"
99
pull_request_target:
1010
types: [opened, synchronize, reopened, ready_for_review]
11+
1112
jobs:
12-
call-run-python-tests:
13+
call-run-python-tests-unit:
14+
uses: openclimatefix/.github/.github/workflows/python-test.yml@issue/pip-all
15+
with:
16+
# pytest-cov looks at this folder
17+
pytest_cov_dir: "quartz_solar_forecast"
18+
os_list: '["ubuntu-latest"]'
19+
python-version: "['3.11']"
20+
extra_commands: echo "HF_TOKEN=${{ vars.HF_TOKEN }}" > .env
21+
pytest_numcpus: '1'
22+
test_dir: tests/unit
23+
24+
call-run-python-tests-all:
25+
# only run on push, not external PR
1326
uses: openclimatefix/.github/.github/workflows/python-test.yml@issue/pip-all
27+
if: github.event_name == 'push'
1428
with:
1529
# pytest-cov looks at this folder
1630
pytest_cov_dir: "quartz_solar_forecast"
1731
os_list: '["ubuntu-latest"]'
1832
python-version: "['3.11']"
1933
extra_commands: echo "HF_TOKEN=${{ vars.HF_TOKEN }}" > .env
2034
pytest_numcpus: '1'
35+
test_dir: tests

pytest.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[pytest]
2+
markers =
3+
integration: marks tests as integration tests

quartz_solar_forecast/eval/metrics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def metrics(results_df: pd.DataFrame, pv_metadata: pd.DataFrame, include_night:
3535
.mean(),
3636
4,
3737
)
38-
print(f"MAE: {mae} kw, normalized {mae_normalized} %")
38+
print(f"MAE: {mae} kw, normalized {100*mae_normalized} %")
3939

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

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

8080
# TODO add more metrics using ocf_ml_metrics

tests/eval/test_evaluation.py renamed to tests/integration/eval/test_evaluation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from quartz_solar_forecast.evaluation import run_eval
22
import tempfile
33
import pandas as pd
4+
import pytest
45

56

7+
@pytest.mark.integration
68
def test_run_eval():
79

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

2123
testset_filename = tmpdirname + "/test_dataset.csv"

tests/eval/test_nwp.py renamed to tests/integration/eval/test_nwp.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from quartz_solar_forecast.eval.nwp import get_nwp
22
import pandas as pd
3+
import pytest
34

45

56
# can take ~ 1 minute to run
7+
@pytest.mark.integration
68
def test_get_nwp():
79
# make test dataset file
810
test_set_df = pd.DataFrame(

tests/eval/test_pv.py renamed to tests/integration/eval/test_pv.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from quartz_solar_forecast.eval.pv import get_pv_truth, get_pv_metadata
22
import pandas as pd
3+
import pytest
34

4-
5+
@pytest.mark.integration
56
def test_get_pv_metadata():
67
test_set_df = pd.DataFrame(
78
[
@@ -16,6 +17,7 @@ def test_get_pv_metadata():
1617
assert "latitude" in metadata_df.columns
1718

1819

20+
@pytest.mark.integration
1921
def test_get_pv():
2022
# make test dataset file
2123
test_set_df = pd.DataFrame(

tests/test_forecast_no_ts.py

Lines changed: 0 additions & 29 deletions
This file was deleted.
File renamed without changes.

0 commit comments

Comments
 (0)