From 3bb9b4477db8c4ac1d1e7722d0cc65b962589c7b Mon Sep 17 00:00:00 2001 From: Fabrizio Finozzi Date: Fri, 22 Nov 2024 14:12:55 +0100 Subject: [PATCH] code: include requested comments to PR --- .github/workflows/test.yaml | 8 ++++++-- Makefile | 2 +- test/__init__.py | 2 +- test/conftest.py | 8 +++----- test/test_build_powerplants.py | 11 ++++------- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 3dec8fda3..537762c03 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -88,9 +88,13 @@ jobs: conda env update -n pypsa-eur -f ${{ env.env_file }} echo "Run conda list" && conda list - - name: Run snakemake test workflows and unit tests + - name: Run snakemake test workflows + run: | + make test + + - name: Run unit tests run: | - make checks + make unit-test - name: Upload artifacts if: always() diff --git a/Makefile b/Makefile index edac07cdf..c8763702d 100755 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ test: snakemake --configfile config/test/config.scenarios.yaml --rerun-triggers=mtime -n echo "All tests completed successfully." -checks: test +unit-test: pytest test # Cleans all output files from tests diff --git a/test/__init__.py b/test/__init__.py index fc781c2f0..dfadb19de 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -1,4 +1,4 @@ # -*- coding: utf-8 -*- -# SPDX-FileCopyrightText: : 2017-2023 The PyPSA-Eur Authors +# SPDX-FileCopyrightText: : 2017-2024 The PyPSA-Eur Authors # # SPDX-License-Identifier: MIT diff --git a/test/conftest.py b/test/conftest.py index fb04f5015..8b618cb3b 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -6,25 +6,23 @@ # coding: utf-8 import pathlib -import shutil - import pypsa import pytest import yaml @pytest.fixture(scope="function") -def get_power_network_scigrid_de(): +def scigrid_network(): return pypsa.examples.scigrid_de(from_master=True) @pytest.fixture(scope="function") -def get_power_network_ac_dc_meshed(): +def ac_dc_network(): return pypsa.examples.ac_dc_meshed(from_master=True) @pytest.fixture(scope="function") -def get_config_dict(): +def config(): path_config = pathlib.Path(pathlib.Path.cwd(), "config", "config.default.yaml") with open(path_config, "r") as file: config_dict = yaml.safe_load(file) diff --git a/test/test_build_powerplants.py b/test/test_build_powerplants.py index 69a309c16..60f09a934 100644 --- a/test/test_build_powerplants.py +++ b/test/test_build_powerplants.py @@ -8,17 +8,14 @@ Tests the functionalities of scripts/build_powerplants.py. """ -import pathlib -import sys - import numpy as np import pandas as pd +import pathlib import pytest +import sys sys.path.append("./scripts") -from test.conftest import get_config_dict - from build_powerplants import ( add_custom_powerplants, replace_natural_gas_fueltype, @@ -32,11 +29,11 @@ "query_value,expected", [(False, (131, 18)), (True, (137, 18))], ) -def test_add_custom_powerplants(get_config_dict, query_value, expected): +def test_add_custom_powerplants(config, query_value, expected): """ Verify what returned by add_custom_powerplants. """ - config_dict = get_config_dict + config_dict = config config_dict["electricity"]["custom_powerplants"] = query_value custom_powerplants_path = pathlib.Path( path_cwd, "test", "test_data", "custom_powerplants_DE.csv"