Skip to content

Commit

Permalink
Merge pull request #18 from Australian-Imaging-Service/lazy-mi4tests-…
Browse files Browse the repository at this point in the history
…imports

Lazy loading of medimages4tests imports
  • Loading branch information
tclose authored Oct 16, 2024
2 parents 3c247bb + f533e44 commit 325b778
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
4 changes: 3 additions & 1 deletion tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ def test_launch(config, launched_xnat):
login.put(f"/data/archive/projects/{PROJECT}")

# Create subject
xsubject = login.classes.SubjectData(label=SUBJECT, parent=login.projects[PROJECT])
xsubject = login.classes.SubjectData(
label=SUBJECT, parent=login.projects[PROJECT]
)
# Create session
xsession = login.classes.MrSessionData(label=SESSION, parent=xsubject)

Expand Down
4 changes: 2 additions & 2 deletions xnat4tests/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ def restart_cli(ctx, loglevel):

@cli.command(
name="add-data",
help="""Adds sample data to the XNAT instance
help=f"""Adds sample data to the XNAT instance
DATASET is the name of the dataset to add (out of ['dummydicom'])""",
DATASET is the name of the dataset to add (out of {AVAILABLE_DATASETS})""",
)
@click.argument("dataset", type=click.Choice(AVAILABLE_DATASETS))
@click.option(
Expand Down
23 changes: 13 additions & 10 deletions xnat4tests/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@
from contextlib import contextmanager
from pathlib import Path
from xnat.exceptions import XNATResponseError
from medimages4tests.dummy.dicom.mri.t1w.siemens.skyra.syngo_d13c import (
get_image as t1w_syngo,
)
from medimages4tests.dummy.dicom.mri.dwi.siemens.skyra.syngo_d13c import (
get_image as dwi_syngo,
)
from medimages4tests.dummy.dicom.mri.fmap.siemens.skyra.syngo_d13c import (
get_image as fmap_syngo,
)
from medimages4tests.mri.neuro.t1w import get_image as openneuro_t1w
from .base import connect
from .config import Config
from .utils import logger
Expand Down Expand Up @@ -64,6 +54,15 @@ def add_data(dataset: str, config_name: str or dict = "default"):
)

if dataset == "dummydicom":
from medimages4tests.dummy.dicom.mri.t1w.siemens.skyra.syngo_d13c import (
get_image as t1w_syngo,
)
from medimages4tests.dummy.dicom.mri.dwi.siemens.skyra.syngo_d13c import (
get_image as dwi_syngo,
)
from medimages4tests.dummy.dicom.mri.fmap.siemens.skyra.syngo_d13c import (
get_image as fmap_syngo,
)

_upload_dicom_data(
[t1w_syngo(), dwi_syngo(), fmap_syngo()],
Expand All @@ -74,6 +73,7 @@ def add_data(dataset: str, config_name: str or dict = "default"):
)

elif dataset == "openneuro-t1w":
from medimages4tests.mri.neuro.t1w import get_image as openneuro_t1w

_upload_directly(
{"t1w": openneuro_t1w()},
Expand Down Expand Up @@ -119,6 +119,9 @@ def add_data(dataset: str, config_name: str or dict = "default"):
)

elif dataset == "user-training":
from medimages4tests.dummy.dicom.mri.fmap.siemens.skyra.syngo_d13c import (
get_image as fmap_syngo,
)

_upload_dicom_data(
[t1w_syngo(), fmap_syngo()],
Expand Down
6 changes: 3 additions & 3 deletions xnat4tests/registry.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import docker
import docker.models.containers
from .utils import logger
from .config import Config
from .base import docker_network, connect


def start_registry(config_name="default"):
def start_registry(config_name: str = "default") -> docker.models.containers.Container:

config = Config.load(config_name)

Expand Down Expand Up @@ -38,7 +38,7 @@ def start_registry(config_name="default"):
return container


def stop_registry(config_name="default"):
def stop_registry(config_name: str = "default") -> None:

config = Config.load(config_name)

Expand Down

0 comments on commit 325b778

Please sign in to comment.