From 8da9d87a6c906ba8345b6cc8375aca22808c0a54 Mon Sep 17 00:00:00 2001 From: Henrik Koski <98282892+PiispaH@users.noreply.github.com> Date: Thu, 18 Jul 2024 09:39:08 +0300 Subject: [PATCH] Issue 2895 configure isort (#146) * Sort imports using isort No functional changes, just configured isort in pyproject.toml and ran it. * Clean imports Removed unused imports and disabled pylint warnings on some lines. --- .github/pull_request_template.md | 2 +- pyproject.toml | 9 ++++ .../conda_kernel_spec_manager.py | 15 +++--- .../conda_kernel_spec_runner.py | 4 +- .../kernel_execution_manager.py | 6 +-- .../persistent_execution_manager.py | 16 +++---- .../process_execution_manager.py | 4 +- spine_engine/execution_managers/spine_repl.py | 6 +-- spine_engine/jumpster.py | 9 ++-- spine_engine/project_item/connection.py | 25 ++++------ .../project_item/project_item_resource.py | 6 +-- .../project_item_specification.py | 2 +- spine_engine/server/certificate_creator.py | 2 +- spine_engine/server/engine_server.py | 15 +++--- .../server/persistent_execution_service.py | 2 +- spine_engine/server/ping_service.py | 4 +- .../server/project_extractor_service.py | 6 +-- .../server/project_remover_service.py | 2 +- .../server/project_retriever_service.py | 6 +-- .../server/remote_execution_service.py | 2 +- spine_engine/spine_engine.py | 48 +++++++++---------- spine_engine/utils/helpers.py | 12 ++--- spine_engine/utils/returning_process.py | 4 +- spine_engine/utils/serialization.py | 2 +- .../test_kernel_execution_manager.py | 6 +-- .../test_process_execution_manager.py | 2 +- tests/project_item/test_connection.py | 2 +- .../test_project_item_resource.py | 2 +- tests/server/test_EngineServer.py | 4 +- tests/server/test_PingService.py | 2 +- tests/server/test_ProjectExtractorService.py | 8 ++-- tests/server/test_ProjectRemoverService.py | 6 +-- tests/server/test_start_server.py | 4 +- tests/server/util/test_EventDataConverter.py | 4 +- tests/server/util/test_ServerMessage.py | 2 +- tests/server/util/test_ZipHandler.py | 2 +- tests/test_load_project_items.py | 2 +- tests/test_spine_engine.py | 14 +++--- tests/utils/test_helpers.py | 6 +-- tests/utils/test_serialization.py | 7 ++- 40 files changed, 141 insertions(+), 141 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 4d703c17..30302cda 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -6,5 +6,5 @@ Fixes # (issue) - [ ] Documentation (also in Toolbox repo) is up-to-date - [ ] Release notes in Toolbox repo have been updated - [ ] Unit tests have been added/updated accordingly -- [ ] Code has been formatted by black +- [ ] Code has been formatted by black & isort - [ ] Unit tests pass diff --git a/pyproject.toml b/pyproject.toml index 0573b0a5..90100d55 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,3 +57,12 @@ ignore_errors = true [tool.black] line-length = 120 exclude = '\.git|version.py' + +[tool.isort] +profile = "black" +lines_between_sections = 0 +force_sort_within_sections = true +honor_case_in_force_sorted_sections = true +skip = ["version.py"] +line_length = 120 +known_first_party = ["spinedb_api"] diff --git a/spine_engine/execution_managers/conda_kernel_spec_manager.py b/spine_engine/execution_managers/conda_kernel_spec_manager.py index db37351b..0318adc8 100644 --- a/spine_engine/execution_managers/conda_kernel_spec_manager.py +++ b/spine_engine/execution_managers/conda_kernel_spec_manager.py @@ -2,19 +2,18 @@ # https://github.com/Anaconda-Platform/nb_conda_kernels/blob/master/nb_conda_kernels/manager.py # -*- coding: utf-8 -*- -import logging +import glob import json +import logging +import os +from os.path import abspath, basename, dirname, join, split import re import shutil import subprocess import sys import time -import glob - -import os -from os.path import join, split, dirname, basename, abspath -from traitlets import Bool, Unicode, TraitError, validate -from jupyter_client.kernelspec import KernelSpecManager, KernelSpec, NoSuchKernel +from jupyter_client.kernelspec import KernelSpec, KernelSpecManager, NoSuchKernel +from traitlets import Bool, TraitError, Unicode, validate CACHE_TIMEOUT = 60 @@ -109,7 +108,7 @@ def clean_kernel_name(kname): kname.encode("ascii") except UnicodeEncodeError: # Replace accented characters with unaccented equivalents - import unicodedata + import unicodedata # pylint: disable=import-outside-toplevel nfkd_form = unicodedata.normalize("NFKD", kname) kname = "".join([c for c in nfkd_form if not unicodedata.combining(c)]) diff --git a/spine_engine/execution_managers/conda_kernel_spec_runner.py b/spine_engine/execution_managers/conda_kernel_spec_runner.py index 1a08bf75..6aa30993 100644 --- a/spine_engine/execution_managers/conda_kernel_spec_runner.py +++ b/spine_engine/execution_managers/conda_kernel_spec_runner.py @@ -2,11 +2,9 @@ # https://github.com/Anaconda-Platform/nb_conda_kernels/blob/master/nb_conda_kernels/runner.py from __future__ import print_function - import os -import sys import subprocess -import locale +import sys try: from shlex import quote diff --git a/spine_engine/execution_managers/kernel_execution_manager.py b/spine_engine/execution_managers/kernel_execution_manager.py index 4701a03d..eae9d7b3 100644 --- a/spine_engine/execution_managers/kernel_execution_manager.py +++ b/spine_engine/execution_managers/kernel_execution_manager.py @@ -16,14 +16,14 @@ """ import os -import sys import subprocess +import sys import uuid -from jupyter_client.manager import KernelManager from jupyter_client.kernelspec import NoSuchKernel +from jupyter_client.manager import KernelManager +from spine_engine.execution_managers.conda_kernel_spec_manager import CondaKernelSpecManager from ..utils.helpers import Singleton from .execution_manager_base import ExecutionManagerBase -from spine_engine.execution_managers.conda_kernel_spec_manager import CondaKernelSpecManager class GroupedKernelManager(KernelManager): diff --git a/spine_engine/execution_managers/persistent_execution_manager.py b/spine_engine/execution_managers/persistent_execution_manager.py index 57f86a62..0e0a5737 100644 --- a/spine_engine/execution_managers/persistent_execution_manager.py +++ b/spine_engine/execution_managers/persistent_execution_manager.py @@ -15,20 +15,20 @@ as well as some convenience functions. """ -import uuid +from dataclasses import dataclass +from multiprocessing import Lock, Process +import os +from queue import Empty, Queue +import signal import socket import socketserver +from subprocess import PIPE, Popen import sys -import os -import signal import threading import time -from dataclasses import dataclass -from subprocess import Popen, PIPE -from multiprocessing import Process, Lock -from queue import Queue, Empty -from ..utils.helpers import Singleton +import uuid from ..utils.execution_resources import persistent_process_semaphore +from ..utils.helpers import Singleton from .execution_manager_base import ExecutionManagerBase if sys.platform == "win32": diff --git a/spine_engine/execution_managers/process_execution_manager.py b/spine_engine/execution_managers/process_execution_manager.py index e2be5750..fcc013ce 100644 --- a/spine_engine/execution_managers/process_execution_manager.py +++ b/spine_engine/execution_managers/process_execution_manager.py @@ -15,11 +15,11 @@ """ -import sys import subprocess +import sys from threading import Thread -from .execution_manager_base import ExecutionManagerBase from ..utils.execution_resources import one_shot_process_semaphore +from .execution_manager_base import ExecutionManagerBase class ProcessExecutionManager(ExecutionManagerBase): diff --git a/spine_engine/execution_managers/spine_repl.py b/spine_engine/execution_managers/spine_repl.py index bdc5be17..e42e2e87 100644 --- a/spine_engine/execution_managers/spine_repl.py +++ b/spine_engine/execution_managers/spine_repl.py @@ -10,14 +10,14 @@ # this program. If not, see . ###################################################################################################################### -import socketserver +import code import socket +import socketserver import threading -import code try: - import readline import itertools + import readline _history_offset = -1 _history_saved_line = "" diff --git a/spine_engine/jumpster.py b/spine_engine/jumpster.py index a4466b99..ce55e09f 100644 --- a/spine_engine/jumpster.py +++ b/spine_engine/jumpster.py @@ -12,12 +12,13 @@ """ In-house dagster replacement that also handles jumps. """ +from collections import namedtuple +from enum import Enum, unique +import queue import sys import threading -import queue -from enum import Enum, unique -from collections import namedtuple -from .utils.helpers import serializable_error_info_from_exc_info, ExecutionDirection as ED +from .utils.helpers import ExecutionDirection as ED +from .utils.helpers import serializable_error_info_from_exc_info @unique diff --git a/spine_engine/project_item/connection.py b/spine_engine/project_item/connection.py index 26ef0f26..64d071cc 100644 --- a/spine_engine/project_item/connection.py +++ b/spine_engine/project_item/connection.py @@ -10,31 +10,26 @@ # this program. If not, see . ###################################################################################################################### """ Provides connection classes for linking project items. """ +from contextlib import ExitStack from dataclasses import asdict, dataclass, field +from multiprocessing import Lock import os import subprocess import tempfile -from contextlib import ExitStack -from multiprocessing import Lock from datapackage import Package -from spinedb_api import DatabaseMapping, SpineDBAPIError, SpineDBVersionError -from spinedb_api.filters.scenario_filter import SCENARIO_FILTER_TYPE -from spinedb_api.filters.alternative_filter import ALTERNATIVE_FILTER_TYPE -from spinedb_api.purge import purge_url from spine_engine.project_item.project_item_resource import ( - file_resource, - make_cmd_line_arg, expand_cmd_line_args, + file_resource, labelled_resource_args, + make_cmd_line_arg, ) -from spine_engine.utils.helpers import ( - resolve_current_python_interpreter, - ItemExecutionFinishState, - PartCount, - ExecutionDirection as ED, -) +from spine_engine.utils.helpers import ExecutionDirection as ED +from spine_engine.utils.helpers import ItemExecutionFinishState, PartCount, resolve_current_python_interpreter from spine_engine.utils.queue_logger import QueueLogger - +from spinedb_api import DatabaseMapping, SpineDBAPIError, SpineDBVersionError +from spinedb_api.filters.alternative_filter import ALTERNATIVE_FILTER_TYPE +from spinedb_api.filters.scenario_filter import SCENARIO_FILTER_TYPE +from spinedb_api.purge import purge_url SUPPORTED_FILTER_TYPES = {ALTERNATIVE_FILTER_TYPE, SCENARIO_FILTER_TYPE} diff --git a/spine_engine/project_item/project_item_resource.py b/spine_engine/project_item/project_item_resource.py index f2c60a37..25dcdc6e 100644 --- a/spine_engine/project_item/project_item_resource.py +++ b/spine_engine/project_item/project_item_resource.py @@ -10,15 +10,15 @@ # this program. If not, see . ###################################################################################################################### """ Provides the ProjectItemResource class. """ -import copy -import uuid from contextlib import contextmanager +import copy from pathlib import Path from urllib.parse import urlparse from urllib.request import url2pathname +import uuid from spinedb_api.filters.tools import clear_filter_configs -from spinedb_api.spine_db_server import closing_spine_db_server, quick_db_checkout from spinedb_api.spine_db_client import SpineDBClient +from spinedb_api.spine_db_server import closing_spine_db_server, quick_db_checkout from ..utils.helpers import PartCount diff --git a/spine_engine/project_item/project_item_specification.py b/spine_engine/project_item/project_item_specification.py index 7ce33f70..88050503 100644 --- a/spine_engine/project_item/project_item_specification.py +++ b/spine_engine/project_item/project_item_specification.py @@ -12,7 +12,7 @@ """Contains project item specification class.""" import json -from spine_engine.utils.helpers import shorten, gather_leaf_data +from spine_engine.utils.helpers import gather_leaf_data, shorten class ProjectItemSpecification: diff --git a/spine_engine/server/certificate_creator.py b/spine_engine/server/certificate_creator.py index c735f53a..1a5ecbb8 100644 --- a/spine_engine/server/certificate_creator.py +++ b/spine_engine/server/certificate_creator.py @@ -18,8 +18,8 @@ """ import os -import sys import shutil +import sys import zmq.auth diff --git a/spine_engine/server/engine_server.py b/spine_engine/server/engine_server.py index bf9bbe07..818992c8 100644 --- a/spine_engine/server/engine_server.py +++ b/spine_engine/server/engine_server.py @@ -13,24 +13,23 @@ """ Contains EngineServer class for running a Zero-MQ server with Spine Engine. """ +import enum +import ipaddress import json.decoder import os import queue -import time import threading -import ipaddress -import enum import uuid import zmq from zmq.auth.thread import ThreadAuthenticator -from spine_engine.server.util.server_message import ServerMessage -from spine_engine.server.request import Request -from spine_engine.server.remote_execution_service import RemoteExecutionService +from spine_engine.server.persistent_execution_service import PersistentExecutionService from spine_engine.server.ping_service import PingService from spine_engine.server.project_extractor_service import ProjectExtractorService -from spine_engine.server.project_retriever_service import ProjectRetrieverService -from spine_engine.server.persistent_execution_service import PersistentExecutionService from spine_engine.server.project_remover_service import ProjectRemoverService +from spine_engine.server.project_retriever_service import ProjectRetrieverService +from spine_engine.server.remote_execution_service import RemoteExecutionService +from spine_engine.server.request import Request +from spine_engine.server.util.server_message import ServerMessage class ServerSecurityModel(enum.Enum): diff --git a/spine_engine/server/persistent_execution_service.py b/spine_engine/server/persistent_execution_service.py index 9178ce73..2c67ba58 100644 --- a/spine_engine/server/persistent_execution_service.py +++ b/spine_engine/server/persistent_execution_service.py @@ -14,8 +14,8 @@ Contains a class for remote persistent execution manager related actions. """ -import threading import json +import threading import zmq from spine_engine.server.service_base import ServiceBase diff --git a/spine_engine/server/ping_service.py b/spine_engine/server/ping_service.py index 1b5fc8ff..f6599ec6 100644 --- a/spine_engine/server/ping_service.py +++ b/spine_engine/server/ping_service.py @@ -14,9 +14,9 @@ Contains a class for handling ping requests. """ -import threading import json -import zmq +import threading +import zmq # pylint: disable=unused-import from spine_engine.server.service_base import ServiceBase from spine_engine.server.util.server_message import ServerMessage diff --git a/spine_engine/server/project_extractor_service.py b/spine_engine/server/project_extractor_service.py index ed94b334..a8757f88 100644 --- a/spine_engine/server/project_extractor_service.py +++ b/spine_engine/server/project_extractor_service.py @@ -14,15 +14,15 @@ Contains a class for extracting a project ZIP file into a new directory on server. """ -import os import json +import os import threading import uuid -import zmq -from spine_engine.utils.helpers import get_file_size +import zmq # pylint: disable=unused-import from spine_engine.server.service_base import ServiceBase from spine_engine.server.util.server_message import ServerMessage from spine_engine.server.util.zip_handler import ZipHandler +from spine_engine.utils.helpers import get_file_size class ProjectExtractorService(threading.Thread, ServiceBase): diff --git a/spine_engine/server/project_remover_service.py b/spine_engine/server/project_remover_service.py index 3fa86f8a..4645878f 100644 --- a/spine_engine/server/project_remover_service.py +++ b/spine_engine/server/project_remover_service.py @@ -17,7 +17,7 @@ import os import shutil import threading -import zmq +import zmq # pylint: disable=unused-import from spine_engine.server.service_base import ServiceBase diff --git a/spine_engine/server/project_retriever_service.py b/spine_engine/server/project_retriever_service.py index e043115e..808f6589 100644 --- a/spine_engine/server/project_retriever_service.py +++ b/spine_engine/server/project_retriever_service.py @@ -14,14 +14,14 @@ Contains a class for sending a finished project back to client. """ +import json import os import shutil import threading -import json -import zmq -from spine_engine.utils.helpers import get_file_size +import zmq # pylint: disable=unused-import from spine_engine.server.service_base import ServiceBase from spine_engine.server.util.server_message import ServerMessage +from spine_engine.utils.helpers import get_file_size class ProjectRetrieverService(threading.Thread, ServiceBase): diff --git a/spine_engine/server/remote_execution_service.py b/spine_engine/server/remote_execution_service.py index 89bc71e6..fa026c5e 100644 --- a/spine_engine/server/remote_execution_service.py +++ b/spine_engine/server/remote_execution_service.py @@ -15,9 +15,9 @@ import threading import zmq from spine_engine import SpineEngine -from spine_engine.utils.helpers import get_file_size from spine_engine.server.service_base import ServiceBase from spine_engine.server.util.event_data_converter import EventDataConverter +from spine_engine.utils.helpers import get_file_size class RemoteExecutionService(threading.Thread, ServiceBase): diff --git a/spine_engine/spine_engine.py b/spine_engine/spine_engine.py index 336cbab0..8fe6b612 100644 --- a/spine_engine/spine_engine.py +++ b/spine_engine/spine_engine.py @@ -11,46 +11,46 @@ ###################################################################################################################### """ Contains the SpineEngine class for running Spine Toolbox DAGs. """ from enum import Enum, unique +from itertools import product +import multiprocessing as mp import os import threading -import multiprocessing as mp -from itertools import product import networkx as nx from spinedb_api import append_filter_config, name_from_dict -from spinedb_api.spine_db_server import db_server_manager -from spinedb_api.filters.tools import filter_config -from spinedb_api.filters.scenario_filter import scenario_name_from_dict from spinedb_api.filters.execution_filter import execution_filter_config +from spinedb_api.filters.scenario_filter import scenario_name_from_dict +from spinedb_api.filters.tools import filter_config +from spinedb_api.spine_db_server import db_server_manager from .exception import EngineInitFailed from .execution_managers.persistent_execution_manager import ( disable_persistent_process_creation, enable_persistent_process_creation, ) -from .utils.helpers import ( - AppSettings, - required_items_for_execution, - inverted, - create_timestamp, - make_dag, - ExecutionDirection as ED, - ItemExecutionFinishState, - dag_edges, - make_connections, -) -from .utils.execution_resources import one_shot_process_semaphore, persistent_process_semaphore -from .utils.queue_logger import QueueLogger -from .project_item_loader import ProjectItemLoader from .jumpster import ( - execute_pipeline_iterator, + Failure, + Finalization, + InputDefinition, JumpsterEventType, + Output, PipelineDefinition, SolidDefinition, - InputDefinition, - Output, - Failure, - Finalization, + execute_pipeline_iterator, ) from .project_item.connection import Connection, Jump +from .project_item_loader import ProjectItemLoader +from .utils.execution_resources import one_shot_process_semaphore, persistent_process_semaphore +from .utils.helpers import ( + ItemExecutionFinishState, + create_timestamp, + dag_edges, + inverted, + make_connections, + make_dag, + required_items_for_execution, +) +from .utils.helpers import AppSettings +from .utils.helpers import ExecutionDirection as ED +from .utils.queue_logger import QueueLogger @unique diff --git a/spine_engine/utils/helpers.py b/spine_engine/utils/helpers.py index 3894fd6e..1d95a1df 100644 --- a/spine_engine/utils/helpers.py +++ b/spine_engine/utils/helpers.py @@ -12,18 +12,18 @@ """Helper functions and classes.""" import collections -import os -import sys import datetime +from enum import Enum, auto, unique import itertools -import time import json +import os from pathlib import Path -from enum import Enum, auto, unique -import networkx +import sys +import time from jupyter_client.kernelspec import KernelSpecManager +import networkx from spinedb_api.spine_io.gdx_utils import find_gams_directory -from ..config import PYTHON_EXECUTABLE, JULIA_EXECUTABLE, GAMS_EXECUTABLE, EMBEDDED_PYTHON, is_frozen +from ..config import EMBEDDED_PYTHON, GAMS_EXECUTABLE, JULIA_EXECUTABLE, PYTHON_EXECUTABLE, is_frozen @unique diff --git a/spine_engine/utils/returning_process.py b/spine_engine/utils/returning_process.py index 43443599..8b35c7bc 100644 --- a/spine_engine/utils/returning_process.py +++ b/spine_engine/utils/returning_process.py @@ -15,10 +15,10 @@ """ -import multiprocessing as mp -import threading from contextlib import contextmanager from enum import Enum, auto, unique +import multiprocessing as mp +import threading from .execution_resources import one_shot_process_semaphore diff --git a/spine_engine/utils/serialization.py b/spine_engine/utils/serialization.py index 322ff4f2..e06d93b9 100644 --- a/spine_engine/utils/serialization.py +++ b/spine_engine/utils/serialization.py @@ -16,9 +16,9 @@ """ import os +from pathlib import Path import sys import urllib -from pathlib import Path from urllib.parse import urljoin diff --git a/tests/execution_managers/test_kernel_execution_manager.py b/tests/execution_managers/test_kernel_execution_manager.py index 8226d850..3af60df8 100644 --- a/tests/execution_managers/test_kernel_execution_manager.py +++ b/tests/execution_managers/test_kernel_execution_manager.py @@ -11,12 +11,12 @@ ###################################################################################################################### """Unit tests for ``kernel_execution_manager`` module.""" +from pathlib import Path +from tempfile import TemporaryDirectory import unittest from unittest.mock import MagicMock -from tempfile import TemporaryDirectory -from pathlib import Path -from spine_engine.execution_managers.kernel_execution_manager import KernelExecutionManager, _kernel_manager_factory from jupyter_client.kernelspec import NATIVE_KERNEL_NAME # =='python3' +from spine_engine.execution_managers.kernel_execution_manager import KernelExecutionManager, _kernel_manager_factory class TestKernelExecutionManager(unittest.TestCase): diff --git a/tests/execution_managers/test_process_execution_manager.py b/tests/execution_managers/test_process_execution_manager.py index b64d6178..2ce50af8 100644 --- a/tests/execution_managers/test_process_execution_manager.py +++ b/tests/execution_managers/test_process_execution_manager.py @@ -10,9 +10,9 @@ # this program. If not, see . ###################################################################################################################### """Unit tests for ``process_execution_manager`` module.""" +from tempfile import TemporaryDirectory import unittest from unittest.mock import MagicMock -from tempfile import TemporaryDirectory from spine_engine.execution_managers.process_execution_manager import ProcessExecutionManager diff --git a/tests/project_item/test_connection.py b/tests/project_item/test_connection.py index 67263f9b..a98bda53 100644 --- a/tests/project_item/test_connection.py +++ b/tests/project_item/test_connection.py @@ -14,9 +14,9 @@ from tempfile import TemporaryDirectory import unittest from unittest.mock import Mock -from spinedb_api import DatabaseMapping, import_entity_classes, import_scenarios, import_alternatives from spine_engine.project_item.connection import Connection, FilterSettings, Jump from spine_engine.project_item.project_item_resource import database_resource +from spinedb_api import DatabaseMapping, import_alternatives, import_entity_classes, import_scenarios from spinedb_api.filters.scenario_filter import SCENARIO_FILTER_TYPE diff --git a/tests/project_item/test_project_item_resource.py b/tests/project_item/test_project_item_resource.py index dced026b..64d17add 100644 --- a/tests/project_item/test_project_item_resource.py +++ b/tests/project_item/test_project_item_resource.py @@ -17,6 +17,7 @@ from unittest import mock from spine_engine.project_item.project_item_resource import ( CmdLineArg, + LabelArg, database_resource, expand_cmd_line_args, file_resource, @@ -24,7 +25,6 @@ get_labelled_source_resources, get_source, get_source_extras, - LabelArg, labelled_resource_args, transient_file_resource, url_resource, diff --git a/tests/server/test_EngineServer.py b/tests/server/test_EngineServer.py index ca85f5e5..8b269fd2 100644 --- a/tests/server/test_EngineServer.py +++ b/tests/server/test_EngineServer.py @@ -12,11 +12,11 @@ """ Unit tests for EngineServer class. """ +import os +import pathlib import threading import unittest import zmq -import os -import pathlib from spine_engine.server.engine_server import EngineServer, ServerSecurityModel from spine_engine.server.util.server_message import ServerMessage diff --git a/tests/server/test_PingService.py b/tests/server/test_PingService.py index d8a397d3..15a48e07 100644 --- a/tests/server/test_PingService.py +++ b/tests/server/test_PingService.py @@ -16,8 +16,8 @@ import unittest import zmq -from spine_engine.server.util.server_message import ServerMessage from spine_engine.server.engine_server import EngineServer, ServerSecurityModel +from spine_engine.server.util.server_message import ServerMessage class TestPingService(unittest.TestCase): diff --git a/tests/server/test_ProjectExtractorService.py b/tests/server/test_ProjectExtractorService.py index 713615dd..80a71adc 100644 --- a/tests/server/test_ProjectExtractorService.py +++ b/tests/server/test_ProjectExtractorService.py @@ -14,15 +14,15 @@ Unit tests for ProjectExtractorService class. """ -import unittest -import os import json +import os from pathlib import Path -from unittest import mock from tempfile import TemporaryDirectory +import unittest +from unittest import mock import zmq -from spine_engine.server.util.server_message import ServerMessage from spine_engine.server.engine_server import EngineServer, ServerSecurityModel +from spine_engine.server.util.server_message import ServerMessage class TestProjectExtractorService(unittest.TestCase): diff --git a/tests/server/test_ProjectRemoverService.py b/tests/server/test_ProjectRemoverService.py index 01e2a0c3..7f546ad6 100644 --- a/tests/server/test_ProjectRemoverService.py +++ b/tests/server/test_ProjectRemoverService.py @@ -14,13 +14,13 @@ Unit tests for ProjectRemoverService class. """ -import unittest -import os import json +import os from pathlib import Path +import unittest import zmq -from spine_engine.server.util.server_message import ServerMessage from spine_engine.server.engine_server import EngineServer, ServerSecurityModel +from spine_engine.server.util.server_message import ServerMessage class TestProjectRemoverService(unittest.TestCase): diff --git a/tests/server/test_start_server.py b/tests/server/test_start_server.py index f4812a04..2d3c316d 100644 --- a/tests/server/test_start_server.py +++ b/tests/server/test_start_server.py @@ -13,9 +13,9 @@ """ Unit tests for start_server.py script. """ -import unittest -import time from multiprocessing import Process +import time +import unittest from spine_engine.server.start_server import main diff --git a/tests/server/util/test_EventDataConverter.py b/tests/server/util/test_EventDataConverter.py index 90e7e275..7c0eacbc 100644 --- a/tests/server/util/test_EventDataConverter.py +++ b/tests/server/util/test_EventDataConverter.py @@ -11,10 +11,10 @@ ###################################################################################################################### """Unit tests for EventDataConverter class.""" -import unittest from copy import deepcopy -from spine_engine.spine_engine import ItemExecutionFinishState +import unittest from spine_engine.server.util.event_data_converter import EventDataConverter +from spine_engine.spine_engine import ItemExecutionFinishState from spine_engine.utils.helpers import ExecutionDirection diff --git a/tests/server/util/test_ServerMessage.py b/tests/server/util/test_ServerMessage.py index 5a2a9545..08d8d5a5 100644 --- a/tests/server/util/test_ServerMessage.py +++ b/tests/server/util/test_ServerMessage.py @@ -14,8 +14,8 @@ Unit tests for ServerMessage class. """ -import unittest import json +import unittest from spine_engine.server.util.server_message import ServerMessage diff --git a/tests/server/util/test_ZipHandler.py b/tests/server/util/test_ZipHandler.py index 0df4ae42..3f8128bb 100644 --- a/tests/server/util/test_ZipHandler.py +++ b/tests/server/util/test_ZipHandler.py @@ -14,9 +14,9 @@ Unit tests for FileExtractor class. """ -import unittest import os from pathlib import Path +import unittest from spine_engine.server.util.zip_handler import ZipHandler diff --git a/tests/test_load_project_items.py b/tests/test_load_project_items.py index f3486aa1..fbe33506 100644 --- a/tests/test_load_project_items.py +++ b/tests/test_load_project_items.py @@ -12,8 +12,8 @@ """Unit tests for `load_project_items` module.""" import os.path -import unittest import sys +import unittest from spine_engine.load_project_items import load_executable_item_classes, load_item_specification_factories from spine_engine.project_item.executable_item_base import ExecutableItemBase from spine_engine.project_item.project_item_specification_factory import ProjectItemSpecificationFactory diff --git a/tests/test_spine_engine.py b/tests/test_spine_engine.py index 4e2c0114..6228476a 100644 --- a/tests/test_spine_engine.py +++ b/tests/test_spine_engine.py @@ -21,16 +21,16 @@ from tempfile import TemporaryDirectory import unittest from unittest.mock import MagicMock, NonCallableMagicMock, call, patch -from spinedb_api import DatabaseMapping, import_scenarios -from spinedb_api.filters.scenario_filter import scenario_filter_config -from spinedb_api.filters.execution_filter import execution_filter_config -from spinedb_api.filters.tools import clear_filter_configs +from spine_engine import ExecutionDirection, ItemExecutionFinishState, SpineEngine, SpineEngineState from spine_engine.exception import EngineInitFailed +from spine_engine.project_item.connection import Connection, Jump +from spine_engine.project_item.project_item_resource import ProjectItemResource from spine_engine.spine_engine import validate_single_jump from spine_engine.utils.helpers import make_dag -from spine_engine import ExecutionDirection, SpineEngine, SpineEngineState, ItemExecutionFinishState -from spine_engine.project_item.connection import Jump, Connection -from spine_engine.project_item.project_item_resource import ProjectItemResource +from spinedb_api import DatabaseMapping, import_scenarios +from spinedb_api.filters.execution_filter import execution_filter_config +from spinedb_api.filters.scenario_filter import scenario_filter_config +from spinedb_api.filters.tools import clear_filter_configs def _make_url_resource(url): diff --git a/tests/utils/test_helpers.py b/tests/utils/test_helpers.py index ef8f41cc..ec268c6d 100644 --- a/tests/utils/test_helpers.py +++ b/tests/utils/test_helpers.py @@ -15,15 +15,15 @@ import unittest from unittest import mock from spine_engine.project_item.connection import Connection, FilterSettings -from spinedb_api.filters.scenario_filter import SCENARIO_FILTER_TYPE -from spinedb_api.helpers import remove_credentials_from_url from spine_engine.utils.helpers import ( - make_dag, gather_leaf_data, get_file_size, + make_dag, required_items_for_execution, resolve_python_interpreter, ) +from spinedb_api.filters.scenario_filter import SCENARIO_FILTER_TYPE +from spinedb_api.helpers import remove_credentials_from_url class TestRequiredItemsForExecution(unittest.TestCase): diff --git a/tests/utils/test_serialization.py b/tests/utils/test_serialization.py index e635ebab..9d891e35 100644 --- a/tests/utils/test_serialization.py +++ b/tests/utils/test_serialization.py @@ -14,12 +14,11 @@ Unit tests for serialization module. """ +from pathlib import Path import sys +from tempfile import NamedTemporaryFile, TemporaryDirectory, gettempdir import unittest -from pathlib import Path -from tempfile import gettempdir, TemporaryDirectory, NamedTemporaryFile - -from spine_engine.utils.serialization import deserialize_path, path_in_dir, serialize_url, serialize_path +from spine_engine.utils.serialization import deserialize_path, path_in_dir, serialize_path, serialize_url class TestSerialization(unittest.TestCase):