Skip to content

Commit

Permalink
30 test don't pass
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle committed Jan 21, 2025
1 parent 4e0f38d commit cacdd62
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
9 changes: 7 additions & 2 deletions tests/variantstudy/model/command/test_create_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
import numpy as np
import pytest
from pydantic import ValidationError
from sqlalchemy.orm import Session

from antarest.core.exceptions import LinkValidationError
from antarest.study.business.link_management import LinkInternal
from antarest.study.model import STUDY_VERSION_8_8
from antarest.study.model import STUDY_VERSION_8_8, RawStudy
from antarest.study.storage.rawstudy.ini_reader import IniReader
from antarest.study.storage.rawstudy.model.filesystem.config.model import transform_name_to_id
from antarest.study.storage.rawstudy.model.filesystem.factory import FileStudy
Expand Down Expand Up @@ -57,9 +58,13 @@ def test_validation(self, empty_study: FileStudy, command_context: CommandContex
study_version=STUDY_VERSION_8_8,
)

def test_apply(self, empty_study: FileStudy, command_context: CommandContext):
def test_apply(self, empty_study: FileStudy, command_context: CommandContext, db_session: Session):
study_version = empty_study.config.version
study_path = empty_study.config.study_path
raw_study = RawStudy(id=empty_study.config.study_id, version=str(study_version), path=str(study_path))
db_session.add(raw_study)
db_session.commit()

area1 = "Area1"
area1_id = transform_name_to_id(area1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

import numpy as np
import pytest
from sqlalchemy.orm import Session

from antarest.study.model import STUDY_VERSION_8_8
from antarest.study.model import STUDY_VERSION_8_8, RawStudy
from antarest.study.storage.rawstudy.ini_reader import IniReader
from antarest.study.storage.rawstudy.model.filesystem.config.binding_constraint import (
BindingConstraintFrequency,
Expand Down Expand Up @@ -232,13 +233,17 @@ def test_manage_binding_constraint(empty_study: FileStudy, command_context: Comm


@pytest.mark.parametrize("empty_study", ["empty_study_870.zip"], indirect=True)
def test_scenario_builder(empty_study: FileStudy, command_context: CommandContext):
def test_scenario_builder(empty_study: FileStudy, command_context: CommandContext, db_session: Session):
"""
Test that the scenario builder is updated when a binding constraint group is renamed or removed
"""
# This test requires a study with version >= 870, which support "scenarised" binding constraints.
study_version = empty_study.config.version
assert study_version >= 870
study_id = empty_study.config.study_id
raw_study = RawStudy(id=study_id, version=str(study_version), path=str(empty_study.config.study_path))
db_session.add(raw_study)
db_session.commit()

# Create two areas and a link between them:
areas = {name: transform_name_to_id(name) for name in ["Area X", "Area Y"]}
Expand Down
16 changes: 11 additions & 5 deletions tests/variantstudy/model/command/test_remove_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@

import pytest
from checksumdir import dirhash
from sqlalchemy.orm import Session

from antarest.study.model import STUDY_VERSION_8_8
from antarest.study.model import STUDY_VERSION_8_8, RawStudy
from antarest.study.storage.rawstudy.model.filesystem.config.binding_constraint import (
BindingConstraintFrequency,
BindingConstraintOperator,
Expand Down Expand Up @@ -79,10 +80,15 @@ def test_remove_with_aggregated(self, empty_study: FileStudy, command_context: C
assert output.status, output.message

@pytest.mark.parametrize("empty_study", ["empty_study_810.zip", "empty_study_840.zip"], indirect=True)
def test_apply(self, empty_study: FileStudy, command_context: CommandContext):
def test_apply(self, empty_study: FileStudy, command_context: CommandContext, db_session: Session):
# noinspection SpellCheckingInspection
(empty_study, area_id) = self._set_up(empty_study, command_context)
study_version = empty_study.config.version
study_path = empty_study.config.study_path

raw_study = RawStudy(id=empty_study.config.study_id, version=str(study_version), path=str(study_path))
db_session.add(raw_study)
db_session.commit()

create_district_command = CreateDistrict(
name="foo",
Expand Down Expand Up @@ -111,8 +117,8 @@ def test_apply(self, empty_study: FileStudy, command_context: CommandContext):
########################################################################################

# Line ending of the `settings/scenariobuilder.dat` must be reset before checksum
reset_line_separator(empty_study.config.study_path.joinpath("settings/scenariobuilder.dat"))
hash_before_removal = dirhash(empty_study.config.study_path, "md5")
reset_line_separator(study_path.joinpath("settings/scenariobuilder.dat"))
hash_before_removal = dirhash(study_path, "md5")

empty_study_cfg = empty_study.tree.get(depth=999)
if study_version >= 830:
Expand Down Expand Up @@ -238,7 +244,7 @@ def test_apply(self, empty_study: FileStudy, command_context: CommandContext):
)
output = remove_area_command.apply(study_data=empty_study)
assert output.status, output.message
assert dirhash(empty_study.config.study_path, "md5") == hash_before_removal
assert dirhash(study_path, "md5") == hash_before_removal

actual_cfg = empty_study.tree.get(depth=999)
assert actual_cfg == empty_study_cfg
Expand Down

0 comments on commit cacdd62

Please sign in to comment.