Skip to content

Commit

Permalink
cleanup test imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy Wiggins authored and Roy Wiggins committed Dec 6, 2024
1 parent 4d17c57 commit 2af6333
Show file tree
Hide file tree
Showing 17 changed files with 121 additions and 157 deletions.
32 changes: 16 additions & 16 deletions app/tests/dispatch/test_restart_job.py
Original file line number Diff line number Diff line change
@@ -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()

Expand Down Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions app/tests/dispatch/test_retry.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
7 changes: 2 additions & 5 deletions app/tests/dispatch/test_send.py
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
3 changes: 1 addition & 2 deletions app/tests/dispatch/test_status.py
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
6 changes: 3 additions & 3 deletions app/tests/generate_dicoms.py
Original file line number Diff line number Diff line change
@@ -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):
"""
Expand Down
8 changes: 4 additions & 4 deletions app/tests/getdcmtags.py
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
6 changes: 3 additions & 3 deletions app/tests/test_bookkeeper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 6 additions & 8 deletions app/tests/test_cleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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():
Expand Down
9 changes: 4 additions & 5 deletions app/tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -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)")
Expand Down
33 changes: 15 additions & 18 deletions app/tests/test_notifications.py
Original file line number Diff line number Diff line change
@@ -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()

Expand Down Expand Up @@ -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
[
Expand Down
37 changes: 15 additions & 22 deletions app/tests/test_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 0 additions & 2 deletions app/tests/test_pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
==================
"""
import bookkeeper as b


import testing_common
from testing_common import *

Expand Down
30 changes: 15 additions & 15 deletions app/tests/test_query.py
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
22 changes: 7 additions & 15 deletions app/tests/test_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 2af6333

Please sign in to comment.