diff --git a/app/tests/dispatch/test_restart_job.py b/app/tests/dispatch/test_restart_job.py index 74cf76c..697f2a8 100644 --- a/app/tests/dispatch/test_restart_job.py +++ b/app/tests/dispatch/test_restart_job.py @@ -1,28 +1,28 @@ +import copy import json import os import time -import copy +import unittest +import uuid from pathlib import Path -from subprocess import CalledProcessError -import common.config as config +from typing import Callable, Tuple +import common.config as config import pytest -import uuid import routing import routing.generate_taskfile -import unittest - -import router +from common.constants import mercure_actions, mercure_names +from common.types import * +from dispatch.send import execute +from docker.models.containers import ContainerCollection # import processor from process import processor -from dispatch.send import execute, is_ready_for_sending -from docker.models.containers import ContainerCollection -from webinterface.queue import RestartTaskErrors, restart_dispatch -from common.constants import mercure_names, mercure_actions -from common.types import * -from tests.testing_common import mock_incoming_uid, mock_task_ids, make_fake_processor, mercure_config, FakeDockerContainer, mocked, bookkeeper_port -from typing import Tuple, Callable from pytest_mock import MockerFixture +from routing import router +from tests.testing_common import (FakeDockerContainer, bookkeeper_port, + make_fake_processor, mercure_config, + mock_incoming_uid, mock_task_ids, mocked) +from webinterface.queue import RestartTaskErrors, restart_dispatch logger = config.get_logger() @@ -192,9 +192,9 @@ def create_and_route(fs, mocked, task_id, config, uid="TESTFAKEUID") -> Tuple[Li mock_task_ids(mocked, task_id, new_task_id) # mocked.patch("routing.route_series.parse_ascconv", new=lambda x: {}) - routing.router.run_router() + router.run_router() - routing.router.route_series.assert_called_once_with(task_id, uid) # type: ignore + router.route_series.assert_called_once_with(task_id, uid) # type: ignore routing.route_series.push_series_serieslevel.assert_called_once_with(task_id, {"catchall": True}, [f"{uid}#bar"], uid, unittest.mock.ANY) # type: ignore routing.route_series.push_serieslevel_outgoing.assert_called_once_with(task_id, {"catchall": True}, [f"{uid}#bar"], uid, unittest.mock.ANY, {}) # type: ignore diff --git a/app/tests/dispatch/test_retry.py b/app/tests/dispatch/test_retry.py index ea3b165..7f7306a 100644 --- a/app/tests/dispatch/test_retry.py +++ b/app/tests/dispatch/test_retry.py @@ -1,8 +1,7 @@ import json -from dispatch.retry import increase_retry from common.constants import mercure_names - +from dispatch.retry import increase_retry dummy_info = { "action": "route", diff --git a/app/tests/dispatch/test_send.py b/app/tests/dispatch/test_send.py index 87e0dfa..1d89dd7 100644 --- a/app/tests/dispatch/test_send.py +++ b/app/tests/dispatch/test_send.py @@ -1,15 +1,12 @@ import json -import os import time from pathlib import Path from subprocess import CalledProcessError from unittest.mock import call -from common.monitor import m_events, task_event, severity -import pytest - -from dispatch.send import execute, is_ready_for_sending from common.constants import mercure_names +from common.monitor import m_events, severity, task_event +from dispatch.send import execute, is_ready_for_sending from tests.testing_common import * dummy_info = { diff --git a/app/tests/dispatch/test_status.py b/app/tests/dispatch/test_status.py index 91fbbbf..00bc105 100644 --- a/app/tests/dispatch/test_status.py +++ b/app/tests/dispatch/test_status.py @@ -1,8 +1,7 @@ import json -from common.types import Task -from dispatch.status import is_ready_for_sending, is_target_json_valid from common.constants import mercure_names +from dispatch.status import is_ready_for_sending, is_target_json_valid pytest_plugins = ("pyfakefs",) dummy_info = { diff --git a/app/tests/generate_dicoms.py b/app/tests/generate_dicoms.py index 70e074c..9f6aa8b 100644 --- a/app/tests/generate_dicoms.py +++ b/app/tests/generate_dicoms.py @@ -1,9 +1,9 @@ import itertools -import os from pathlib import Path -from pydicom.dataset import FileMetaDataset, Dataset -from pydicom.uid import generate_uid, ExplicitVRLittleEndian, CTImageStorage +from pydicom.dataset import Dataset, FileMetaDataset +from pydicom.uid import CTImageStorage, ExplicitVRLittleEndian, generate_uid + def generate_dicom_files(accession_number, destination_folder:Path, num_files=10, num_studies=2, num_series=2): """ diff --git a/app/tests/getdcmtags.py b/app/tests/getdcmtags.py index 12d00aa..e78742d 100644 --- a/app/tests/getdcmtags.py +++ b/app/tests/getdcmtags.py @@ -1,12 +1,12 @@ -import os -import sys +import argparse import json import shutil -import argparse +import sys +from pathlib import Path from typing import Dict, List, Optional, Tuple + import pydicom import requests -from pathlib import Path VERSION = "1.0" diff --git a/app/tests/test_bookkeeper.py b/app/tests/test_bookkeeper.py index 5cc4a81..e16963d 100644 --- a/app/tests/test_bookkeeper.py +++ b/app/tests/test_bookkeeper.py @@ -3,13 +3,13 @@ ================== """ import multiprocessing -from pathlib import Path import time -import testing_common -from testing_common import bookkeeper_port, mercure_config +from pathlib import Path import requests +import testing_common from bookkeeping import bookkeeper +from testing_common import bookkeeper_port, mercure_config # def run_server(app, port): # b.uvicorn.run(app, host="localhost", port=port) diff --git a/app/tests/test_cleaner.py b/app/tests/test_cleaner.py index 0e43298..f040777 100644 --- a/app/tests/test_cleaner.py +++ b/app/tests/test_cleaner.py @@ -2,17 +2,15 @@ test_cleaner.py =============== """ -from datetime import datetime, timedelta -from datetime import time -import shutil +from datetime import datetime, time, timedelta +from pathlib import Path -from freezegun import freeze_time -import cleaner as c +import cleaner import common.helper as helper +from freezegun import freeze_time from pyfakefs.fake_filesystem import FakeFilesystem -from pathlib import Path from testing_common import * -import cleaner + # helper func def _to_time(time) -> time: @@ -21,7 +19,7 @@ def _to_time(time) -> time: def test_cleaner_no_syntax_errors(): """Checks if cleaner.py can be started.""" - assert c + assert cleaner def test_is_not_offpeak(): diff --git a/app/tests/test_integration.py b/app/tests/test_integration.py index 8ee8e1b..906ae35 100644 --- a/app/tests/test_integration.py +++ b/app/tests/test_integration.py @@ -1,12 +1,11 @@ -from dataclasses import dataclass -import os -from pathlib import Path import time +from pathlib import Path + import pytest -from common.types import FolderTarget, Module, Rule, Target +from common.types import FolderTarget, Module, Rule +from testing_integration_common import * from tests.testing_common import create_minimal_dicom -from testing_integration_common import * @pytest.mark.parametrize("n_series",(2,)) @pytest.mark.skipif("os.getenv('TEST_FAST',False)") diff --git a/app/tests/test_notifications.py b/app/tests/test_notifications.py index 22c5b2d..10bde25 100644 --- a/app/tests/test_notifications.py +++ b/app/tests/test_notifications.py @@ -1,26 +1,23 @@ -import asyncio -from itertools import product -import time +import itertools import unittest -from unittest.mock import call +import unittest.mock import uuid -from pytest_mock import MockerFixture -from common import notification -import router -from process import processor -from dispatch import dispatcher +from collections.abc import Iterable +from itertools import product +from pathlib import Path +from typing import Callable, Iterator +from unittest.mock import call +import pytest +from common import notification from common.constants import mercure_events -from collections.abc import Iterable -from pprint import pprint from common.types import * -from pathlib import Path -from testing_common import * +from dispatch import dispatcher from docker.models.containers import ContainerCollection -import unittest.mock -import itertools -from typing import Iterator, Callable -import pytest +from process import processor +from pytest_mock import MockerFixture +from routing import router +from testing_common import * logger = config.get_logger() @@ -124,7 +121,7 @@ def generate_uuids() -> Iterator[str]: ) mock_incoming_uid(config, fs, uid) mocked.patch("uuid.uuid1", new=lambda: next(generator)) - routing.router.run_router() + router.run_router() if action=="notification": notification.trigger_notification_for_rule.assert_has_calls( # type: ignore [ diff --git a/app/tests/test_processor.py b/app/tests/test_processor.py index c0d0b7d..2708567 100644 --- a/app/tests/test_processor.py +++ b/app/tests/test_processor.py @@ -2,40 +2,33 @@ test_processor.py ============== """ -from typing import Tuple +import json import os import shutil +import socket import unittest -from unittest.mock import call import uuid -from pytest_mock import MockerFixture -import common -from common.monitor import task_event - - -from process import processor from itertools import permutations -from common.constants import mercure_version, mercure_names +from pathlib import Path +from typing import Callable, Tuple +from unittest.mock import call -import json -from common.types import * +import common import process.process_series -from routing import router +import pytest import routing.generate_taskfile -from pathlib import Path - -from testing_common import * -from testing_common import mock_task_ids - +from common.constants import mercure_names, mercure_version +from common.monitor import task_event +from common.types import * from docker.models.containers import ContainerCollection from docker.models.images import ImageCollection - from nomad.api.job import Job from nomad.api.jobs import Jobs -import socket - -from typing import Callable -import pytest +from process import processor +from pytest_mock import MockerFixture +from routing import router +from testing_common import * +from testing_common import mock_task_ids logger = config.get_logger() diff --git a/app/tests/test_pydantic.py b/app/tests/test_pydantic.py index ea20e80..e8febd0 100644 --- a/app/tests/test_pydantic.py +++ b/app/tests/test_pydantic.py @@ -3,8 +3,6 @@ ================== """ import bookkeeper as b - - import testing_common from testing_common import * diff --git a/app/tests/test_query.py b/app/tests/test_query.py index a19b273..a8a05d5 100644 --- a/app/tests/test_query.py +++ b/app/tests/test_query.py @@ -1,30 +1,30 @@ import json import os -from pathlib import Path import subprocess import tempfile +from logging import getLogger +from pathlib import Path from typing import Dict, Optional, Tuple + import pydicom -import pyfakefs import pytest -from pynetdicom import AE, evt, StoragePresentationContexts, build_role -from pynetdicom.sop_class import Verification, StudyRootQueryRetrieveInformationModelFind, StudyRootQueryRetrieveInformationModelGet,PatientRootQueryRetrieveInformationModelGet, CTImageStorage # type: ignore -from pynetdicom.status import Status -from pydicom.uid import generate_uid +from common.types import DicomTarget, DicomWebTarget, Rule +from fakeredis import FakeStrictRedis from pydicom.dataset import Dataset, FileMetaDataset -from rq import Worker +from pydicom.uid import ExplicitVRLittleEndian, generate_uid +from pynetdicom import AE, StoragePresentationContexts, evt +from pynetdicom.sop_class import (CTImageStorage, # type: ignore + PatientRootQueryRetrieveInformationModelGet, + StudyRootQueryRetrieveInformationModelFind, + StudyRootQueryRetrieveInformationModelGet, + Verification) +from pynetdicom.status import Status from routing import router +from rq import SimpleWorker, Worker +from testing_common import bookkeeper_port, mercure_config, receiver_port from webinterface.dashboards.query.jobs import GetAccessionTask, QueryPipeline from webinterface.dicom_client import SimpleDicomClient -from common.types import DicomTarget, DicomWebTarget, Rule -from webinterface.common import redis -from pydicom.uid import ExplicitVRLittleEndian, ImplicitVRLittleEndian -from testing_common import receiver_port, mercure_config, bookkeeper_port -from logging import getLogger -from rq import SimpleWorker, Queue, Connection -from fakeredis import FakeStrictRedis - getLogger('pynetdicom').setLevel('WARNING') # Mock data for testing MOCK_ACCESSIONS = ["1","2","3"] diff --git a/app/tests/test_router.py b/app/tests/test_router.py index 59af46e..7905234 100644 --- a/app/tests/test_router.py +++ b/app/tests/test_router.py @@ -2,30 +2,22 @@ test_router.py ============== """ -import importlib +import json import os -import stat +import unittest +import uuid +from pathlib import Path from typing import Tuple from unittest.mock import call -import json -from pprint import pprint -import uuid -import pytest -from common.helper import FileLock -from common.monitor import m_events, task_event, severity -from common.types import * import common -from pyfakefs.fake_filesystem import FakeFilesystem -from pyfakefs import fake_filesystem import routing.generate_taskfile +from common.monitor import m_events, severity, task_event +from common.types import * from dispatch import dispatcher +from pyfakefs.fake_filesystem import FakeFilesystem from routing import router -from pathlib import Path -import unittest - from testing_common import * - from testing_common import mock_task_ids # import common.config as config diff --git a/app/tests/test_studies.py b/app/tests/test_studies.py index b6eeeb4..7dfdae3 100644 --- a/app/tests/test_studies.py +++ b/app/tests/test_studies.py @@ -1,29 +1,20 @@ import asyncio -from datetime import datetime, timedelta -import importlib - -from typing import Tuple -from pprint import pprint import unittest import uuid +from datetime import timedelta +from pathlib import Path +from typing import Tuple import pytest -from common import helper +from common import notification from common.constants import mercure_events, mercure_names from common.types import * -from common import notification -import common +from freezegun import freeze_time +from nomad.api.job import Job +from process import processor from pyfakefs.fake_filesystem import FakeFilesystem -from pyfakefs import fake_filesystem -import routing.generate_taskfile - from routing import router -from process import processor - -from pathlib import Path -from freezegun import freeze_time from testing_common import * -from nomad.api.job import Job def create_series(mocked, fs, config, study_uid, series_uid, series_description, study_description="") -> Tuple[str, str]: diff --git a/app/tests/testing_common.py b/app/tests/testing_common.py index 82c9111..fd747b3 100644 --- a/app/tests/testing_common.py +++ b/app/tests/testing_common.py @@ -4,26 +4,28 @@ """ import json import os -from pathlib import Path import shutil import socket -from typing import Callable, Dict, Any, Iterator, List, Optional, Tuple import uuid +from pathlib import Path +from typing import Any, Callable, Dict, Iterator, Optional, Tuple import pydicom + pydicom.config.settings.reading_validation_mode = pydicom.config.IGNORE pydicom.config.settings.writing_validation_mode = pydicom.config.IGNORE -from pydicom.dataset import Dataset, FileDataset, FileMetaDataset -from pydicom.uid import generate_uid - -import pytest -import routing, common, process, bookkeeping +import bookkeeping +import common import common.config as config -from common.types import Config import docker.errors - +import process +import pytest +import routing +from common.types import Config +from pydicom.dataset import Dataset, FileDataset, FileMetaDataset +from pydicom.uid import generate_uid from tests.getdcmtags import process_dicom diff --git a/app/tests/testing_integration_common.py b/app/tests/testing_integration_common.py index 27d0e61..a0bdee3 100644 --- a/app/tests/testing_integration_common.py +++ b/app/tests/testing_integration_common.py @@ -1,26 +1,25 @@ -from dataclasses import dataclass import json import multiprocessing import os -from pathlib import Path +import socket import subprocess import sys +import tempfile import threading import time -from typing import Any, Callable, Dict, Generator, Optional +import xmlrpc.client +from dataclasses import dataclass +from pathlib import Path +from typing import Any, Callable, Generator, Optional + +import pydicom import pytest import requests -from supervisor.supervisord import Supervisor -from supervisor.states import RUNNING_STATES +from common.config import mercure_defaults from supervisor.options import ServerOptions +from supervisor.states import RUNNING_STATES +from supervisor.supervisord import Supervisor from supervisor.xmlrpc import SupervisorTransport -import xmlrpc.client -import tempfile -from common.config import mercure_defaults -import pydicom -import socket -import tempfile - # current workding directory here = os.path.abspath(os.getcwd())