Skip to content

Commit

Permalink
factorisation, removal of unused import and move of test files
Browse files Browse the repository at this point in the history
  • Loading branch information
Yann-Temudjin committed Apr 5, 2024
1 parent fccf367 commit 006131b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 76 deletions.
26 changes: 26 additions & 0 deletions tests/unittests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,33 @@

import pytest

from andromede.model.parsing import parse_yaml_library
from andromede.model.resolve_library import resolve_library


@pytest.fixture(scope="session")
def data_dir() -> Path:
return Path(__file__).parent / "data"


@pytest.fixture(scope="session")
def lib(data_dir: Path):
lib_file = data_dir / "lib.yml"

with lib_file.open() as f:
input_lib = parse_yaml_library(f)

lib = resolve_library(input_lib)
return lib


@pytest.fixture(scope="session")
def lib_sc(data_dir: Path):
libs_path = Path(__file__).parents[2] / "src/andromede/libs/"
lib_sc_file = libs_path / "standard_sc.yml"

with lib_sc_file.open() as f:
input_lib_sc = parse_yaml_library(f)

lib_sc = resolve_library(input_lib_sc)
return lib_sc
64 changes: 4 additions & 60 deletions tests/unittests/model/test_electrolyzer_n_inputs_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,8 @@
# This file is part of the Antares project.

import math
import os
from pathlib import Path

from andromede.libs.standard import DEMAND_MODEL, GENERATOR_MODEL, NODE_BALANCE_MODEL
from andromede.libs.standard_sc import (
CONVERTOR_MODEL,
CONVERTOR_RECEIVE_IN,
DECOMPOSE_1_FLOW_INTO_2_FLOW,
NODE_BALANCE_MODEL_MOD,
TWO_INPUTS_CONVERTOR_MODEL,
)
from andromede.model.parsing import parse_yaml_library
from andromede.model.resolve_library import resolve_library
from andromede.simulation import OutputValues, TimeBlock, build_problem
from andromede.study import (
ConstantData,
Expand Down Expand Up @@ -54,7 +43,7 @@
"""


def test_electrolyzer_n_inputs_1(data_dir: Path):
def test_electrolyzer_n_inputs_1(data_dir: Path, lib, lib_sc):
"""
Test with an electrolyzer for each input
Expand All @@ -67,17 +56,6 @@ def test_electrolyzer_n_inputs_1(data_dir: Path):
total gaz production = flow_ep1 * alpha_ez1 + flow_ep2 * alpha_ez2 + flow_gp
"""
libs_path = Path(__file__).parents[3] / "src/andromede/libs/"
lib_file = data_dir / "lib.yml"
lib_sc_file = libs_path / "standard_sc.yml"

with lib_file.open() as f:
input_lib = parse_yaml_library(f)
with lib_sc_file.open() as f:
input_lib_sc = parse_yaml_library(f)

lib = resolve_library(input_lib)
lib_sc = resolve_library(input_lib_sc)

gen_model = lib.models["generator"]
node_model = lib.models["node"]
Expand Down Expand Up @@ -168,7 +146,7 @@ def test_electrolyzer_n_inputs_1(data_dir: Path):
assert math.isclose(problem.solver.Objective().Value(), 1990)


def test_electrolyzer_n_inputs_2(data_dir: Path):
def test_electrolyzer_n_inputs_2(data_dir: Path, lib, lib_sc):
"""
Test with one electrolyzer that has two inputs
Expand All @@ -180,18 +158,6 @@ def test_electrolyzer_n_inputs_2(data_dir: Path):
total gaz production = flow_ep1 * alpha1_ez + flow_ep2 * alpha2_ez + flow_gp
"""

libs_path = Path(__file__).parents[3] / "src/andromede/libs/"
lib_file = data_dir / "lib.yml"
lib_sc_file = libs_path / "standard_sc.yml"

with lib_file.open() as f:
input_lib = parse_yaml_library(f)
with lib_sc_file.open() as f:
input_lib_sc = parse_yaml_library(f)

lib = resolve_library(input_lib)
lib_sc = resolve_library(input_lib_sc)

gen_model = lib.models["generator"]
node_model = lib.models["node"]
convertor_model = lib_sc.models["two_input_convertor"]
Expand Down Expand Up @@ -278,7 +244,7 @@ def test_electrolyzer_n_inputs_2(data_dir: Path):
assert math.isclose(problem.solver.Objective().Value(), 1990)


def test_electrolyzer_n_inputs_3(data_dir: Path):
def test_electrolyzer_n_inputs_3(data_dir: Path, lib, lib_sc):
"""
Test with a consumption_electrolyzer with two inputs
Expand All @@ -291,17 +257,6 @@ def test_electrolyzer_n_inputs_3(data_dir: Path):
The result is different since we only have one alpha at 0.7
"""
libs_path = Path(__file__).parents[3] / "src/andromede/libs/"
lib_file = data_dir / "lib.yml"
lib_sc_file = libs_path / "standard_sc.yml"

with lib_file.open() as f:
input_lib = parse_yaml_library(f)
with lib_sc_file.open() as f:
input_lib_sc = parse_yaml_library(f)

lib = resolve_library(input_lib)
lib_sc = resolve_library(input_lib_sc)

gen_model = lib.models["generator"]
node_model = lib.models["node"]
Expand Down Expand Up @@ -394,7 +349,7 @@ def test_electrolyzer_n_inputs_3(data_dir: Path):
assert math.isclose(problem.solver.Objective().Value(), 1750)


def test_electrolyzer_n_inputs_4(data_dir: Path):
def test_electrolyzer_n_inputs_4(data_dir: Path, lib, lib_sc):
"""
Test with one electrolyzer with one input that takes every inputs
Expand All @@ -407,17 +362,6 @@ def test_electrolyzer_n_inputs_4(data_dir: Path):
same as test 3, the result is different than the first two since we only have one alpha at 0.7
"""
libs_path = Path(__file__).parents[3] / "src/andromede/libs/"
lib_file = data_dir / "lib.yml"
lib_sc_file = libs_path / "standard_sc.yml"

with lib_file.open() as f:
input_lib = parse_yaml_library(f)
with lib_sc_file.open() as f:
input_lib_sc = parse_yaml_library(f)

lib = resolve_library(input_lib)
lib_sc = resolve_library(input_lib_sc)

gen_model = lib.models["generator"]
node_model = lib.models["node"]
Expand Down
File renamed without changes.
17 changes: 1 addition & 16 deletions tests/unittests/model/test_quota_co2_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
import math
from pathlib import Path

from andromede.libs.standard import DEMAND_MODEL, LINK_MODEL, NODE_BALANCE_MODEL
from andromede.libs.standard_sc import C02_POWER_MODEL, QUOTA_CO2_MODEL
from andromede.model.parsing import parse_yaml_library
from andromede.model.resolve_library import resolve_library
from andromede.simulation import OutputValues, TimeBlock, build_problem
from andromede.study import (
ConstantData,
Expand All @@ -42,18 +38,7 @@
""" Test of a generation of energy and co2 with a quota to limit the emission"""


def test_quota_co2(data_dir: Path):
libs_path = Path(__file__).parents[3] / "src/andromede/libs/"
lib_file = data_dir / "lib.yml"
lib_sc_file = libs_path / "standard_sc.yml"

with lib_file.open() as f:
input_lib = parse_yaml_library(f)
with lib_sc_file.open() as f:
input_lib_sc = parse_yaml_library(f)

lib = resolve_library(input_lib)
lib_sc = resolve_library(input_lib_sc)
def test_quota_co2(data_dir: Path, lib, lib_sc):

gen_model = lib_sc.models["generator_with_co2"]
node_model = lib.models["node"]
Expand Down

0 comments on commit 006131b

Please sign in to comment.