From 76353372b15a7688c339412318c6ecdead379273 Mon Sep 17 00:00:00 2001 From: MartinBelthle Date: Wed, 19 Feb 2025 12:57:56 +0100 Subject: [PATCH 1/2] chore(simulator): bump simulator v8.8 version inside Desktop app (#2355) --- scripts/package_antares_web.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/package_antares_web.sh b/scripts/package_antares_web.sh index 9c1f8c3035..fb799bfbfc 100755 --- a/scripts/package_antares_web.sh +++ b/scripts/package_antares_web.sh @@ -9,7 +9,7 @@ set -e ANTARES_SOLVER_VERSION="8.8" -ANTARES_SOLVER_FULL_VERSION="8.8.11" +ANTARES_SOLVER_FULL_VERSION="8.8.13" ANTARES_SOLVER_VERSION_INT="880" SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P) From c428a2adb0f5efbe95bdd2c98bffc2b9782b31f2 Mon Sep 17 00:00:00 2001 From: MartinBelthle Date: Wed, 19 Feb 2025 14:01:14 +0100 Subject: [PATCH 2/2] build(lint): use ruff instead of isort and black (#2349) --- .github/workflows/main.yml | 14 +--- antarest/__init__.py | 1 + antarest/core/filesystem_blueprint.py | 1 + antarest/core/persistence.py | 4 +- antarest/core/serde/__init__.py | 1 - .../utils/fastapi_sqlalchemy/middleware.py | 2 +- antarest/core/version_info.py | 1 + antarest/dbmodel.py | 24 ------ antarest/eventbus/web.py | 1 - antarest/launcher/model.py | 7 +- antarest/launcher/repository.py | 2 +- antarest/main.py | 5 +- antarest/service_creator.py | 3 - antarest/study/business/area_management.py | 1 - .../business/areas/renewable_management.py | 1 - .../business/binding_constraint_management.py | 5 +- .../study/business/correlation_management.py | 1 + .../business/scenario_builder_management.py | 1 - antarest/study/business/study_interface.py | 1 - .../business/thematic_trimming_field_infos.py | 4 +- antarest/study/model.py | 3 +- antarest/study/service.py | 2 +- antarest/study/storage/df_download.py | 6 ++ .../filesystem/config/field_validators.py | 1 - .../model/filesystem/config/st_storage.py | 2 +- .../model/filesystem/config/thermal.py | 2 +- .../model/filesystem/matrix/matrix.py | 1 - .../model/filesystem/root/input/areas/list.py | 2 +- .../root/settings/scenariobuilder.py | 2 +- .../business/matrix_constants/__init__.py | 2 + .../matrix_constants/hydro/__init__.py | 2 + .../matrix_constants/link/__init__.py | 2 + .../matrix_constants/st_storage/__init__.py | 2 +- .../matrix_constants/thermals/__init__.py | 2 +- .../storage/variantstudy/command_factory.py | 1 - .../variantstudy/model/command/create_area.py | 12 +-- .../model/command/create_cluster.py | 2 +- .../model/command/update_area_ui.py | 2 +- .../variantstudy/model/command_context.py | 1 - .../storage/variantstudy/model/interfaces.py | 32 ++++---- .../variantstudy/snapshot_generator.py | 1 + .../variantstudy/variant_command_generator.py | 2 +- .../variantstudy/variant_study_service.py | 9 +-- antarest/study/web/raw_studies_blueprint.py | 6 -- antarest/study/web/study_data_blueprint.py | 1 - antarest/study/web/variant_blueprint.py | 1 - docs/developer-guide/0-developer-tools.md | 16 ++++ ...ersion.md => 1-add-new-antares-version.md} | 0 .../{5-roadmap.md => 2-roadmap.md} | 0 .../architecture/0-introduction.md | 2 +- mkdocs.yml | 4 +- pyproject.toml | 68 +--------------- requirements-dev.txt | 4 +- tests/conftest.py | 9 +-- tests/conftest_db.py | 2 - tests/conftest_instances.py | 5 +- tests/conftest_services.py | 1 + tests/core/test_tasks.py | 2 +- tests/db_statement_recorder.py | 1 + .../test_download_matrices.py | 13 ++- .../studies_blueprint/test_get_studies.py | 14 ++-- .../test_binding_constraints.py | 2 +- .../study_data_blueprint/test_thermal.py | 1 + tests/integration/test_integration.py | 80 +++++++++---------- tests/integration/test_integration_watcher.py | 2 +- .../variant_blueprint/test_variant_manager.py | 16 ++-- tests/login/test_web.py | 2 +- .../test_matrix_garbage_collector.py | 3 +- tests/matrixstore/test_repository.py | 5 +- tests/matrixstore/test_service.py | 14 +--- .../storage/business/test_arealink_manager.py | 3 - tests/storage/business/test_config_manager.py | 3 - .../test_timeseries_config_manager.py | 2 +- .../business/test_variant_study_service.py | 1 - .../integration/test_write_STA_mini.py | 18 ----- .../hydro/common/capacity/test_capacity.py | 9 +-- .../root/input/hydro/series/area/test_area.py | 9 +-- .../simulation/mode/common/test_area.py | 11 ++- .../mode/common/test_binding_const.py | 6 +- .../simulation/mode/common/test_link.py | 6 +- .../output/simulation/mode/common/test_set.py | 6 +- .../repository/filesystem/test_bucket_node.py | 2 +- .../areas/test_st_storage_management.py | 3 - .../business/areas/test_thermal_management.py | 1 - tests/study/business/conftest.py | 1 - .../study/business/test_allocation_manager.py | 5 -- .../test_binding_constraint_management.py | 14 ++-- .../business/test_correlation_manager.py | 5 -- tests/study/business/test_district_manager.py | 12 +-- .../variantstudy/test_snapshot_generator.py | 3 +- tests/study/test_model.py | 1 + tests/study/test_repository.py | 25 +++--- tests/variantstudy/test_command_factory.py | 1 - 93 files changed, 225 insertions(+), 369 deletions(-) create mode 100644 docs/developer-guide/0-developer-tools.md rename docs/developer-guide/{2-add-new-antares-version.md => 1-add-new-antares-version.md} (100%) rename docs/developer-guide/{5-roadmap.md => 2-roadmap.md} (100%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 30db6c0d4f..890f635069 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,16 +18,10 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements-dev.txt - - uses: isort/isort-action@v1.1.1 - with: - sort-paths: antarest, tests - requirementsFiles: "requirements-dev.txt" - - name: Check with black - uses: psf/black@stable - with: - # Version of Black should match the versions set in `requirements-dev.txt` - version: "~=25.1.0" - options: --check --diff + - name: Check format (ruff) + run: | + ruff check antarest/ tests/ + ruff format --check antarest/ tests/ - name: Check Typing (mypy) #continue-on-error: true run: | diff --git a/antarest/__init__.py b/antarest/__init__.py index 9159daa2bc..d422b1ddfb 100644 --- a/antarest/__init__.py +++ b/antarest/__init__.py @@ -15,6 +15,7 @@ This module contains the project metadata. """ + from pathlib import Path # Standard project metadata diff --git a/antarest/core/filesystem_blueprint.py b/antarest/core/filesystem_blueprint.py index 13cc54ef9c..7d6cfcd31c 100644 --- a/antarest/core/filesystem_blueprint.py +++ b/antarest/core/filesystem_blueprint.py @@ -13,6 +13,7 @@ """ Filesystem Blueprint """ + import asyncio import datetime import os diff --git a/antarest/core/persistence.py b/antarest/core/persistence.py index 4af73a064a..3df2f57e17 100644 --- a/antarest/core/persistence.py +++ b/antarest/core/persistence.py @@ -15,11 +15,11 @@ from io import StringIO from pathlib import Path +from sqlalchemy.orm import declarative_base # type: ignore + from alembic import command from alembic.config import Config from alembic.util import CommandError -from sqlalchemy.orm import declarative_base # type: ignore - from antarest.core.utils.utils import get_local_path logger = logging.getLogger(__name__) diff --git a/antarest/core/serde/__init__.py b/antarest/core/serde/__init__.py index 7d54736159..b82c12ef60 100644 --- a/antarest/core/serde/__init__.py +++ b/antarest/core/serde/__init__.py @@ -14,7 +14,6 @@ This modules hosts technical components related to serializing and deserializing, for various formats: INI, JSON, ... """ -import typing as t import pydantic diff --git a/antarest/core/utils/fastapi_sqlalchemy/middleware.py b/antarest/core/utils/fastapi_sqlalchemy/middleware.py index db18bc3efc..68f959e705 100644 --- a/antarest/core/utils/fastapi_sqlalchemy/middleware.py +++ b/antarest/core/utils/fastapi_sqlalchemy/middleware.py @@ -1,7 +1,7 @@ from contextvars import ContextVar, Token from typing import Any, Dict, Optional, Type, Union -from sqlalchemy import create_engine, event # type: ignore +from sqlalchemy import create_engine # type: ignore from sqlalchemy.engine import Engine # type: ignore from sqlalchemy.engine.url import URL # type: ignore from sqlalchemy.event import listen # type: ignore diff --git a/antarest/core/version_info.py b/antarest/core/version_info.py index 724e85f697..7fdfe17623 100644 --- a/antarest/core/version_info.py +++ b/antarest/core/version_info.py @@ -13,6 +13,7 @@ """ Python module that is dedicated to printing application version and dependencies information """ + import subprocess import sys from pathlib import Path diff --git a/antarest/dbmodel.py b/antarest/dbmodel.py index f2bcb418be..966936a764 100644 --- a/antarest/dbmodel.py +++ b/antarest/dbmodel.py @@ -10,31 +10,7 @@ # # This file is part of the Antares project. -# noinspection PyUnresolvedReferences -from antarest.core.configdata import model as configdatamodel - -# noinspection PyUnresolvedReferences -from antarest.core.filetransfer import model as filetransfermodel - # noinspection PyUnresolvedReferences from antarest.core.persistence import Base as PersistenceBase -# noinspection PyUnresolvedReferences -from antarest.core.tasks import model as tasksmodel - -# noinspection PyUnresolvedReferences -from antarest.launcher import model as launchermodel - -# noinspection PyUnresolvedReferences -from antarest.login import model as loginmodel - -# noinspection PyUnresolvedReferences -from antarest.matrixstore import model as matrixstoremodel - -# noinspection PyUnresolvedReferences -from antarest.study import model as studymodel - -# noinspection PyUnresolvedReferences -from antarest.study.storage.variantstudy.model import dbmodel as variantmodel - Base = PersistenceBase diff --git a/antarest/eventbus/web.py b/antarest/eventbus/web.py index 3decb495cd..06466b97bc 100644 --- a/antarest/eventbus/web.py +++ b/antarest/eventbus/web.py @@ -12,7 +12,6 @@ import dataclasses import logging -import pathlib from enum import StrEnum from http import HTTPStatus from typing import List, Optional diff --git a/antarest/launcher/model.py b/antarest/launcher/model.py index 4aea83018c..d62cdee8e5 100644 --- a/antarest/launcher/model.py +++ b/antarest/launcher/model.py @@ -165,12 +165,7 @@ def __str__(self) -> str: @override def __repr__(self) -> str: - return ( - f"" - ) + return f"" class JobResult(Base): # type: ignore diff --git a/antarest/launcher/repository.py b/antarest/launcher/repository.py index d87d11e858..8aeb6fa8ef 100644 --- a/antarest/launcher/repository.py +++ b/antarest/launcher/repository.py @@ -54,7 +54,7 @@ def get_all(self, filter_orphan: bool = False, latest: Optional[int] = None) -> return job_results def get_running(self) -> List[JobResult]: - query = db.session.query(JobResult).where(JobResult.completion_date == None) + query = db.session.query(JobResult).where(JobResult.completion_date == None) # noqa: E711 job_results: List[JobResult] = query.all() return job_results diff --git a/antarest/main.py b/antarest/main.py index 3d2bf6ed83..35ffdc02ec 100644 --- a/antarest/main.py +++ b/antarest/main.py @@ -313,10 +313,7 @@ def home(request: Request) -> Any: LOGGING_CONFIG["formatters"]["default"]["fmt"] = "[%(asctime)s] [%(process)s] %(levelprefix)s %(message)s" # noinspection SpellCheckingInspection LOGGING_CONFIG["formatters"]["access"]["fmt"] = ( - "[%(asctime)s] [%(process)s] [%(name)s]" - " %(levelprefix)s" - ' %(client_addr)s - "%(request_line)s"' - " %(status_code)s" + '[%(asctime)s] [%(process)s] [%(name)s] %(levelprefix)s %(client_addr)s - "%(request_line)s" %(status_code)s' ) diff --git a/antarest/service_creator.py b/antarest/service_creator.py index 44670ffcd2..686b1376f8 100644 --- a/antarest/service_creator.py +++ b/antarest/service_creator.py @@ -16,9 +16,6 @@ from typing import Any, Dict, Mapping, Optional, Tuple import redis -from ratelimit import RateLimitMiddleware # type: ignore -from ratelimit.backends.redis import RedisBackend # type: ignore -from ratelimit.backends.simple import MemoryBackend # type: ignore from sqlalchemy import create_engine # type: ignore from sqlalchemy.engine.base import Engine # type: ignore from sqlalchemy.pool import NullPool # type: ignore diff --git a/antarest/study/business/area_management.py b/antarest/study/business/area_management.py index 5a3f45edcc..b514a91c14 100644 --- a/antarest/study/business/area_management.py +++ b/antarest/study/business/area_management.py @@ -488,7 +488,6 @@ def update_area_metadata( ) def update_area_ui(self, study: StudyInterface, area_id: str, area_ui: UpdateAreaUi, layer: str) -> None: - command = UpdateAreaUI( area_id=area_id, area_ui=area_ui, diff --git a/antarest/study/business/areas/renewable_management.py b/antarest/study/business/areas/renewable_management.py index af0e542564..16b83a7a82 100644 --- a/antarest/study/business/areas/renewable_management.py +++ b/antarest/study/business/areas/renewable_management.py @@ -28,7 +28,6 @@ create_renewable_config, create_renewable_properties, ) -from antarest.study.storage.storage_service import StudyStorageService from antarest.study.storage.variantstudy.model.command.create_renewables_cluster import CreateRenewablesCluster from antarest.study.storage.variantstudy.model.command.remove_renewables_cluster import RemoveRenewablesCluster from antarest.study.storage.variantstudy.model.command.replace_matrix import ReplaceMatrix diff --git a/antarest/study/business/binding_constraint_management.py b/antarest/study/business/binding_constraint_management.py index c208257561..ca2a5d8c2a 100644 --- a/antarest/study/business/binding_constraint_management.py +++ b/antarest/study/business/binding_constraint_management.py @@ -377,7 +377,7 @@ def _get_references_by_widths( ) for matrix_name in matrices_name: matrix_id = matrix_name.format(bc_id=bc.id) - logger.info(f"⏲ Validating BC '{bc.id}': {matrix_id=} [{_index+1}/{_total}]") + logger.info(f"⏲ Validating BC '{bc.id}': {matrix_id=} [{_index + 1}/{_total}]") obj = file_study.tree.get(url=["input", "bindingconstraints", matrix_id]) matrix = np.array(obj["data"], dtype=float) # We ignore empty matrices as there are default matrices for the simulator. @@ -904,8 +904,9 @@ def update_binding_constraint( updated_matrices = [term for term in [m.value for m in TermMatrices] if getattr(data, term)] if updated_matrices: time_step = data.time_step or existing_constraint.time_step + assert time_step is not None command.validates_and_fills_matrices( - time_step=time_step, specific_matrices=updated_matrices, version=study.version, create=False # type: ignore + time_step=time_step, specific_matrices=updated_matrices, version=study.version, create=False ) study.add_commands([command]) diff --git a/antarest/study/business/correlation_management.py b/antarest/study/business/correlation_management.py index 489073d783..c9975ec8ed 100644 --- a/antarest/study/business/correlation_management.py +++ b/antarest/study/business/correlation_management.py @@ -14,6 +14,7 @@ Management of spatial correlations between the different generators. The generators are of the same category and can be hydraulic, wind, load or solar. """ + import collections from typing import Dict, List, Sequence, Union diff --git a/antarest/study/business/scenario_builder_management.py b/antarest/study/business/scenario_builder_management.py index 1adfaaa58b..8c9efdd912 100644 --- a/antarest/study/business/scenario_builder_management.py +++ b/antarest/study/business/scenario_builder_management.py @@ -192,7 +192,6 @@ def get_config(self, study: StudyInterface) -> Rulesets: return rulesets def update_config(self, study: StudyInterface, rulesets: Rulesets) -> None: - sections: _Sections = {} for ruleset_name, ruleset in rulesets.items(): section = sections[ruleset_name] = {} diff --git a/antarest/study/business/study_interface.py b/antarest/study/business/study_interface.py index b441598efc..ccaec0db4f 100644 --- a/antarest/study/business/study_interface.py +++ b/antarest/study/business/study_interface.py @@ -10,7 +10,6 @@ # # This file is part of the Antares project. from abc import ABC, abstractmethod -from pathlib import Path from typing import Sequence from antares.study.version import StudyVersion diff --git a/antarest/study/business/thematic_trimming_field_infos.py b/antarest/study/business/thematic_trimming_field_infos.py index 8c8ac6d081..ee920473f3 100644 --- a/antarest/study/business/thematic_trimming_field_infos.py +++ b/antarest/study/business/thematic_trimming_field_infos.py @@ -136,8 +136,8 @@ class ThematicTrimmingFormFields(FormFieldsBaseModel): _SHORT_TERM_STORAGES = "Short-Term Storages" _SHORT_TERM_STORAGES_GROUP = "Short-Term Storages - Group" +# fmt: off FIELDS_INFO: Mapping[str, Mapping[str, Any]] = { - # fmt: off "ov_cost": {"topic": _GENERAL, "path": "OV. COST", "default_value": True}, "op_cost": {"topic": _GENERAL, "path": "OP. COST", "default_value": True}, "mrg_price": {"topic": _GENERAL, "path": "MRG. PRICE", "default_value": True}, @@ -237,8 +237,8 @@ class ThematicTrimmingFormFields(FormFieldsBaseModel): "other5_injection": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other5_injection", "default_value": True, "start_version": STUDY_VERSION_8_6}, "other5_withdrawal": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other5_withdrawal", "default_value": True, "start_version": STUDY_VERSION_8_6}, "other5_level": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other5_level", "default_value": True, "start_version": STUDY_VERSION_8_6}, - # fmt: on } +# fmt: on def get_fields_info(study_version: StudyVersion) -> Mapping[str, Mapping[str, Any]]: diff --git a/antarest/study/model.py b/antarest/study/model.py index 06bc2bb94d..3f850110be 100644 --- a/antarest/study/model.py +++ b/antarest/study/model.py @@ -30,8 +30,7 @@ PrimaryKeyConstraint, String, ) -from sqlalchemy.orm import relationship # type: ignore -from sqlalchemy.orm import validates +from sqlalchemy.orm import relationship, validates # type: ignore from typing_extensions import override from antarest.core.exceptions import ShouldNotHappenException diff --git a/antarest/study/service.py b/antarest/study/service.py index 4fee65237c..69344bb171 100644 --- a/antarest/study/service.py +++ b/antarest/study/service.py @@ -20,7 +20,7 @@ import time from datetime import datetime, timedelta from pathlib import Path, PurePosixPath -from typing import Any, BinaryIO, Callable, Dict, List, MutableSequence, Optional, Sequence, Tuple, Type, cast +from typing import Any, BinaryIO, Callable, Dict, List, Optional, Sequence, Tuple, Type, cast from uuid import uuid4 import numpy as np diff --git a/antarest/study/storage/df_download.py b/antarest/study/storage/df_download.py index bd80762bb0..49e808dc13 100644 --- a/antarest/study/storage/df_download.py +++ b/antarest/study/storage/df_download.py @@ -23,6 +23,12 @@ from antarest.core.jwt import JWTUser from antarest.study.business.enum_ignore_case import EnumIgnoreCase +try: + import tables # type: ignore # noqa: F401 + import xlsxwriter # type: ignore # noqa: F401 +except ImportError: + raise ImportError("The 'xlsxwriter' and 'tables' packages are required") from None + class TableExportFormat(EnumIgnoreCase): """Export format for tables.""" diff --git a/antarest/study/storage/rawstudy/model/filesystem/config/field_validators.py b/antarest/study/storage/rawstudy/model/filesystem/config/field_validators.py index cefd32439e..776ed4a016 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/config/field_validators.py +++ b/antarest/study/storage/rawstudy/model/filesystem/config/field_validators.py @@ -9,7 +9,6 @@ # SPDX-License-Identifier: MPL-2.0 # # This file is part of the Antares project. -import re from typing import Annotated, Any, List, Mapping, MutableMapping from pydantic import BeforeValidator, Field diff --git a/antarest/study/storage/rawstudy/model/filesystem/config/st_storage.py b/antarest/study/storage/rawstudy/model/filesystem/config/st_storage.py index 6d4635b4ac..0c9a13f760 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/config/st_storage.py +++ b/antarest/study/storage/rawstudy/model/filesystem/config/st_storage.py @@ -10,7 +10,7 @@ # # This file is part of the Antares project. -from typing import Any, Dict, Type, Union +from typing import Any, Dict, Type from antares.study.version import StudyVersion from pydantic import Field diff --git a/antarest/study/storage/rawstudy/model/filesystem/config/thermal.py b/antarest/study/storage/rawstudy/model/filesystem/config/thermal.py index 3e4be3ac41..42f74e2e2c 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/config/thermal.py +++ b/antarest/study/storage/rawstudy/model/filesystem/config/thermal.py @@ -10,7 +10,7 @@ # # This file is part of the Antares project. -from typing import Any, Dict, Optional, Type, Union, cast +from typing import Any, Dict, Optional, Type, cast from antares.study.version import StudyVersion from pydantic import Field diff --git a/antarest/study/storage/rawstudy/model/filesystem/matrix/matrix.py b/antarest/study/storage/rawstudy/model/filesystem/matrix/matrix.py index 7ea1fda086..1af1d6b554 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/matrix/matrix.py +++ b/antarest/study/storage/rawstudy/model/filesystem/matrix/matrix.py @@ -18,7 +18,6 @@ import numpy as np import pandas as pd -from numpy import typing as npt from typing_extensions import override from antarest.core.model import JSON diff --git a/antarest/study/storage/rawstudy/model/filesystem/root/input/areas/list.py b/antarest/study/storage/rawstudy/model/filesystem/root/input/areas/list.py index 4ed88960a6..39a306cd10 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/root/input/areas/list.py +++ b/antarest/study/storage/rawstudy/model/filesystem/root/input/areas/list.py @@ -57,7 +57,7 @@ def get( lines = extract_lines_from_archive(self.config.archive_path, AREAS_LIST_RELATIVE_PATH) else: lines = self.config.path.read_text().split("\n") - return [l.strip() for l in lines if l.strip()] + return [line.strip() for line in lines if line.strip()] @override def save(self, data: List[str], url: Optional[List[str]] = None) -> None: diff --git a/antarest/study/storage/rawstudy/model/filesystem/root/settings/scenariobuilder.py b/antarest/study/storage/rawstudy/model/filesystem/root/settings/scenariobuilder.py index d3288e9f6d..353f79ce33 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/root/settings/scenariobuilder.py +++ b/antarest/study/storage/rawstudy/model/filesystem/root/settings/scenariobuilder.py @@ -106,7 +106,7 @@ def _populate_thermal_rules(self, rules: _Rules) -> None: def _populate_renewable_rules(self, rules: _Rules) -> None: for area_id in self.config.areas: - for cl_id in (re.lower() for re in self.config.get_renewable_ids(area_id)): + for cl_id in (renew.lower() for renew in self.config.get_renewable_ids(area_id)): rules[f"r,{area_id},0,{cl_id}"] = _TSNumber def _populate_binding_constraints_rules(self, rules: _Rules) -> None: diff --git a/antarest/study/storage/variantstudy/business/matrix_constants/__init__.py b/antarest/study/storage/variantstudy/business/matrix_constants/__init__.py index 3b4bc42056..7a2624b361 100644 --- a/antarest/study/storage/variantstudy/business/matrix_constants/__init__.py +++ b/antarest/study/storage/variantstudy/business/matrix_constants/__init__.py @@ -11,3 +11,5 @@ # This file is part of the Antares project. from . import binding_constraint, hydro, link, prepro, st_storage, thermals + +__all__ = ("binding_constraint", "hydro", "link", "prepro", "st_storage", "thermals") diff --git a/antarest/study/storage/variantstudy/business/matrix_constants/hydro/__init__.py b/antarest/study/storage/variantstudy/business/matrix_constants/hydro/__init__.py index 608a308295..d442952bb5 100644 --- a/antarest/study/storage/variantstudy/business/matrix_constants/hydro/__init__.py +++ b/antarest/study/storage/variantstudy/business/matrix_constants/hydro/__init__.py @@ -11,3 +11,5 @@ # This file is part of the Antares project. from . import v6, v7 + +__all__ = ("v6", "v7") diff --git a/antarest/study/storage/variantstudy/business/matrix_constants/link/__init__.py b/antarest/study/storage/variantstudy/business/matrix_constants/link/__init__.py index cb756f7274..c167de4a4d 100644 --- a/antarest/study/storage/variantstudy/business/matrix_constants/link/__init__.py +++ b/antarest/study/storage/variantstudy/business/matrix_constants/link/__init__.py @@ -11,3 +11,5 @@ # This file is part of the Antares project. from . import v7, v8 + +__all__ = ("v7", "v8") diff --git a/antarest/study/storage/variantstudy/business/matrix_constants/st_storage/__init__.py b/antarest/study/storage/variantstudy/business/matrix_constants/st_storage/__init__.py index 8998175b7d..99400a3f0e 100644 --- a/antarest/study/storage/variantstudy/business/matrix_constants/st_storage/__init__.py +++ b/antarest/study/storage/variantstudy/business/matrix_constants/st_storage/__init__.py @@ -10,4 +10,4 @@ # # This file is part of the Antares project. -from . import series +from . import series # noqa: F401 diff --git a/antarest/study/storage/variantstudy/business/matrix_constants/thermals/__init__.py b/antarest/study/storage/variantstudy/business/matrix_constants/thermals/__init__.py index c4a504b5e7..9f446875bf 100644 --- a/antarest/study/storage/variantstudy/business/matrix_constants/thermals/__init__.py +++ b/antarest/study/storage/variantstudy/business/matrix_constants/thermals/__init__.py @@ -10,4 +10,4 @@ # # This file is part of the Antares project. -from . import prepro +from . import prepro # noqa: F401 diff --git a/antarest/study/storage/variantstudy/command_factory.py b/antarest/study/storage/variantstudy/command_factory.py index 837f3523a0..91a9c9837b 100644 --- a/antarest/study/storage/variantstudy/command_factory.py +++ b/antarest/study/storage/variantstudy/command_factory.py @@ -18,7 +18,6 @@ from antarest.core.model import JSON from antarest.matrixstore.service import ISimpleMatrixService -from antarest.study.storage.patch_service import PatchService from antarest.study.storage.variantstudy.business.matrix_constants_generator import GeneratorMatrixConstants from antarest.study.storage.variantstudy.model.command.common import CommandName from antarest.study.storage.variantstudy.model.command.create_area import CreateArea diff --git a/antarest/study/storage/variantstudy/model/command/create_area.py b/antarest/study/storage/variantstudy/model/command/create_area.py index 5b1de89a7c..e657fdc276 100644 --- a/antarest/study/storage/variantstudy/model/command/create_area.py +++ b/antarest/study/storage/variantstudy/model/command/create_area.py @@ -253,12 +253,12 @@ def _apply(self, study_data: FileStudy, listener: Optional[ICommandListener] = N hydro_config.setdefault("leeway up", {})[area_id] = 1 hydro_config.setdefault("pumping efficiency", {})[area_id] = 1 - new_area_data["input"]["hydro"]["common"]["capacity"][ - f"creditmodulations_{area_id}" - ] = self.command_context.generator_matrix_constants.get_hydro_credit_modulations() - new_area_data["input"]["hydro"]["common"]["capacity"][ - f"inflowPattern_{area_id}" - ] = self.command_context.generator_matrix_constants.get_hydro_inflow_pattern() + new_area_data["input"]["hydro"]["common"]["capacity"][f"creditmodulations_{area_id}"] = ( + self.command_context.generator_matrix_constants.get_hydro_credit_modulations() + ) + new_area_data["input"]["hydro"]["common"]["capacity"][f"inflowPattern_{area_id}"] = ( + self.command_context.generator_matrix_constants.get_hydro_inflow_pattern() + ) new_area_data["input"]["hydro"]["common"]["capacity"][f"waterValues_{area_id}"] = null_matrix has_renewables = version >= STUDY_VERSION_8_1 and EnrModelling(config.enr_modelling) == EnrModelling.CLUSTERS diff --git a/antarest/study/storage/variantstudy/model/command/create_cluster.py b/antarest/study/storage/variantstudy/model/command/create_cluster.py index 032c10e34b..bb36156fd4 100644 --- a/antarest/study/storage/variantstudy/model/command/create_cluster.py +++ b/antarest/study/storage/variantstudy/model/command/create_cluster.py @@ -10,7 +10,7 @@ # # This file is part of the Antares project. import typing as t -from typing import Any, ClassVar, Dict, Final, List, Optional, Tuple +from typing import Any, Dict, Final, List, Optional, Tuple from pydantic import Field, model_validator from pydantic_core.core_schema import ValidationInfo diff --git a/antarest/study/storage/variantstudy/model/command/update_area_ui.py b/antarest/study/storage/variantstudy/model/command/update_area_ui.py index d395e3dea3..77be7f9bf3 100644 --- a/antarest/study/storage/variantstudy/model/command/update_area_ui.py +++ b/antarest/study/storage/variantstudy/model/command/update_area_ui.py @@ -18,7 +18,7 @@ from antarest.study.storage.rawstudy.model.filesystem.config.model import FileStudyTreeConfig from antarest.study.storage.rawstudy.model.filesystem.factory import FileStudy from antarest.study.storage.variantstudy.model.command.common import CommandName, CommandOutput -from antarest.study.storage.variantstudy.model.command.icommand import MATCH_SIGNATURE_SEPARATOR, ICommand +from antarest.study.storage.variantstudy.model.command.icommand import ICommand from antarest.study.storage.variantstudy.model.command_listener.command_listener import ICommandListener from antarest.study.storage.variantstudy.model.model import CommandDTO diff --git a/antarest/study/storage/variantstudy/model/command_context.py b/antarest/study/storage/variantstudy/model/command_context.py index 34acd7b6d2..80fe6696cf 100644 --- a/antarest/study/storage/variantstudy/model/command_context.py +++ b/antarest/study/storage/variantstudy/model/command_context.py @@ -12,7 +12,6 @@ from antarest.core.serde import AntaresBaseModel from antarest.matrixstore.service import ISimpleMatrixService -from antarest.study.storage.patch_service import PatchService from antarest.study.storage.variantstudy.business.matrix_constants_generator import GeneratorMatrixConstants diff --git a/antarest/study/storage/variantstudy/model/interfaces.py b/antarest/study/storage/variantstudy/model/interfaces.py index 2eb84be257..018db73b2e 100644 --- a/antarest/study/storage/variantstudy/model/interfaces.py +++ b/antarest/study/storage/variantstudy/model/interfaces.py @@ -12,16 +12,20 @@ import abc from abc import abstractmethod -from typing import List, Optional, Tuple +from typing import TYPE_CHECKING, List, Optional, Tuple from antarest.core.model import JSON from antarest.study.storage.rawstudy.model.filesystem.factory import FileStudy from antarest.study.storage.rawstudy.model.filesystem.root.filestudytree import FileStudyTree +if TYPE_CHECKING: + # avoid circular import + from antarest.study.storage.variantstudy.model.command.icommand import ICommand + class ICommandExtractor(abc.ABC): @abstractmethod - def extract_area(self, study: FileStudy, area_id: str) -> Tuple[List["ICommand"], List["ICommand"]]: # type: ignore + def extract_area(self, study: FileStudy, area_id: str) -> Tuple[List["ICommand"], List["ICommand"]]: raise NotImplementedError() @abstractmethod @@ -31,29 +35,27 @@ def extract_link( area1: str, area2: str, links_data: Optional[JSON] = None, - ) -> List["ICommand"]: # type: ignore + ) -> List["ICommand"]: raise NotImplementedError() @abstractmethod - def extract_cluster(self, study: FileStudy, area_id: str, thermal_id: str) -> List["ICommand"]: # type: ignore + def extract_cluster(self, study: FileStudy, area_id: str, thermal_id: str) -> List["ICommand"]: raise NotImplementedError() @abstractmethod - def extract_renewables_cluster( - self, study: FileStudy, area_id: str, thermal_id: str - ) -> List["ICommand"]: # type: ignore + def extract_renewables_cluster(self, study: FileStudy, area_id: str, thermal_id: str) -> List["ICommand"]: raise NotImplementedError() @abstractmethod - def extract_hydro(self, study: FileStudy, area_id: str) -> List["ICommand"]: # type: ignore + def extract_hydro(self, study: FileStudy, area_id: str) -> List["ICommand"]: raise NotImplementedError() @abstractmethod - def extract_district(self, study: FileStudy, district_id: str) -> List["ICommand"]: # type: ignore + def extract_district(self, study: FileStudy, district_id: str) -> List["ICommand"]: raise NotImplementedError() @abstractmethod - def extract_comments(self, study: FileStudy) -> List["ICommand"]: # type: ignore + def extract_comments(self, study: FileStudy) -> List["ICommand"]: raise NotImplementedError() @abstractmethod @@ -62,7 +64,7 @@ def extract_binding_constraint( study: FileStudy, binding_id: str, bindings_data: Optional[JSON] = None, - ) -> List["ICommand"]: # type: ignore + ) -> List["ICommand"]: raise NotImplementedError() @abstractmethod @@ -70,7 +72,7 @@ def generate_update_config( self, study_tree: FileStudyTree, url: List[str], - ) -> "ICommand": # type: ignore + ) -> "ICommand": raise NotImplementedError() @abstractmethod @@ -78,14 +80,14 @@ def generate_update_raw_file( self, study_tree: FileStudyTree, url: List[str], - ) -> "ICommand": # type: ignore + ) -> "ICommand": raise NotImplementedError() @abstractmethod def generate_update_comments( self, study_tree: FileStudyTree, - ) -> "ICommand": # type: ignore + ) -> "ICommand": raise NotImplementedError() @abstractmethod @@ -94,5 +96,5 @@ def generate_replace_matrix( study_tree: FileStudyTree, url: List[str], default_value: Optional[str] = None, - ) -> "ICommand": # type: ignore + ) -> "ICommand": raise NotImplementedError() diff --git a/antarest/study/storage/variantstudy/snapshot_generator.py b/antarest/study/storage/variantstudy/snapshot_generator.py index 543f5bae5d..a9fcd15234 100644 --- a/antarest/study/storage/variantstudy/snapshot_generator.py +++ b/antarest/study/storage/variantstudy/snapshot_generator.py @@ -13,6 +13,7 @@ """ This module dedicated to variant snapshot generation. """ + import datetime import logging import shutil diff --git a/antarest/study/storage/variantstudy/variant_command_generator.py b/antarest/study/storage/variantstudy/variant_command_generator.py index 87820681aa..22cb121efc 100644 --- a/antarest/study/storage/variantstudy/variant_command_generator.py +++ b/antarest/study/storage/variantstudy/variant_command_generator.py @@ -14,7 +14,7 @@ import shutil import uuid from pathlib import Path -from typing import Callable, Dict, List, Optional, Set, Tuple, Union, cast +from typing import Callable, List, Optional, Tuple, Union, cast from antarest.core.utils.utils import StopWatch from antarest.study.storage.rawstudy.model.filesystem.config.model import FileStudyTreeConfig diff --git a/antarest/study/storage/variantstudy/variant_study_service.py b/antarest/study/storage/variantstudy/variant_study_service.py index 75b9fc3cc8..a4257379ba 100644 --- a/antarest/study/storage/variantstudy/variant_study_service.py +++ b/antarest/study/storage/variantstudy/variant_study_service.py @@ -22,7 +22,6 @@ from uuid import uuid4 import humanize -from antares.study.version import StudyVersion from fastapi import HTTPException from filelock import FileLock from typing_extensions import override @@ -42,13 +41,13 @@ ) from antarest.core.filetransfer.model import FileDownloadTaskDTO from antarest.core.interfaces.cache import ICache -from antarest.core.interfaces.eventbus import Event, EventChannelDirectory, EventType, IEventBus +from antarest.core.interfaces.eventbus import Event, EventType, IEventBus from antarest.core.jwt import DEFAULT_ADMIN_USER from antarest.core.model import JSON, PermissionInfo, PublicMode, StudyPermissionType from antarest.core.requests import RequestParameters, UserHasNotPermissionError from antarest.core.serde.json import to_json_string from antarest.core.tasks.model import CustomTaskEventMessages, TaskDTO, TaskResult, TaskType -from antarest.core.tasks.service import DEFAULT_AWAIT_MAX_TIMEOUT, ITaskNotifier, ITaskService, NoopNotifier +from antarest.core.tasks.service import DEFAULT_AWAIT_MAX_TIMEOUT, ITaskNotifier, ITaskService from antarest.core.utils.fastapi_sqlalchemy import db from antarest.core.utils.utils import assert_this, suppress_exception from antarest.login.model import Identity @@ -70,7 +69,6 @@ from antarest.study.storage.variantstudy.model.model import ( CommandDTO, CommandDTOAPI, - CommandResultDTO, GenerationResultInfoDTO, VariantTreeDTO, ) @@ -612,8 +610,7 @@ def create_variant_study(self, uuid: str, name: str, params: RequestParameters) if not is_managed(study): raise VariantStudyParentNotValid( - f"The study {study.name} is not managed. Cannot create a variant from it." - f" It must be imported first." + f"The study {study.name} is not managed. Cannot create a variant from it. It must be imported first." ) assert_permission(params.user, study, StudyPermissionType.READ) diff --git a/antarest/study/web/raw_studies_blueprint.py b/antarest/study/web/raw_studies_blueprint.py index 36201ab5ce..b7c4b5fc73 100644 --- a/antarest/study/web/raw_studies_blueprint.py +++ b/antarest/study/web/raw_studies_blueprint.py @@ -41,12 +41,6 @@ from antarest.study.storage.rawstudy.model.filesystem.matrix.matrix import MatrixFrequency from antarest.study.storage.variantstudy.model.command.create_user_resource import ResourceType -try: - import tables # type: ignore - import xlsxwriter # type: ignore -except ImportError: - raise ImportError("The 'xlsxwriter' and 'tables' packages are required") from None - logger = logging.getLogger(__name__) diff --git a/antarest/study/web/study_data_blueprint.py b/antarest/study/web/study_data_blueprint.py index 671b258bdb..3d36fbbb1c 100644 --- a/antarest/study/web/study_data_blueprint.py +++ b/antarest/study/web/study_data_blueprint.py @@ -62,7 +62,6 @@ from antarest.study.business.correlation_management import ( AreaCoefficientItem, CorrelationFormFields, - CorrelationManager, CorrelationMatrix, ) from antarest.study.business.district_manager import DistrictCreationDTO, DistrictInfoDTO, DistrictUpdateDTO diff --git a/antarest/study/web/variant_blueprint.py b/antarest/study/web/variant_blueprint.py index c4056d7e1a..64a121b8d0 100644 --- a/antarest/study/web/variant_blueprint.py +++ b/antarest/study/web/variant_blueprint.py @@ -438,7 +438,6 @@ def create_from_variant( f"Creating new raw study {name} from variant study {uuid}", extra={"user": current_user.id}, ) - params = RequestParameters(user=current_user) raise NotImplementedError() @bp.put( diff --git a/docs/developer-guide/0-developer-tools.md b/docs/developer-guide/0-developer-tools.md new file mode 100644 index 0000000000..c6e3719dcd --- /dev/null +++ b/docs/developer-guide/0-developer-tools.md @@ -0,0 +1,16 @@ +### install dev requirements + +Install dev requirements with `pip install -r requirements-dev.txt` + +### linting and formatting + +To reformat your code, use this command line: `ruff check antarest/ tests/ --fix && ruff format antarest/ tests/` + +### typechecking + +To typecheck your code, use this command line: `mypy` (`mypy --install-types --non-interactive` inside the CI) + +### testing + +Integration tests can take quite a while to run on your local environment. +To speed up the process, you may launch pytest with these given args `--basetemp=/path_to_your_projects/AntaREST/target -n logical --dist=worksteal` diff --git a/docs/developer-guide/2-add-new-antares-version.md b/docs/developer-guide/1-add-new-antares-version.md similarity index 100% rename from docs/developer-guide/2-add-new-antares-version.md rename to docs/developer-guide/1-add-new-antares-version.md diff --git a/docs/developer-guide/5-roadmap.md b/docs/developer-guide/2-roadmap.md similarity index 100% rename from docs/developer-guide/5-roadmap.md rename to docs/developer-guide/2-roadmap.md diff --git a/docs/developer-guide/architecture/0-introduction.md b/docs/developer-guide/architecture/0-introduction.md index 00805f01a5..29ba29c412 100644 --- a/docs/developer-guide/architecture/0-introduction.md +++ b/docs/developer-guide/architecture/0-introduction.md @@ -32,6 +32,6 @@ Each package/module is structured in the following way : ## Specific topics - [Database management](./1-database.md) -- [Adding a new antares simulator version support](./2-add-new-antares-version.md) +- [Adding a new antares simulator version support](./1-add-new-antares-version.md) diff --git a/mkdocs.yml b/mkdocs.yml index 02bd594987..bad3181a9b 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -75,9 +75,9 @@ nav: - 'Deployment': 'developer-guide/install/2-DEPLOY.md' - 'Architecture': 'developer-guide/architecture/0-introduction.md' - 'Database management': 'developer-guide/architecture/1-database.md' - - 'Add a new study version': 'developer-guide/2-add-new-antares-version.md' + - 'Add a new study version': 'developer-guide/1-add-new-antares-version.md' - 'Changelog': 'CHANGELOG.md' - - 'Roadmap': 'developer-guide/5-roadmap.md' + - 'Roadmap': 'developer-guide/2-roadmap.md' - 'External links' : - 'Antares ecosystem': 'https://antares-doc.readthedocs.io' - 'Antares website' : 'https://antares-simulator.org/' diff --git a/pyproject.toml b/pyproject.toml index a11ffde3d3..1cea097386 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,22 +68,12 @@ markers = [ "integration_test" ] - -[tool.black] -target-version = ["py38"] -line-length = 120 -exclude = "(antares-?launcher/*|alembic/*)" - [tool.coverage.run] omit = ["antarest/tools/admin.py", "antarest/fastapi_jwt_auth/*.py"] relative_files = true # avoids absolute path issues in CI -[tool.isort] -profile = "black" -line_length = 120 -src_paths = ["antarest", "tests"] -skip_gitignore = true -extend_skip_glob = [ +[tool.ruff] +exclude = [ "alembic/*", "conf/*", "docs/*", @@ -94,32 +84,6 @@ extend_skip_glob = [ "webapp/*", ] -[tool.ruff] -# Exclude a variety of commonly ignored directories. -exclude = [ - ".bzr", - ".direnv", - ".eggs", - ".git", - ".git-rewrite", - ".hg", - ".mypy_cache", - ".nox", - ".pants.d", - ".pytype", - ".ruff_cache", - ".svn", - ".tox", - ".venv", - "__pypackages__", - "_build", - "buck-out", - "build", - "dist", - "node_modules", - "venv", -] - # Same as Black. line-length = 120 indent-width = 4 @@ -128,18 +92,8 @@ indent-width = 4 target-version = "py311" [tool.ruff.lint] -# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default. -# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or -# McCabe complexity (`C901`) by default. -select = ["E4", "E7", "E9", "F"] -ignore = [] - -# Allow fix for all enabled rules (when `--fix`) is provided. -fixable = ["ALL"] -unfixable = [] - -# Allow unused variables when underscore-prefixed. -dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" +## E4, E7, E9 and F are the default configuration of ruff, "I" is added to handle imports +select = ["E4", "E7", "E9", "F", "I"] [tool.ruff.format] # Like Black, use double quotes for strings. @@ -153,17 +107,3 @@ skip-magic-trailing-comma = false # Like Black, automatically detect the appropriate line ending. line-ending = "auto" - -# Enable auto-formatting of code examples in docstrings. Markdown, -# reStructuredText code/literal blocks and doctests are all supported. -# -# This is currently disabled by default, but it is planned for this -# to be opt-out in the future. -docstring-code-format = true - -# Set the line length limit used when formatting code snippets in -# docstrings. -# -# This only has an effect when the `docstring-code-format` setting is -# enabled. -docstring-code-line-length = "dynamic" diff --git a/requirements-dev.txt b/requirements-dev.txt index f3ec4b5a88..a54224c04d 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,8 +1,6 @@ -r requirements-test.txt -r requirements-desktop.txt -# Version of Black should match the versions set in `.github/workflows/main.yml` -black~=25.1.0 -isort~=6.0.0 +ruff~=0.9.6 mypy~=1.15.0 pyinstaller==6.10.0 pyinstaller-hooks-contrib==2024.8 diff --git a/tests/conftest.py b/tests/conftest.py index dd39f681d0..634bf94b61 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -13,14 +13,13 @@ from pathlib import Path from typing import Callable -# noinspection PyUnresolvedReferences -from tests.conftest_db import * +import pytest -# noinspection PyUnresolvedReferences -from tests.conftest_instances import * +from tests.conftest_db import db_engine_fixture, db_middleware_fixture, db_session_fixture # noqa: F401 +from tests.conftest_instances import admin_user # noqa: F401 # noinspection PyUnresolvedReferences -from tests.conftest_services import * +from tests.conftest_services import * # noqa: F403 HERE = Path(__file__).parent.resolve() PROJECT_DIR = next(iter(p for p in HERE.parents if p.joinpath("antarest").exists())) diff --git a/tests/conftest_db.py b/tests/conftest_db.py index 520decb814..e71a879784 100644 --- a/tests/conftest_db.py +++ b/tests/conftest_db.py @@ -21,8 +21,6 @@ from antarest.core.utils.fastapi_sqlalchemy import DBSessionMiddleware from antarest.dbmodel import Base -__all__ = ("db_engine_fixture", "db_session_fixture", "db_middleware_fixture") - @pytest.fixture(name="db_engine") def db_engine_fixture() -> t.Generator[Engine, None, None]: diff --git a/tests/conftest_instances.py b/tests/conftest_instances.py index bd5057c34f..ae653bc9c5 100644 --- a/tests/conftest_instances.py +++ b/tests/conftest_instances.py @@ -13,15 +13,16 @@ The aim of this module is to contain fixtures for instantiating objects such as users, studies, ... """ + import pytest from antarest.core.jwt import DEFAULT_ADMIN_USER -from antarest.core.utils.fastapi_sqlalchemy import DBSessionMiddleware, db +from antarest.core.utils.fastapi_sqlalchemy import db from antarest.login.model import User @pytest.fixture -def admin_user(db_middleware: DBSessionMiddleware) -> User: +def admin_user() -> User: with db(commit_on_exit=True): user = User(id=DEFAULT_ADMIN_USER.id) db.session.add(user) diff --git a/tests/conftest_services.py b/tests/conftest_services.py index f5890a6d99..0a41c75367 100644 --- a/tests/conftest_services.py +++ b/tests/conftest_services.py @@ -16,6 +16,7 @@ Fixtures in this module are used to set up and provide instances of different classes and services required during testing. """ + import datetime import typing as t import uuid diff --git a/tests/core/test_tasks.py b/tests/core/test_tasks.py index 47b8ea08cd..bf2872f153 100644 --- a/tests/core/test_tasks.py +++ b/tests/core/test_tasks.py @@ -22,7 +22,7 @@ from fastapi import HTTPException from sqlalchemy import create_engine # type: ignore from sqlalchemy.engine.base import Engine # type: ignore -from sqlalchemy.orm import Session, sessionmaker # type: ignore +from sqlalchemy.orm import sessionmaker # type: ignore from antarest.core.config import Config from antarest.core.interfaces.eventbus import DummyEventBusService, EventType, IEventBus diff --git a/tests/db_statement_recorder.py b/tests/db_statement_recorder.py index fc40e7c9da..5259fb3a14 100644 --- a/tests/db_statement_recorder.py +++ b/tests/db_statement_recorder.py @@ -13,6 +13,7 @@ """ Record SQL statements in memory to diagnose the queries performed by the application. """ + import contextlib import types import typing as t diff --git a/tests/integration/raw_studies_blueprint/test_download_matrices.py b/tests/integration/raw_studies_blueprint/test_download_matrices.py index 7198736cbf..431fcdf8cd 100644 --- a/tests/integration/raw_studies_blueprint/test_download_matrices.py +++ b/tests/integration/raw_studies_blueprint/test_download_matrices.py @@ -64,9 +64,9 @@ def upload_matrix(self, internal_study_id: str, matrix_path: str, df: pd.DataFra # noinspection SpellCheckingInspection res = self.client.put( f"/v1/studies/{internal_study_id}/raw", - params={"path": matrix_path, "create_missing": True}, + params={"path": matrix_path}, headers=self.headers, - files={"file": tsv, "create_missing": "true"}, + files={"file": tsv}, ) res.raise_for_status() @@ -113,9 +113,6 @@ def update_general_data(self, internal_study_id: str, **data: t.Any): res.raise_for_status() -from tests.integration.prepare_proxy import PreparerProxy - - @pytest.mark.integration_test class TestDownloadMatrices: """ @@ -132,13 +129,13 @@ def test_download_matrices(self, client: TestClient, user_access_token: str, int preparer = PreparerProxy(client, user_access_token) - study_820_id = preparer.copy_study_and_upgrade(internal_study_id, target_version=820) + study_820_id = preparer.copy_upgrade_study(internal_study_id, target_version=820) # Create Variant variant_id = preparer.create_variant(study_820_id, name="New Variant") # Create a new area to implicitly create normalized matrices - area_id = preparer.create_area(variant_id, name="Mayenne", country="France")["id"] + area_id = preparer.create_area(variant_id, name="Mayenne", country="France") # Change study start_date preparer.update_general_data(variant_id, firstMonth="July") @@ -147,7 +144,7 @@ def test_download_matrices(self, client: TestClient, user_access_token: str, int preparer.generate_snapshot(variant_id) # Prepare a managed study to test specific matrices for version 8.6 - study_860_id = preparer.copy_study_and_upgrade(internal_study_id, target_version=860) + study_860_id = preparer.copy_upgrade_study(internal_study_id, target_version=860) # Import a Min Gen. matrix: shape=(8760, 3), with random integers between 0 and 1000 generator = np.random.default_rng(11) diff --git a/tests/integration/studies_blueprint/test_get_studies.py b/tests/integration/studies_blueprint/test_get_studies.py index e2432464d0..25276550c2 100644 --- a/tests/integration/studies_blueprint/test_get_studies.py +++ b/tests/integration/studies_blueprint/test_get_studies.py @@ -1369,11 +1369,10 @@ def test_get_studies__access_permissions(self, client: TestClient, admin_access_ ########################## # user_1 access + # fmt: off requests_params_expected_studies = [ - # fmt: off ([], {"1", "2", "5", "6", "7", "8", "9", "10", "13", "14", "15", "16", "17", "18", "21", "22", "23", "24", "25", "26", "29", "30", "31", "32", "34"}), - # fmt: on (["1"], {"1", "7", "8", "9", "17", "23", "24", "25"}), (["2"], {"2", "5", "6", "7", "8", "9", "18", "21", "22", "23", "24", "25", "34"}), (["3"], set()), @@ -1385,10 +1384,11 @@ def test_get_studies__access_permissions(self, client: TestClient, admin_access_ {"1", "2", "5", "6", "7", "8", "9", "17", "18", "21", "22", "23", "24", "25", "34"}, ), ] + # fmt: on for request_groups_numbers, expected_studies_numbers in requests_params_expected_studies: request_groups_ids = [groups_ids[f"group_{group_number}"] for group_number in request_groups_numbers] expected_studies = [ - studies_ids_mapping[f"study_{(study_number if int(study_number) <= 9 else 'X'+study_number)}"] + studies_ids_mapping[f"study_{(study_number if int(study_number) <= 9 else 'X' + study_number)}"] for study_number in expected_studies_numbers ] res = client.get( @@ -1415,11 +1415,10 @@ def test_get_studies__access_permissions(self, client: TestClient, admin_access_ # assert list(res.json()) == expected_studies[2:4] # user_2 access + # fmt: off requests_params_expected_studies = [ - # fmt: off ([], {"1", "3", "4", "5", "7", "8", "9", "11", "13", "14", "15", "16", "17", "19", "20", "21", "23", "24", "25", "27", "29", "30", "31", "32", "33"}), - # fmt: on (["1"], {"1", "3", "4", "7", "8", "9", "17", "19", "20", "23", "24", "25", "33"}), (["2"], {"5", "7", "8", "9", "21", "23", "24", "25"}), (["3"], set()), @@ -1431,10 +1430,11 @@ def test_get_studies__access_permissions(self, client: TestClient, admin_access_ {"1", "3", "4", "5", "7", "8", "9", "17", "19", "20", "21", "23", "24", "25", "33"}, ), ] + # fmt: on for request_groups_numbers, expected_studies_numbers in requests_params_expected_studies: request_groups_ids = [groups_ids[f"group_{group_number}"] for group_number in request_groups_numbers] expected_studies = { - studies_ids_mapping[f"study_{(study_number if int(study_number) <= 9 else 'X'+study_number)}"] + studies_ids_mapping[f"study_{(study_number if int(study_number) <= 9 else 'X' + study_number)}"] for study_number in expected_studies_numbers } res = client.get( @@ -1461,7 +1461,7 @@ def test_get_studies__access_permissions(self, client: TestClient, admin_access_ for request_groups_numbers, expected_studies_numbers in requests_params_expected_studies: request_groups_ids = [groups_ids[f"group_{group_number}"] for group_number in request_groups_numbers] expected_studies = { - studies_ids_mapping[f"study_{(study_number if int(study_number) <= 9 else 'X'+study_number)}"] + studies_ids_mapping[f"study_{(study_number if int(study_number) <= 9 else 'X' + study_number)}"] for study_number in expected_studies_numbers } res = client.get( diff --git a/tests/integration/study_data_blueprint/test_binding_constraints.py b/tests/integration/study_data_blueprint/test_binding_constraints.py index beb0036ba4..c1fd0215f1 100644 --- a/tests/integration/study_data_blueprint/test_binding_constraints.py +++ b/tests/integration/study_data_blueprint/test_binding_constraints.py @@ -989,7 +989,7 @@ def test_for_version_870(self, client: TestClient, user_access_token: str, study # Asserts that the deletion worked binding_constraints_list = client.get( f"/v1/studies/{study_id}/raw", - params={"path": f"input/bindingconstraints/bindingconstraints"}, # type: ignore + params={"path": "input/bindingconstraints/bindingconstraints"}, # type: ignore ).json() assert len(binding_constraints_list) == 2 actual_ids = [constraint["id"] for constraint in binding_constraints_list.values()] diff --git a/tests/integration/study_data_blueprint/test_thermal.py b/tests/integration/study_data_blueprint/test_thermal.py index 1c106a8c87..bea905c0d4 100644 --- a/tests/integration/study_data_blueprint/test_thermal.py +++ b/tests/integration/study_data_blueprint/test_thermal.py @@ -39,6 +39,7 @@ * delete a cluster (or several clusters) * validate the consistency of the matrices (and properties) """ + import io import re import typing as t diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index fc52af7a64..10046ead3c 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -75,7 +75,7 @@ def test_main(client: TestClient, admin_access_token: str) -> None: # reject user creation from non admin res = client.post( "/v1/users", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, json={"name": "Fred", "password": "mypass"}, ) assert res.status_code == 403 @@ -83,21 +83,21 @@ def test_main(client: TestClient, admin_access_token: str) -> None: # check study listing res = client.get( "/v1/studies", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, ) assert len(res.json()) == 1 study_id = next(iter(res.json())) res = client.get( f"/v1/studies/{study_id}/outputs", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, ) res_output = res.json() assert len(res_output) == 6 res = client.get( f"/v1/studies/{study_id}/outputs/20201014-1427eco/variables", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, ) assert res.status_code == 417 assert res.json()["description"] == "Not a year by year simulation" @@ -105,7 +105,7 @@ def test_main(client: TestClient, admin_access_token: str) -> None: # study synthesis res = client.get( f"/v1/studies/{study_id}/synthesis", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, ) assert res.status_code == 200, res.json() @@ -113,7 +113,7 @@ def test_main(client: TestClient, admin_access_token: str) -> None: active_ruleset_name = "ruleset test" res = client.post( f"/v1/studies/{study_id}/raw?path=settings/generaldata/general/active-rules-scenario", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, json=active_ruleset_name.title(), # ruleset names are case-insensitive ) assert res.status_code == 204 @@ -121,7 +121,7 @@ def test_main(client: TestClient, admin_access_token: str) -> None: # scenario builder res = client.put( f"/v1/studies/{study_id}/config/scenariobuilder", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, json={ active_ruleset_name: { "l": {"area1": {"0": 1}}, @@ -136,7 +136,7 @@ def test_main(client: TestClient, admin_access_token: str) -> None: res = client.get( f"/v1/studies/{study_id}/config/scenariobuilder", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, ) assert res.status_code == 200 assert res.json() == { @@ -154,57 +154,57 @@ def test_main(client: TestClient, admin_access_token: str) -> None: # config / thematic trimming res = client.get( f"/v1/studies/{study_id}/config/thematictrimming/form", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, ) assert res.status_code == 200 res = client.delete( f"/v1/studies/{study_id}/outputs/20201014-1427eco", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, ) assert res.status_code == 200 res = client.get( f"/v1/studies/{study_id}/outputs", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, ) assert len(res.json()) == 5 # study creation created = client.post( "/v1/studies?name=foo", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, ) assert created.status_code == 201 res = client.get( f"/v1/studies/{created.json()}/raw?path=study&depth=3&formatted=true", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, ) assert res.json()["antares"]["author"] == "George" res = client.get( "/v1/studies", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, ) assert len(res.json()) == 2 # Study copy copied = client.post( f"/v1/studies/{created.json()}/copy?dest=copied&use_task=false", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, ) assert copied.status_code == 201 updated = client.put( f"/v1/studies/{copied.json()}/move?folder_dest=foo/bar", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, ) assert updated.status_code == 200 res = client.get( "/v1/studies", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, ) assert len(res.json()) == 3 moved_study = filter(lambda s: s["id"] == copied.json(), res.json().values()).__next__() @@ -213,19 +213,19 @@ def test_main(client: TestClient, admin_access_token: str) -> None: # Study delete client.delete( f"/v1/studies/{copied.json()}", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, ) res = client.get( "/v1/studies", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, ) assert len(res.json()) == 2 # check study permission res = client.get( "/v1/studies", - headers={"Authorization": f'Bearer {fred_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {fred_credentials['access_token']}"}, ) assert len(res.json()) == 1 @@ -247,26 +247,26 @@ def test_main(client: TestClient, admin_access_token: str) -> None: # reset login to update credentials res = client.post( "/v1/refresh", - headers={"Authorization": f'Bearer {george_credentials["refresh_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['refresh_token']}"}, ) george_credentials = res.json() res = client.post( "/v1/refresh", - headers={"Authorization": f'Bearer {fred_credentials["refresh_token"]}'}, + headers={"Authorization": f"Bearer {fred_credentials['refresh_token']}"}, ) fred_credentials = res.json() client.post( f"/v1/studies?name=bar&groups={group_id}", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, ) res = client.get( "/v1/studies", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, ) assert len(res.json()) == 3 res = client.get( "/v1/studies", - headers={"Authorization": f'Bearer {fred_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {fred_credentials['access_token']}"}, ) assert len(res.json()) == 2 @@ -276,7 +276,7 @@ def test_main(client: TestClient, admin_access_token: str) -> None: study_id = studies[0] res = client.post( f"/v1/launcher/run/{study_id}", - headers={"Authorization": f'Bearer {fred_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {fred_credentials['access_token']}"}, ) job_id = res.json()["job_id"] @@ -290,7 +290,7 @@ def test_main(client: TestClient, admin_access_token: str) -> None: res = client.get( f"/v1/launcher/jobs?study_id={study_id}", - headers={"Authorization": f'Bearer {fred_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {fred_credentials['access_token']}"}, ) job_info = res.json()[0] assert job_info == { @@ -311,7 +311,7 @@ def test_main(client: TestClient, admin_access_token: str) -> None: # update metadata res = client.put( f"/v1/studies/{study_id}", - headers={"Authorization": f'Bearer {fred_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {fred_credentials['access_token']}"}, json={ "name": "STA-mini-copy", "status": "copied", @@ -321,7 +321,7 @@ def test_main(client: TestClient, admin_access_token: str) -> None: ) new_meta = client.get( f"/v1/studies/{study_id}", - headers={"Authorization": f'Bearer {fred_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {fred_credentials['access_token']}"}, ) assert res.json() == new_meta.json() assert new_meta.json()["status"] == "copied" @@ -1536,7 +1536,7 @@ def set_maintenance(value: bool) -> None: # Set maintenance mode when not admin res = client.post( "/v1/core/maintenance?maintenance=true", - headers={"Authorization": f'Bearer {non_admin_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {non_admin_credentials['access_token']}"}, ) assert res.status_code == 403 @@ -1578,7 +1578,7 @@ def test_import(client: TestClient, admin_access_token: str, internal_study_id: george_credentials = res.json() # George imports a study - georges_headers = {"Authorization": f'Bearer {george_credentials["access_token"]}'} + georges_headers = {"Authorization": f"Bearer {george_credentials['access_token']}"} uuid = client.post( "/v1/studies/_import", files={"study": io.BytesIO(zip_path.read_bytes())}, @@ -1603,12 +1603,12 @@ def test_import(client: TestClient, admin_access_token: str, internal_study_id: # reset login to update credentials res = client.post( "/v1/refresh", - headers={"Authorization": f'Bearer {george_credentials["refresh_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['refresh_token']}"}, ) george_credentials = res.json() # George imports a study, and it should succeed even if he has only "READER" access in the group - georges_headers = {"Authorization": f'Bearer {george_credentials["access_token"]}'} + georges_headers = {"Authorization": f"Bearer {george_credentials['access_token']}"} res = client.post( "/v1/studies/_import", files={"study": io.BytesIO(zip_path.read_bytes())}, @@ -1631,12 +1631,12 @@ def test_import(client: TestClient, admin_access_token: str, internal_study_id: output_path_zip = ASSETS_DIR / "output_adq.zip" client.post( f"/v1/studies/{internal_study_id}/output", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, files={"output": io.BytesIO(output_path_zip.read_bytes())}, ) res = client.get( f"/v1/studies/{internal_study_id}/outputs", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, ) assert len(res.json()) == 7 @@ -1644,12 +1644,12 @@ def test_import(client: TestClient, admin_access_token: str, internal_study_id: output_path_seven_zip = ASSETS_DIR / "output_adq.7z" client.post( f"/v1/studies/{internal_study_id}/output", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, files={"output": io.BytesIO(output_path_seven_zip.read_bytes())}, ) res = client.get( f"/v1/studies/{internal_study_id}/outputs", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, ) assert len(res.json()) == 8 @@ -1657,13 +1657,13 @@ def test_import(client: TestClient, admin_access_token: str, internal_study_id: matrices_zip_path = ASSETS_DIR / "matrices.zip" res_zip = client.post( "/v1/matrix/_import", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, files={"file": (matrices_zip_path.name, io.BytesIO(matrices_zip_path.read_bytes()), "application/zip")}, ) matrices_seven_zip_path = ASSETS_DIR / "matrices.7z" res_seven_zip = client.post( "/v1/matrix/_import", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, files={ "file": (matrices_seven_zip_path.name, io.BytesIO(matrices_seven_zip_path.read_bytes()), "application/zip") }, @@ -1694,7 +1694,7 @@ def test_copy(client: TestClient, admin_access_token: str, internal_study_id: st # George copies a study copied = client.post( f"/v1/studies/{internal_study_id}/copy?dest=copied&use_task=false", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, ) assert copied.status_code == 201 # asserts that it has no groups and PublicMode to READ diff --git a/tests/integration/test_integration_watcher.py b/tests/integration/test_integration_watcher.py index a80da7c0c1..70631b34d6 100644 --- a/tests/integration/test_integration_watcher.py +++ b/tests/integration/test_integration_watcher.py @@ -18,7 +18,7 @@ def test_integration_xpansion(app: FastAPI, tmp_path: str): client = TestClient(app, raise_server_exceptions=False) res = client.post("/v1/login", json={"username": "admin", "password": "admin"}) admin_credentials = res.json() - headers = {"Authorization": f'Bearer {admin_credentials["access_token"]}'} + headers = {"Authorization": f"Bearer {admin_credentials['access_token']}"} client.post("/v1/watcher/_scan", headers=headers) client.post("/v1/watcher/_scan?path=/tmp", headers=headers) diff --git a/tests/integration/variant_blueprint/test_variant_manager.py b/tests/integration/variant_blueprint/test_variant_manager.py index 5cc7178754..9d9df25db7 100644 --- a/tests/integration/variant_blueprint/test_variant_manager.py +++ b/tests/integration/variant_blueprint/test_variant_manager.py @@ -151,13 +151,13 @@ def test_variant_manager( george_credentials = res.json() base_study_res = client.post( "/v1/studies?name=foo", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, ) base_study_id = base_study_res.json() res = client.post( f"/v1/studies/{base_study_id}/variants?name=foo_2", - headers={"Authorization": f'Bearer {george_credentials["access_token"]}'}, + headers={"Authorization": f"Bearer {george_credentials['access_token']}"}, ) variant_id = res.json() res = client.get(f"/v1/studies/{variant_id}/commands", headers=admin_headers) @@ -410,9 +410,9 @@ def test_clear_snapshots( # Set up admin_headers = {"Authorization": f"Bearer {admin_access_token}"} - older = Path(tmp_path).joinpath(f"internal_workspace", generate_snapshots[0], "snapshot") - old = Path(tmp_path).joinpath(f"internal_workspace", generate_snapshots[1], "snapshot") - recent = Path(tmp_path).joinpath(f"internal_workspace", generate_snapshots[2], "snapshot") + older = Path(tmp_path).joinpath("internal_workspace", generate_snapshots[0], "snapshot") + old = Path(tmp_path).joinpath("internal_workspace", generate_snapshots[1], "snapshot") + recent = Path(tmp_path).joinpath("internal_workspace", generate_snapshots[2], "snapshot") # Test # Check initial data @@ -420,19 +420,19 @@ def test_clear_snapshots( # Delete the older snapshot (default retention hours implicitly equals to 24 hours) # and check if it was successfully deleted - response = client.put(f"v1/studies/variants/clear-snapshots", headers=admin_headers) + response = client.put("v1/studies/variants/clear-snapshots", headers=admin_headers) task = response.json() wait_task_completion(client, admin_access_token, task) assert (not older.exists()) and old.exists() and recent.exists() # Delete the old snapshot and check if it was successfully deleted - response = client.put(f"v1/studies/variants/clear-snapshots?hours=6", headers=admin_headers) + response = client.put("v1/studies/variants/clear-snapshots?hours=6", headers=admin_headers) task = response.json() wait_task_completion(client, admin_access_token, task) assert (not older.exists()) and (not old.exists()) and recent.exists() # Delete the recent snapshot and check if it was successfully deleted - response = client.put(f"v1/studies/variants/clear-snapshots?hours=-1", headers=admin_headers) + response = client.put("v1/studies/variants/clear-snapshots?hours=-1", headers=admin_headers) task = response.json() wait_task_completion(client, admin_access_token, task) assert not (older.exists() and old.exists() and recent.exists()) diff --git a/tests/login/test_web.py b/tests/login/test_web.py index 467707721c..73cc2f63d6 100644 --- a/tests/login/test_web.py +++ b/tests/login/test_web.py @@ -179,7 +179,7 @@ def test_refresh() -> None: meta, b64, sign = str(data["access_token"]).split(".") data = b64 + "===" # fix padding issue - identity = json.loads(base64.b64decode(data))["sub"] + json.loads(base64.b64decode(data))["sub"] @pytest.mark.unit_test diff --git a/tests/matrixstore/test_matrix_garbage_collector.py b/tests/matrixstore/test_matrix_garbage_collector.py index 6c0ce26470..d681f3a38e 100644 --- a/tests/matrixstore/test_matrix_garbage_collector.py +++ b/tests/matrixstore/test_matrix_garbage_collector.py @@ -23,7 +23,6 @@ from antarest.matrixstore.model import MatrixDataSetUpdateDTO, MatrixInfoDTO from antarest.matrixstore.repository import MatrixDataSetRepository from antarest.matrixstore.service import MatrixService -from antarest.study.storage.patch_service import PatchService from antarest.study.storage.variantstudy.business.matrix_constants_generator import GeneratorMatrixConstants from antarest.study.storage.variantstudy.command_factory import CommandFactory from antarest.study.storage.variantstudy.model.command.common import CommandName @@ -181,7 +180,7 @@ def test_get_matrices_used_in_dataset( with db(): matrix1_id = matrix_service.create(np.ones((1, 1))) matrix2_id = matrix_service.create(np.ones((2, 1))) - dataset = matrix_service.create_dataset( + matrix_service.create_dataset( dataset_info=MatrixDataSetUpdateDTO(name="name", groups=[], public=True), matrices=[MatrixInfoDTO(id=matrix1_id, name="matrix_1"), MatrixInfoDTO(id=matrix2_id, name="matrix_2")], params=RequestParameters(admin_user), diff --git a/tests/matrixstore/test_repository.py b/tests/matrixstore/test_repository.py index 7fc4c740c5..7f38d47df1 100644 --- a/tests/matrixstore/test_repository.py +++ b/tests/matrixstore/test_repository.py @@ -173,10 +173,7 @@ def test_datastore_query(self, db_session: Session) -> None: assert repo.get(m1.id) is not None assert ( # fmt: off - db_session - .query(MatrixDataSetRelation) - .filter(MatrixDataSetRelation.dataset_id == dataset.id) - .count() + db_session.query(MatrixDataSetRelation).filter(MatrixDataSetRelation.dataset_id == dataset.id).count() # fmt: on == 0 ) diff --git a/tests/matrixstore/test_service.py b/tests/matrixstore/test_service.py index fa8119a643..ce7d25f8bb 100644 --- a/tests/matrixstore/test_service.py +++ b/tests/matrixstore/test_service.py @@ -16,7 +16,7 @@ import time import typing as t import zipfile -from unittest.mock import ANY, Mock +from unittest.mock import Mock import numpy as np import pytest @@ -364,18 +364,6 @@ def test_dataset_lifecycle() -> None: ] user_service.get_group.return_value = Group(id="groupA", name="groupA") - expected = MatrixDataSet( - name=dataset_info.name, - public=dataset_info.public, - owner_id=userA.user.id, - groups=[Group(id="groupA", name="groupA")], - created_at=ANY, - updated_at=ANY, - matrices=[ - MatrixDataSetRelation(name="A", matrix_id="m1"), - MatrixDataSetRelation(name="B", matrix_id="m2"), - ], - ) service.create_dataset(dataset_info, matrices, params=userA) assert dataset_repo.save.call_count == 1 call = dataset_repo.save.call_args_list[0] diff --git a/tests/storage/business/test_arealink_manager.py b/tests/storage/business/test_arealink_manager.py index 451d386c8e..6128d70448 100644 --- a/tests/storage/business/test_arealink_manager.py +++ b/tests/storage/business/test_arealink_manager.py @@ -100,7 +100,6 @@ def test_area_crud( def test_get_all_area(area_manager: AreaManager, link_manager: LinkManager) -> None: - config = FileStudyTreeConfig( study_path=Path("somepath"), path=Path("somepath"), @@ -364,7 +363,6 @@ def test_get_all_area(area_manager: AreaManager, link_manager: LinkManager) -> N def test_update_area(area_manager: AreaManager): - config = FileStudyTreeConfig( study_path=Path("somepath"), path=Path("somepath"), @@ -401,7 +399,6 @@ def test_update_area(area_manager: AreaManager): def test_update_clusters(area_manager: AreaManager): - config = FileStudyTreeConfig( study_path=Path("somepath"), path=Path("somepath"), diff --git a/tests/storage/business/test_config_manager.py b/tests/storage/business/test_config_manager.py index 6249d6d6e3..ffba76f440 100644 --- a/tests/storage/business/test_config_manager.py +++ b/tests/storage/business/test_config_manager.py @@ -13,10 +13,8 @@ from pathlib import Path from unittest.mock import Mock -import pytest from antares.study.version import StudyVersion -from antarest.matrixstore.service import ISimpleMatrixService from antarest.study.business.study_interface import StudyInterface from antarest.study.business.thematic_trimming_field_infos import FIELDS_INFO from antarest.study.business.thematic_trimming_management import ( @@ -27,7 +25,6 @@ from antarest.study.storage.rawstudy.model.filesystem.config.model import FileStudyTreeConfig from antarest.study.storage.rawstudy.model.filesystem.factory import FileStudy from antarest.study.storage.rawstudy.model.filesystem.root.filestudytree import FileStudyTree -from antarest.study.storage.variantstudy.business.matrix_constants_generator import GeneratorMatrixConstants from antarest.study.storage.variantstudy.model.command.update_config import UpdateConfig from antarest.study.storage.variantstudy.model.command_context import CommandContext diff --git a/tests/storage/business/test_timeseries_config_manager.py b/tests/storage/business/test_timeseries_config_manager.py index 177cc9626d..450dafce28 100644 --- a/tests/storage/business/test_timeseries_config_manager.py +++ b/tests/storage/business/test_timeseries_config_manager.py @@ -35,7 +35,7 @@ def file_study_820(tmpdir: Path) -> FileStudy: cur_dir: Path = Path(__file__).parent study_path = Path(tmpdir / str(uuid.uuid4())) os.mkdir(study_path) - with ZipFile(cur_dir / "assets" / f"empty_study_820.zip") as zip_output: + with ZipFile(cur_dir / "assets" / "empty_study_820.zip") as zip_output: zip_output.extractall(path=study_path) config = build(study_path, "1") return FileStudy(config, FileStudyTree(Mock(), config)) diff --git a/tests/storage/business/test_variant_study_service.py b/tests/storage/business/test_variant_study_service.py index f6e6077c40..26f04a2779 100644 --- a/tests/storage/business/test_variant_study_service.py +++ b/tests/storage/business/test_variant_study_service.py @@ -123,7 +123,6 @@ def test_get_cache(tmp_path: str) -> None: path_study.mkdir() (path_study / "settings").mkdir() (path_study / "study.antares").touch() - path = path_study / "settings" data = {"titi": 43} study = Mock() diff --git a/tests/storage/integration/test_write_STA_mini.py b/tests/storage/integration/test_write_STA_mini.py index 832b2eeded..1769a855e0 100644 --- a/tests/storage/integration/test_write_STA_mini.py +++ b/tests/storage/integration/test_write_STA_mini.py @@ -84,24 +84,6 @@ def test_sta_mini_layers_layers(storage_service, url: str, new: SUB_JSON): ) -@pytest.mark.integration_test -@pytest.mark.parametrize( - "url, new", - [ - ( - f"/v1/studies/{UUID}/raw?path=layers/layers/activeLayer/showAllLayer", - False, - ), - ], -) -def test_sta_mini_layers_layers(storage_service, url: str, new: SUB_JSON): - assert_with_errors( - storage_service=storage_service, - url=url, - new=new, - ) - - @pytest.mark.integration_test @pytest.mark.parametrize( "url, new", diff --git a/tests/storage/repository/filesystem/root/input/hydro/common/capacity/test_capacity.py b/tests/storage/repository/filesystem/root/input/hydro/common/capacity/test_capacity.py index 2f98bf7b4b..b8350b3e3a 100644 --- a/tests/storage/repository/filesystem/root/input/hydro/common/capacity/test_capacity.py +++ b/tests/storage/repository/filesystem/root/input/hydro/common/capacity/test_capacity.py @@ -90,13 +90,12 @@ def test_build_input_hydro_common_capacity( actual = node.build() # check the result - value: InputSeriesMatrix - actual_obj = { - key: { + actual_obj = {} + for key, value in actual.items(): + assert isinstance(value, InputSeriesMatrix) + actual_obj[key] = { "default_empty": [[]], "freq": value.freq, "nb_columns": value.nb_columns, } - for key, value in actual.items() - } assert actual_obj == expected diff --git a/tests/storage/repository/filesystem/root/input/hydro/series/area/test_area.py b/tests/storage/repository/filesystem/root/input/hydro/series/area/test_area.py index 0f71922ede..e102556140 100644 --- a/tests/storage/repository/filesystem/root/input/hydro/series/area/test_area.py +++ b/tests/storage/repository/filesystem/root/input/hydro/series/area/test_area.py @@ -108,13 +108,12 @@ def test_build_input_hydro_series_area( actual = node.build() # check the result - value: InputSeriesMatrix - actual_obj = { - key: { + actual_obj = {} + for key, value in actual.items(): + assert isinstance(value, InputSeriesMatrix) + actual_obj[key] = { "default_empty": value.default_empty.tolist(), "freq": value.freq, "nb_columns": value.nb_columns, } - for key, value in actual.items() - } assert actual_obj == expected diff --git a/tests/storage/repository/filesystem/root/output/simulation/mode/common/test_area.py b/tests/storage/repository/filesystem/root/output/simulation/mode/common/test_area.py index 5727835f9a..311c9870b8 100644 --- a/tests/storage/repository/filesystem/root/output/simulation/mode/common/test_area.py +++ b/tests/storage/repository/filesystem/root/output/simulation/mode/common/test_area.py @@ -58,8 +58,10 @@ def test_build_output_simulation_area_item(self, existing_files: t.List[str], tm actual = node.build() # check the result - value: AreaOutputSeriesMatrix - actual_obj = {key: {"freq": value.freq} for key, value in actual.items()} + actual_obj: dict[str, dict[str, MatrixFrequency]] = {} + for key, value in actual.items(): + assert isinstance(value, AreaOutputSeriesMatrix) + actual_obj[key] = {"freq": value.freq} assert actual_obj == expected new_config = FileStudyTreeConfig( @@ -73,6 +75,9 @@ def test_build_output_simulation_area_item(self, existing_files: t.List[str], tm new_node = area.OutputSimulationAreaItem(context=context, config=new_config, area="fr") new_actual = new_node.build() # check the result - actual_obj = {key: {"freq": value.freq} for key, value in new_actual.items()} + actual_obj: dict[str, dict[str, MatrixFrequency]] = {} + for key, value in new_actual.items(): + assert isinstance(value, AreaOutputSeriesMatrix) + actual_obj[key] = {"freq": value.freq} assert actual_obj == expected diff --git a/tests/storage/repository/filesystem/root/output/simulation/mode/common/test_binding_const.py b/tests/storage/repository/filesystem/root/output/simulation/mode/common/test_binding_const.py index 2654c3fc6a..1b66bc8b03 100644 --- a/tests/storage/repository/filesystem/root/output/simulation/mode/common/test_binding_const.py +++ b/tests/storage/repository/filesystem/root/output/simulation/mode/common/test_binding_const.py @@ -58,6 +58,8 @@ def test_build_output_simulation_binding_constraint_item(self, existing_files: t actual = node.build() # check the result - value: BindingConstraintOutputSeriesMatrix - actual_obj = {key: {"freq": value.freq} for key, value in actual.items()} + actual_obj: dict[str, dict[str, MatrixFrequency]] = {} + for key, value in actual.items(): + assert isinstance(value, BindingConstraintOutputSeriesMatrix) + actual_obj[key] = {"freq": value.freq} assert actual_obj == expected diff --git a/tests/storage/repository/filesystem/root/output/simulation/mode/common/test_link.py b/tests/storage/repository/filesystem/root/output/simulation/mode/common/test_link.py index 685dbedb8c..ee35d6444c 100644 --- a/tests/storage/repository/filesystem/root/output/simulation/mode/common/test_link.py +++ b/tests/storage/repository/filesystem/root/output/simulation/mode/common/test_link.py @@ -56,6 +56,8 @@ def test_build_output_simulation_link_item(self, existing_files: t.List[str], tm actual = node.build() # check the result - value: LinkOutputSeriesMatrix - actual_obj = {key: {"freq": value.freq} for key, value in actual.items()} + actual_obj: dict[str, dict[str, MatrixFrequency]] = {} + for key, value in actual.items(): + assert isinstance(value, LinkOutputSeriesMatrix) + actual_obj[key] = {"freq": value.freq} assert actual_obj == expected diff --git a/tests/storage/repository/filesystem/root/output/simulation/mode/common/test_set.py b/tests/storage/repository/filesystem/root/output/simulation/mode/common/test_set.py index 6721368de5..4d427f15df 100644 --- a/tests/storage/repository/filesystem/root/output/simulation/mode/common/test_set.py +++ b/tests/storage/repository/filesystem/root/output/simulation/mode/common/test_set.py @@ -56,6 +56,8 @@ def test_output_simulation_set(self, existing_files: t.List[str], tmp_path: Path actual = node.build() # check the result - value: AreaOutputSeriesMatrix - actual_obj = {key: {"freq": value.freq} for key, value in actual.items()} + actual_obj: dict[str, dict[str, MatrixFrequency]] = {} + for key, value in actual.items(): + assert isinstance(value, AreaOutputSeriesMatrix) + actual_obj[key] = {"freq": value.freq} assert actual_obj == expected diff --git a/tests/storage/repository/filesystem/test_bucket_node.py b/tests/storage/repository/filesystem/test_bucket_node.py index 596f2fb257..2a26c489a7 100644 --- a/tests/storage/repository/filesystem/test_bucket_node.py +++ b/tests/storage/repository/filesystem/test_bucket_node.py @@ -65,7 +65,7 @@ def test_get_bucket(tmp_path: Path): assert "fileB.txt" in bucket["fileB.txt"] assert "fileC.txt" in bucket["folder"]["fileC.txt"] for registered_file in registered_files: - assert type(node._get([registered_file.key], get_node=True)) == registered_file.node + assert isinstance(node._get([registered_file.key], get_node=True), registered_file.node) def test_save_bucket(tmp_path: Path): diff --git a/tests/study/business/areas/test_st_storage_management.py b/tests/study/business/areas/test_st_storage_management.py index 86b4f2205b..9de2a14254 100644 --- a/tests/study/business/areas/test_st_storage_management.py +++ b/tests/study/business/areas/test_st_storage_management.py @@ -83,7 +83,6 @@ def create_study_interface(tree: FileStudyTree) -> StudyInterface: class TestSTStorageManager: - def test_get_all_storages__nominal_case( self, st_storage_manager: STStorageManager, @@ -476,7 +475,6 @@ def test_get_matrix__invalid_matrix(self, st_storage_manager: STStorageManager) # noinspection SpellCheckingInspection def test_validate_matrices__nominal(self, st_storage_manager: STStorageManager) -> None: - # prepare some random matrices, insuring `lower_rule_curve` <= `upper_rule_curve` matrices = { "pmax_injection": GEN.random((8760, 1)), @@ -510,7 +508,6 @@ def test_validate_matrices__out_of_bound( self, st_storage_manager: STStorageManager, ) -> None: - # prepare some random matrices, insuring `lower_rule_curve` <= `upper_rule_curve` matrices = { "pmax_injection": GEN.random((8760, 1)) * 2 - 0.5, # out of bound diff --git a/tests/study/business/areas/test_thermal_management.py b/tests/study/business/areas/test_thermal_management.py index 7e2906d0e3..f37bd6168c 100644 --- a/tests/study/business/areas/test_thermal_management.py +++ b/tests/study/business/areas/test_thermal_management.py @@ -362,7 +362,6 @@ def test_update_cluster( manager: ThermalManager, study_interface: StudyInterface, ): - # When some properties of the cluster are updated cluster_data = ThermalClusterInput(name="New name", nominalCapacity=2000) manager.update_cluster( diff --git a/tests/study/business/conftest.py b/tests/study/business/conftest.py index 71bbbc94f1..816bab4eba 100644 --- a/tests/study/business/conftest.py +++ b/tests/study/business/conftest.py @@ -16,7 +16,6 @@ from antarest.study.business.area_management import AreaManager from antarest.study.business.areas.st_storage_management import STStorageManager from antarest.study.business.link_management import LinkManager -from antarest.study.business.xpansion_management import XpansionManager from antarest.study.storage.variantstudy.business.matrix_constants_generator import GeneratorMatrixConstants from antarest.study.storage.variantstudy.model.command_context import CommandContext diff --git a/tests/study/business/test_allocation_manager.py b/tests/study/business/test_allocation_manager.py index 3365534089..bd5055bd78 100644 --- a/tests/study/business/test_allocation_manager.py +++ b/tests/study/business/test_allocation_manager.py @@ -184,9 +184,7 @@ def test_validation_matrix_no_non_null_values(self): class TestAllocationManager: - def test_get_allocation_matrix__nominal_case(self, manager): - # Prepare the mocks allocation_cfg = { "n": {"[allocation]": {"n": 1}}, @@ -226,7 +224,6 @@ def test_get_allocation_matrix__nominal_case(self, manager): ) def test_get_allocation_matrix__no_allocation(self, manager): - # Prepare the mocks allocation_cfg = {} study = create_study_interface( @@ -339,7 +336,6 @@ def test_set_allocation_form_fields__nominal_case(self, manager): assert cmd.data == {"e": 0.5, "s": 0.25, "w": 0.25} def test_set_allocation_form_fields__no_allocation_data(self, manager): - all_areas = [ AreaInfoDTO(id="n", name="North", type=AreaType.AREA), AreaInfoDTO(id="e", name="East", type=AreaType.AREA), @@ -374,7 +370,6 @@ def test_set_allocation_form_fields__no_allocation_data(self, manager): assert "n" in ctx.value.detail def test_set_allocation_form_fields__invalid_area_ids(self, manager): - all_areas = [ AreaInfoDTO(id="n", name="North", type=AreaType.AREA), AreaInfoDTO(id="e", name="East", type=AreaType.AREA), diff --git a/tests/study/business/test_binding_constraint_management.py b/tests/study/business/test_binding_constraint_management.py index f14efa3a7f..9c72b196ec 100644 --- a/tests/study/business/test_binding_constraint_management.py +++ b/tests/study/business/test_binding_constraint_management.py @@ -18,6 +18,7 @@ ClusterTerm, ConstraintFilters, ConstraintOutput, + ConstraintOutput830, ConstraintOutput870, ConstraintOutputBase, ConstraintTerm, @@ -82,24 +83,23 @@ def test_filter_by__comments(self, comments: str, expected: bool, cls: t.Type[Co assert bc_filter.match_filters(constraint) == expected @pytest.mark.parametrize("group, expected", [("grp1", False), ("grp2", False), ("", True)]) - @pytest.mark.parametrize("cls", [ConstraintOutput]) - def test_filter_by__group(self, group: str, expected: bool, cls: t.Type[ConstraintOutput]) -> None: + def test_filter_by__group(self, group: str, expected: bool) -> None: """ The filter should never match if the filter's `group` is not empty. """ bc_filter = ConstraintFilters(group=group) - constraint = cls(id="bc1", name="BC1") - assert bc_filter.match_filters(constraint) == expected + for cls in [ConstraintOutputBase, ConstraintOutput830, ConstraintOutput870]: + constraint = cls(id="bc1", name="BC1") + assert bc_filter.match_filters(constraint) == expected @pytest.mark.parametrize("group, expected", [("grp1", True), ("GRP1", True), ("grp2", False), ("", True)]) - @pytest.mark.parametrize("cls", [ConstraintOutput870]) - def test_filter_by__group(self, group: str, expected: bool, cls: t.Type[ConstraintOutput870]) -> None: + def test_filter_by__group_with_existing_group(self, group: str, expected: bool) -> None: """ The filter should match if the `group` is equal to the constraint's `group` or if the filter is empty. Comparisons should be case-insensitive. """ bc_filter = ConstraintFilters(group=group) - constraint = cls(id="bc1", name="BC1", group="Grp1") + constraint = ConstraintOutput870(id="bc1", name="BC1", group="Grp1") assert bc_filter.match_filters(constraint) == expected @pytest.mark.parametrize("time_step, expected", [("hourly", True), ("daily", False), (None, True)]) diff --git a/tests/study/business/test_correlation_manager.py b/tests/study/business/test_correlation_manager.py index fe908007c3..536e3d1e6d 100644 --- a/tests/study/business/test_correlation_manager.py +++ b/tests/study/business/test_correlation_manager.py @@ -165,9 +165,7 @@ def create_study_interface(tree: FileStudyTree, version: StudyVersion = STUDY_VE class TestCorrelationManager: - def test_get_correlation_matrix__nominal_case(self, correlation_manager): - # Prepare the mocks correlation_cfg = { "n%n": 0.1, @@ -209,7 +207,6 @@ def test_get_correlation_matrix__nominal_case(self, correlation_manager): ) def test_get_field_values__nominal_case(self, correlation_manager): - # Prepare the mocks # NOTE: "s%s" value is ignored correlation_cfg = {"s%s": 0.1, "n%s": 0.2, "w%n": 0.6} @@ -238,7 +235,6 @@ def test_get_field_values__nominal_case(self, correlation_manager): ) def test_set_field_values__nominal_case(self, correlation_manager): - # Prepare the mocks: North + South correlation_cfg = {} study = create_study_interface( @@ -282,7 +278,6 @@ def test_set_field_values__nominal_case(self, correlation_manager): assert cmd.data == {"e%s": 0.3, "n%s": 0.4} def test_set_field_values__area_not_found(self, correlation_manager): - # Prepare the mocks: North + South correlation_cfg = {} study = create_study_interface( diff --git a/tests/study/business/test_district_manager.py b/tests/study/business/test_district_manager.py index 45ce81d6ae..1f574f2c2d 100644 --- a/tests/study/business/test_district_manager.py +++ b/tests/study/business/test_district_manager.py @@ -9,8 +9,7 @@ # SPDX-License-Identifier: MPL-2.0 # # This file is part of the Antares project. -from typing import Optional -from unittest.mock import Mock, patch +from unittest.mock import Mock import pytest from antares.study.version import StudyVersion @@ -22,13 +21,11 @@ DistrictManager, DistrictUpdateDTO, ) -from antarest.study.business.study_interface import FileStudyInterface, StudyInterface -from antarest.study.model import STUDY_VERSION_8_6, STUDY_VERSION_8_8, Study -from antarest.study.storage.rawstudy.model.filesystem.config.model import DistrictSet, FileStudyTreeConfig +from antarest.study.business.study_interface import StudyInterface +from antarest.study.model import STUDY_VERSION_8_6, STUDY_VERSION_8_8 +from antarest.study.storage.rawstudy.model.filesystem.config.model import DistrictSet from antarest.study.storage.rawstudy.model.filesystem.factory import FileStudy from antarest.study.storage.rawstudy.model.filesystem.root.filestudytree import FileStudyTree -from antarest.study.storage.rawstudy.raw_study_service import RawStudyService -from antarest.study.storage.storage_service import StudyStorageService from antarest.study.storage.variantstudy.model.command.create_district import CreateDistrict from antarest.study.storage.variantstudy.model.command.remove_district import RemoveDistrict from antarest.study.storage.variantstudy.model.command.update_district import UpdateDistrict @@ -62,7 +59,6 @@ def create_study_interface(file_study: FileStudy, version: StudyVersion = STUDY_ class TestDistrictManager: - def test_get_districts(self, manager: DistrictManager): # prepare data areas = dict.fromkeys(["n1", "n2", "n3"]) diff --git a/tests/study/storage/variantstudy/test_snapshot_generator.py b/tests/study/storage/variantstudy/test_snapshot_generator.py index 5a7a3c96c1..f07d644e90 100644 --- a/tests/study/storage/variantstudy/test_snapshot_generator.py +++ b/tests/study/storage/variantstudy/test_snapshot_generator.py @@ -1125,8 +1125,7 @@ def test_generate__with_invalid_command( ) err_msg = ( - f"Failed to generate variant study {variant_study.id}:" - f" Area 'North' already exists and could not be created" + f"Failed to generate variant study {variant_study.id}: Area 'North' already exists and could not be created" ) with pytest.raises(VariantGenerationError, match=re.escape(err_msg)): generator.generate_snapshot( diff --git a/tests/study/test_model.py b/tests/study/test_model.py index fc6fc148ad..1c7f1bbf12 100644 --- a/tests/study/test_model.py +++ b/tests/study/test_model.py @@ -13,6 +13,7 @@ """ Test the database model. """ + import uuid from sqlalchemy import inspect # type: ignore diff --git a/tests/study/test_repository.py b/tests/study/test_repository.py index 24a7e2c205..140127bb5a 100644 --- a/tests/study/test_repository.py +++ b/tests/study/test_repository.py @@ -861,10 +861,10 @@ def test_get_all__study_tags_filter( assert len(db_recorder.sql_statements) == 1, str(db_recorder) +# fmt: off @pytest.mark.parametrize( "user_id, study_groups, expected_ids", [ - # fmt: off (101, [], ["1", "2", "5", "6", "7", "8", "9", "10", "13", "14", "15", "16", "17", "18", "21", "22", "23", "24", "25", "26", "29", "30", "31", "32", "34"]), (101, ["101"], ["1", "7", "8", "9", "17", "23", "24", "25"]), @@ -901,9 +901,9 @@ def test_get_all__study_tags_filter( (None, ["101", "103"], []), (None, ["102", "103"], []), (None, ["101", "102", "103"], []), - # fmt: on ], ) +# fmt: on def test_get_all__non_admin_permissions_filter( db_session: Session, user_id: t.Optional[int], @@ -974,16 +974,16 @@ def test_get_all__non_admin_permissions_filter( study_38 = RawStudy(id=38, name="study-X38", groups=[group_3]) db_session.add_all([user_1, user_2, user_3, group_1, group_2, group_3]) + # fmt: off db_session.add_all( [ - # fmt: off study_1, study_2, study_3, study_4, study_5, study_6, study_7, study_8, study_9, study_10, study_11, study_12, study_13, study_14, study_15, study_16, study_17, study_18, study_19, study_20, study_21, study_22, study_23, study_24, study_25, study_26, study_27, study_28, study_29, study_30, - study_31, study_32, study_33, study_34, study_35, study_36, study_37, study_38, - # fmt: on - ] + study_31, study_32, study_33, study_34, study_35, study_36, study_37, study_38 + ] ) + # fmt: on db_session.commit() access_permissions = ( @@ -1019,11 +1019,10 @@ def test_get_all__non_admin_permissions_filter( assert sorted((s.id for s in all_studies), key=int) == expected_ids[2:4] assert len(db_recorder.sql_statements) == 1, str(db_recorder) - +# fmt: off @pytest.mark.parametrize( "is_admin, study_groups, expected_ids", [ - # fmt: off (True, [], [str(e) for e in range(1, 39)]), (True, ["101"], ["1", "3", "4", "7", "8", "9", "17", "19", "20", "23", "24", "25", "33"]), (True, ["102"], ["2", "5", "6", "7", "8", "9", "18", "21", "22", "23", "24", "25", "34"]), @@ -1040,9 +1039,9 @@ def test_get_all__non_admin_permissions_filter( (False, ["101", "102"], []), (False, ["101", "103"], []), (False, ["101", "102", "103"], []), - # fmt: on ], ) +# fmt: on def test_get_all__admin_permissions_filter( db_session: Session, is_admin: bool, @@ -1110,16 +1109,16 @@ def test_get_all__admin_permissions_filter( study_38 = RawStudy(id=38, name="study-X38", groups=[group_3]) db_session.add_all([user_1, user_2, user_3, group_1, group_2, group_3]) + # fmt: off db_session.add_all( [ - # fmt: off study_1, study_2, study_3, study_4, study_5, study_6, study_7, study_8, study_9, study_10, study_11, study_12, study_13, study_14, study_15, study_16, study_17, study_18, study_19, study_20, study_21, study_22, study_23, study_24, study_25, study_26, study_27, study_28, study_29, study_30, - study_31, study_32, study_33, study_34, study_35, study_36, study_37, study_38, - # fmt: on - ] + study_31, study_32, study_33, study_34, study_35, study_36, study_37, study_38 + ] ) + # fmt: on db_session.commit() access_permissions = AccessPermissions(is_admin=is_admin) diff --git a/tests/variantstudy/test_command_factory.py b/tests/variantstudy/test_command_factory.py index 60696ab84a..f5b9d56261 100644 --- a/tests/variantstudy/test_command_factory.py +++ b/tests/variantstudy/test_command_factory.py @@ -21,7 +21,6 @@ from antarest.matrixstore.service import MatrixService from antarest.study.business.model.area_model import UpdateAreaUi from antarest.study.model import STUDY_VERSION_8_8 -from antarest.study.storage.patch_service import PatchService from antarest.study.storage.variantstudy.business.matrix_constants_generator import GeneratorMatrixConstants from antarest.study.storage.variantstudy.command_factory import CommandFactory from antarest.study.storage.variantstudy.model.command.common import CommandName