diff --git a/scripts/add_data.py b/scripts/add_data.py index 6bd0cb7..01ed908 100644 --- a/scripts/add_data.py +++ b/scripts/add_data.py @@ -2,4 +2,4 @@ from xnat4tests.data import add_data start_xnat() -add_data("user-training") +add_data("simple-dir") diff --git a/tests/test_data.py b/tests/test_data.py index 181ddc6..5b0a90c 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -44,3 +44,29 @@ def test_add_nifti(config, launched_xnat): assert sorted(s.type for s in xsess2.scans.values()) == [ "t1w", ] + + +def test_simple_dir(config, launched_xnat): + + add_data("simple-dir", config_name=config) + + with connect(config) as login: + xsess1 = ( + login.projects["SIMPLE_DIR"] + .subjects["subject01"] + .experiments["subject01_1"] + ) + + assert sorted(s.type for s in xsess1.scans.values()) == [ + "a-directory", + ] + + xsess2 = ( + login.projects["SIMPLE_DIR"] + .subjects["subject02"] + .experiments["subject02_1"] + ) + + assert sorted(s.type for s in xsess2.scans.values()) == [ + "a-directory", + ] diff --git a/xnat4tests/data.py b/xnat4tests/data.py index db4a6ba..7c0a7bd 100644 --- a/xnat4tests/data.py +++ b/xnat4tests/data.py @@ -81,6 +81,7 @@ def add_data(dataset: str, config_name: str or dict = "default"): project_id="OPENNEURO_T1W", subject_id="subject01", session_id="subject01_MR01", + resource_name="NIFTI", ) _upload_directly( {"t1w": openneuro_t1w()}, @@ -88,29 +89,33 @@ def add_data(dataset: str, config_name: str or dict = "default"): project_id="OPENNEURO_T1W", subject_id="subject02", session_id="subject02_MR01", + resource_name="NIFTI", ) elif dataset == "simple-dir": tmp_dir = Path(tempfile.mkdtemp()) a_dir = tmp_dir / "a-dir" + a_dir.mkdir() for i in range(3): a_file = a_dir / f"file{i + 1}.txt" - a_file.write_text("A dummy file - {i}\n") + a_file.write_text(f"A dummy file - {i + 1}\n") _upload_directly( {"a-directory": a_dir}, config, - project_id="SIMPLEDIR", + project_id="SIMPLE_DIR", subject_id="subject01", session_id="subject01_1", + resource_name="DIRECTORY", ) _upload_directly( {"a-directory": a_dir}, config, - project_id="SIMPLEDIR", + project_id="SIMPLE_DIR", subject_id="subject02", session_id="subject02_1", + resource_name="DIRECTORY", ) elif dataset == "user-training": @@ -186,7 +191,7 @@ def add_data(dataset: str, config_name: str or dict = "default"): def _upload_dicom_data( - to_upload: Path or ty.List[Path] or str, + to_upload: ty.Union[Path, ty.List[Path], str], config: dict, project_id: str, subject_id: str, @@ -281,6 +286,7 @@ def _upload_directly( project_id: str, subject_id: str, session_id: str, + resource_name: str, ): with connect(config) as login: @@ -325,6 +331,6 @@ def _upload_directly( for i, (scan_type, fspath) in enumerate(to_upload.items(), start=1): xdataset = login.classes.MrScanData(id=i, type=scan_type, parent=xsession) resource = xdataset.create_resource( - "NIFTI" + resource_name ) # TODO get this resource name from somewhere else resource.upload_dir(fspath.parent, method="tar_file")