freesurfer_test.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import os
  2. import re
  3. import pytest
  4. from freesurfer_volume_reader.freesurfer import HippocampalSubfieldsVolumeFile
  5. SUBJECTS_DIR = os.path.join(os.path.dirname(__file__), 'subjects')
  6. @pytest.mark.parametrize(('root_dir_path', 'expected_file_paths'), [
  7. (SUBJECTS_DIR,
  8. {os.path.join(SUBJECTS_DIR, 'alice', 'mri', 'lh.hippoSfVolumes-T1.v10.txt'),
  9. os.path.join(SUBJECTS_DIR, 'bert', 'mri', 'lh.hippoSfVolumes-T1-T2.v10.txt'),
  10. os.path.join(SUBJECTS_DIR, 'bert', 'mri', 'lh.hippoSfVolumes-T1.v10.txt')}),
  11. (os.path.join(SUBJECTS_DIR, 'bert'),
  12. {os.path.join(SUBJECTS_DIR, 'bert', 'mri', 'lh.hippoSfVolumes-T1-T2.v10.txt'),
  13. os.path.join(SUBJECTS_DIR, 'bert', 'mri', 'lh.hippoSfVolumes-T1.v10.txt')}),
  14. (os.path.join(SUBJECTS_DIR, 'bert', 'mri'),
  15. {os.path.join(SUBJECTS_DIR, 'bert', 'mri', 'lh.hippoSfVolumes-T1-T2.v10.txt'),
  16. os.path.join(SUBJECTS_DIR, 'bert', 'mri', 'lh.hippoSfVolumes-T1.v10.txt')}),
  17. ])
  18. def test_find_hippocampal_volume_files(root_dir_path, expected_file_paths):
  19. assert expected_file_paths == set(
  20. HippocampalSubfieldsVolumeFile.find(root_dir_path=root_dir_path))
  21. @pytest.mark.parametrize(('root_dir_path', 'filename_pattern', 'expected_file_paths'), [
  22. (SUBJECTS_DIR,
  23. r'hippoSfVolumes-T1\.v10',
  24. {os.path.join(SUBJECTS_DIR, 'alice', 'mri', 'lh.hippoSfVolumes-T1.v10.txt'),
  25. os.path.join(SUBJECTS_DIR, 'bert', 'mri', 'lh.hippoSfVolumes-T1.v10.txt')}),
  26. (os.path.join(SUBJECTS_DIR, 'bert'),
  27. r'hippoSfVolumes-T1-T2',
  28. {os.path.join(SUBJECTS_DIR, 'bert', 'mri', 'lh.hippoSfVolumes-T1-T2.v10.txt')}),
  29. ])
  30. def test_find_hippocampal_volume_files_pattern(root_dir_path, filename_pattern,
  31. expected_file_paths):
  32. assert expected_file_paths == set(HippocampalSubfieldsVolumeFile.find(
  33. root_dir_path=root_dir_path, filename_regex=re.compile(filename_pattern)))