Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy loading of medimages4tests imports #18

Merged
merged 4 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading