-
Notifications
You must be signed in to change notification settings - Fork 52
Integration test for run_dicom_archive_loader.py
#1203
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
Merged
maximemulder
merged 15 commits into
aces:main
from
maximemulder:2024-10-18_integration-s3
Dec 17, 2024
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ad95ef1
add s3fs in docker
maximemulder 2d97ec0
add integration test
maximemulder 81ef042
put keys in github repo
maximemulder 15e1b88
debugging
maximemulder d8f06d8
add database check
maximemulder d9249a5
add comments and debugging
maximemulder 74ed087
remove s3 keys
maximemulder 47ca475
change converter in test
maximemulder e649bcd
check file tree
maximemulder fd78e0d
fix doc
maximemulder 97b61ad
fix docs 2
maximemulder c192ce4
rename variable
maximemulder ab73d05
go back to using s3 keys
maximemulder 8bc17a6
fix path
maximemulder 8bf736f
try fix
maximemulder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
python/tests/integration/scripts/test_run_dicom_archive_loader.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import subprocess | ||
|
||
from lib.db.query.config import set_config_with_setting_name | ||
from lib.db.query.mri_upload import get_mri_upload_with_patient_name | ||
from tests.util.database import get_integration_database_session | ||
from tests.util.file_system import check_file_tree | ||
|
||
|
||
def test(): | ||
db = get_integration_database_session() | ||
|
||
# Set the configuration to use the DICOM to BIDS pipeline | ||
set_config_with_setting_name(db, 'converter', 'dcm2niix') | ||
db.commit() | ||
|
||
# Run the script to test | ||
process = subprocess.run([ | ||
'run_dicom_archive_loader.py', | ||
'--profile', 'database_config.py', | ||
'--tarchive_path', '/data/loris/tarchive/DCM_2015-07-07_ImagingUpload-14-30-FoTt1K.tar', | ||
], capture_output=True) | ||
|
||
# Print the standard output and error for debugging | ||
print(f'STDOUT:\n{process.stdout.decode()}') | ||
print(f'STDERR:\n{process.stderr.decode()}') | ||
|
||
# Check that the return code and standard error are correct | ||
assert process.returncode == 0 | ||
assert process.stderr == b'' | ||
|
||
# Check that the expected files have been created | ||
assert check_file_tree('/data/loris/assembly_bids', { | ||
'sub-300001': { | ||
'ses-V2': { | ||
'anat': { | ||
'sub-300001_ses-V2_run-1_T1w.json': None, | ||
'sub-300001_ses-V2_run-1_T1w.nii.gz': None, | ||
} | ||
} | ||
} | ||
}) | ||
|
||
# Check that the expected data has been inserted in the database | ||
mri_upload = get_mri_upload_with_patient_name(db, 'MTL001_300001_V2') | ||
assert mri_upload.session is not None | ||
assert len(mri_upload.session.files) == 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import os | ||
|
||
FileTree = dict[str, 'FileTree'] | None | ||
""" | ||
Type that represents a file hierarchy relative to a path. | ||
- `None` means that the path refers to a file. | ||
- `dict[str, FileTree]` means that the path refers to a directory, with the entries of the | ||
dictionary as sub-trees. | ||
""" | ||
|
||
|
||
def check_file_tree(path: str, file_tree: FileTree): | ||
""" | ||
Check that a path has at least all the directories and files of a file tree. | ||
""" | ||
|
||
if file_tree is None: | ||
return os.path.isfile(path) | ||
|
||
if not os.path.isdir(path): | ||
return False | ||
|
||
for sub_dir_name, sub_file_tree in file_tree.items(): | ||
sub_dir_path = os.path.join(path, sub_dir_name) | ||
if not check_file_tree(sub_dir_path, sub_file_tree): | ||
return False | ||
|
||
return True |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
# Create a writable directory with links to the imaging dataset files | ||
replicate_raisinbread_for_mcin_dev_vm.pl /data-imaging /data/loris | ||
|
||
# Run the provided command (usually the integration test command) | ||
exec "$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.