From 04b43a8ef852dd943687924e0852dd9c674258ba Mon Sep 17 00:00:00 2001 From: peterdudfield Date: Mon, 18 Nov 2024 20:20:52 +0000 Subject: [PATCH] refactor tests, and only run integration tests on `main` --- .github/workflows/pytest.yaml | 2 ++ tests/{ => integration}/eval/test_evaluation.py | 2 ++ tests/{ => integration}/eval/test_nwp.py | 2 ++ tests/{ => integration}/eval/test_pv.py | 4 +++- tests/{ => unit}/api_tests/test_api.py | 0 tests/{ => unit}/data/test_make_test_set.py | 0 tests/{ => unit}/data/test_process_pv_data.py | 0 tests/{ => unit}/eval/test_eval_forecast.py | 0 tests/{ => unit}/eval/test_metrics.py | 0 tests/{ => unit}/inverters/test_process_enphase_data.py | 0 tests/{ => unit}/inverters/test_victron.py | 0 tests/{ => unit}/test_forecast.py | 0 tests/{ => unit}/test_forecast_no_ts.py | 0 tests/{ => unit}/test_generate_forecast.py | 0 tests/{ => unit}/utils/test_file_path.py | 0 15 files changed, 9 insertions(+), 1 deletion(-) rename tests/{ => integration}/eval/test_evaluation.py (94%) rename tests/{ => integration}/eval/test_nwp.py (92%) rename tests/{ => integration}/eval/test_pv.py (91%) rename tests/{ => unit}/api_tests/test_api.py (100%) rename tests/{ => unit}/data/test_make_test_set.py (100%) rename tests/{ => unit}/data/test_process_pv_data.py (100%) rename tests/{ => unit}/eval/test_eval_forecast.py (100%) rename tests/{ => unit}/eval/test_metrics.py (100%) rename tests/{ => unit}/inverters/test_process_enphase_data.py (100%) rename tests/{ => unit}/inverters/test_victron.py (100%) rename tests/{ => unit}/test_forecast.py (100%) rename tests/{ => unit}/test_forecast_no_ts.py (100%) rename tests/{ => unit}/test_generate_forecast.py (100%) rename tests/{ => unit}/utils/test_file_path.py (100%) diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml index ec5addb6..40dfe4c1 100644 --- a/.github/workflows/pytest.yaml +++ b/.github/workflows/pytest.yaml @@ -18,3 +18,5 @@ jobs: python-version: "['3.11']" extra_commands: echo "HF_TOKEN=${{ vars.HF_TOKEN }}" > .env pytest_numcpus: '1' + # if branch is 'main' then run all tests, if not only run unittests + test_dir: ${{ github.ref == 'refs/heads/main' && '' || 'tests/unit' }} diff --git a/tests/eval/test_evaluation.py b/tests/integration/eval/test_evaluation.py similarity index 94% rename from tests/eval/test_evaluation.py rename to tests/integration/eval/test_evaluation.py index e6548b2b..ce94986d 100644 --- a/tests/eval/test_evaluation.py +++ b/tests/integration/eval/test_evaluation.py @@ -1,8 +1,10 @@ from quartz_solar_forecast.evaluation import run_eval import tempfile import pandas as pd +import pytest +@pytest.test.integration def test_run_eval(): # create a fake dataframe diff --git a/tests/eval/test_nwp.py b/tests/integration/eval/test_nwp.py similarity index 92% rename from tests/eval/test_nwp.py rename to tests/integration/eval/test_nwp.py index e9c3659b..46b786cc 100644 --- a/tests/eval/test_nwp.py +++ b/tests/integration/eval/test_nwp.py @@ -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.test.integration def test_get_nwp(): # make test dataset file test_set_df = pd.DataFrame( diff --git a/tests/eval/test_pv.py b/tests/integration/eval/test_pv.py similarity index 91% rename from tests/eval/test_pv.py rename to tests/integration/eval/test_pv.py index 51739547..56698c6e 100644 --- a/tests/eval/test_pv.py +++ b/tests/integration/eval/test_pv.py @@ -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( [ @@ -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( diff --git a/tests/api_tests/test_api.py b/tests/unit/api_tests/test_api.py similarity index 100% rename from tests/api_tests/test_api.py rename to tests/unit/api_tests/test_api.py diff --git a/tests/data/test_make_test_set.py b/tests/unit/data/test_make_test_set.py similarity index 100% rename from tests/data/test_make_test_set.py rename to tests/unit/data/test_make_test_set.py diff --git a/tests/data/test_process_pv_data.py b/tests/unit/data/test_process_pv_data.py similarity index 100% rename from tests/data/test_process_pv_data.py rename to tests/unit/data/test_process_pv_data.py diff --git a/tests/eval/test_eval_forecast.py b/tests/unit/eval/test_eval_forecast.py similarity index 100% rename from tests/eval/test_eval_forecast.py rename to tests/unit/eval/test_eval_forecast.py diff --git a/tests/eval/test_metrics.py b/tests/unit/eval/test_metrics.py similarity index 100% rename from tests/eval/test_metrics.py rename to tests/unit/eval/test_metrics.py diff --git a/tests/inverters/test_process_enphase_data.py b/tests/unit/inverters/test_process_enphase_data.py similarity index 100% rename from tests/inverters/test_process_enphase_data.py rename to tests/unit/inverters/test_process_enphase_data.py diff --git a/tests/inverters/test_victron.py b/tests/unit/inverters/test_victron.py similarity index 100% rename from tests/inverters/test_victron.py rename to tests/unit/inverters/test_victron.py diff --git a/tests/test_forecast.py b/tests/unit/test_forecast.py similarity index 100% rename from tests/test_forecast.py rename to tests/unit/test_forecast.py diff --git a/tests/test_forecast_no_ts.py b/tests/unit/test_forecast_no_ts.py similarity index 100% rename from tests/test_forecast_no_ts.py rename to tests/unit/test_forecast_no_ts.py diff --git a/tests/test_generate_forecast.py b/tests/unit/test_generate_forecast.py similarity index 100% rename from tests/test_generate_forecast.py rename to tests/unit/test_generate_forecast.py diff --git a/tests/utils/test_file_path.py b/tests/unit/utils/test_file_path.py similarity index 100% rename from tests/utils/test_file_path.py rename to tests/unit/utils/test_file_path.py