Skip to content

Commit

Permalink
added cs internal/external for mutable datasets in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tclose committed Oct 16, 2024
1 parent 02edc38 commit 2d4abaf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
22 changes: 15 additions & 7 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,14 @@ def frametree_home() -> Path:
}

GOOD_DATASETS = ["basic.api", "multi.api", "basic.cs", "multi.cs"]
MUTABLE_DATASETS = ["basic.api", "multi.api", "basic.cs", "multi.cs"]
MUTABLE_DATASETS = [
"basic.api",
"multi.api",
"basic.cs",
"multi.cs",
"basic.cs_internal",
"multi.cs_internal",
]

# ------------------------------------
# Pytest fixtures and helper functions
Expand All @@ -321,8 +328,8 @@ def static_dataset(
xnat_archive_dir: Path,
source_data: Path,
run_prefix: str,
request,
):
request: pytest.FixtureRequest,
) -> FrameSet:
"""Creates a static dataset to can be reused between unittests and save setup
times"""
dataset_id, access_method = request.param.split(".")
Expand All @@ -347,8 +354,8 @@ def dataset(
xnat_archive_dir: Path,
source_data: Path,
run_prefix: str,
request,
):
request: pytest.FixtureRequest,
) -> FrameSet:
"""Creates a dataset that can be mutated (as its name is unique to the function)"""
dataset_id, access_method = request.param.split(".")
blueprint = TEST_XNAT_DATASET_BLUEPRINTS[dataset_id]
Expand All @@ -371,7 +378,7 @@ def dataset(


@pytest.fixture
def simple_dataset(xnat_repository, work_dir, run_prefix):
def simple_dataset(xnat_repository: Xnat, work_dir: Path, run_prefix: str) -> FrameSet:
blueprint = TestXnatDatasetBlueprint(
dim_lengths=[1, 1, 1],
scans=[
Expand All @@ -392,7 +399,7 @@ def access_dataset(
xnat_archive_dir: Path,
run_prefix: str,
) -> FrameSet:
if access_method == "cs":
if access_method.startswith("cs"):
proj_dir = xnat_archive_dir / project_id / "arc001"
store = XnatViaCS(
server=xnat_repository.server,
Expand All @@ -402,6 +409,7 @@ def access_dataset(
row_frequency=Clinical.constant,
input_mount=proj_dir,
output_mount=Path(mkdtemp()),
internal_upload=access_method.endswith("internal"),
)
store.save(name=f"testxnatcs{run_prefix}")
elif access_method == "api":
Expand Down
8 changes: 6 additions & 2 deletions frametree/xnat/tests/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,14 @@ def test_post(dataset: FrameSet, source_data: Path, caplog):
row = next(iter(dataset.rows(deriv_bp.row_frequency)))
with caplog.at_level(logging.INFO, logger="frametree"):
row[deriv_bp.path] = item
method_str = "direct" if type(dataset.store) is XnatViaCS else "api"
method_str = "direct" if isinstance(dataset.store, XnatViaCS) else "api"
assert f"{method_str} access" in caplog.text.lower()

access_method = "cs" if type(dataset.store) is XnatViaCS else "api"
access_method = (
"cs"
if (isinstance(dataset.store, XnatViaCS) and dataset.store.internal_upload)
else "api"
)

def check_inserted():
for deriv_bp in blueprint.derivatives:
Expand Down

0 comments on commit 2d4abaf

Please sign in to comment.