Skip to content

Commit

Permalink
test(export): add unit tests for VariantStudyService.generate_task
Browse files Browse the repository at this point in the history
…method
  • Loading branch information
laurent-laporte-pro committed Sep 12, 2023
1 parent 961929d commit a31feec
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions tests/study/storage/variantstudy/test_variant_study_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import numpy as np
import pytest
from sqlalchemy import create_engine # type: ignore

from antarest.core.model import PublicMode
from antarest.core.requests import RequestParameters
Expand Down Expand Up @@ -118,7 +117,7 @@ def test_generate_task(
denormalize: bool,
from_scratch: bool,
) -> None:
## Prepare database objects
# Prepare database objects
# noinspection PyArgumentList
user = User(id=0, name="admin")
db.session.add(user)
Expand All @@ -129,7 +128,7 @@ def test_generate_task(
db.session.add(group)
db.session.commit()

## First create a raw study (root of the variant)
# First create a raw study (root of the variant)
raw_study_path = tmp_path / "My RAW Study"
# noinspection PyArgumentList
raw_study = RawStudy(
Expand All @@ -149,7 +148,7 @@ def test_generate_task(
db.session.add(raw_study)
db.session.commit()

## Prepare the RAW Study
# Prepare the RAW Study
raw_study_service.create(raw_study)

variant_study = variant_study_service.create_variant_study(
Expand All @@ -161,7 +160,7 @@ def test_generate_task(
),
)

## Prepare the RAW Study
# Prepare the RAW Study
file_study = variant_study_service.get_raw(variant_study)

command_context = CommandContext(
Expand All @@ -175,7 +174,7 @@ def test_generate_task(
area_name="fr",
)

## Prepare the Variant Study Data
# Prepare the Variant Study Data
# noinspection SpellCheckingInspection
pmax_injection = np.random.rand(8760, 1)
inflows = np.random.uniform(0, 1000, size=(8760, 1))
Expand Down Expand Up @@ -205,7 +204,7 @@ def test_generate_task(
storage_service=study_storage_service,
)

## Run the "generate" task
# Run the "generate" task
actual_uui = variant_study_service.generate_task(
variant_study,
denormalize=denormalize,
Expand All @@ -217,7 +216,7 @@ def test_generate_task(
flags=re.IGNORECASE,
)

## Collect the resulting files
# Collect the resulting files
workspaces = variant_study_service.config.storage.workspaces
internal_studies_dir: Path = workspaces["default"].path
snapshot_dir = internal_studies_dir.joinpath(variant_study.snapshot.id, "snapshot")
Expand Down

0 comments on commit a31feec

Please sign in to comment.