ashs_test.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import os
  2. import pytest
  3. from freesurfer_volume_reader.ashs import HippocampalSubfieldsVolumeFile
  4. @pytest.mark.parametrize(('volume_file_path', 'expected_attrs'), [
  5. ('ashs/final/bert_left_heur_volumes.txt',
  6. {'subject': 'bert', 'hemisphere': 'left', 'correction': None}),
  7. ('ashs/final/bert_left_corr_nogray_volumes.txt',
  8. {'subject': 'bert', 'hemisphere': 'left', 'correction': 'nogray'}),
  9. ('ashs/final/bert_left_corr_usegray_volumes.txt',
  10. {'subject': 'bert', 'hemisphere': 'left', 'correction': 'usegray'}),
  11. ('ashs/final/bert_right_heur_volumes.txt',
  12. {'subject': 'bert', 'hemisphere': 'right', 'correction': None}),
  13. ('ashs/final/bert_right_corr_nogray_volumes.txt',
  14. {'subject': 'bert', 'hemisphere': 'right', 'correction': 'nogray'}),
  15. ('ashs/final/bert_right_corr_usegray_volumes.txt',
  16. {'subject': 'bert', 'hemisphere': 'right', 'correction': 'usegray'}),
  17. ('somewhere/else/bert_right_heur_volumes.txt',
  18. {'subject': 'bert', 'hemisphere': 'right', 'correction': None}),
  19. ('somewhere/else/bert_right_corr_nogray_volumes.txt',
  20. {'subject': 'bert', 'hemisphere': 'right', 'correction': 'nogray'}),
  21. ('bert_right_heur_volumes.txt',
  22. {'subject': 'bert', 'hemisphere': 'right', 'correction': None}),
  23. ('/foo/bar/alice_20190503_right_corr_nogray_volumes.txt',
  24. {'subject': 'alice_20190503', 'hemisphere': 'right', 'correction': 'nogray'}),
  25. ])
  26. def test_hippocampal_subfields_volume_file_init(volume_file_path, expected_attrs):
  27. volume_file = HippocampalSubfieldsVolumeFile(path=volume_file_path)
  28. assert os.path.abspath(volume_file_path) == volume_file.absolute_path
  29. for attr, value in expected_attrs.items():
  30. assert value == getattr(volume_file, attr)
  31. @pytest.mark.parametrize('volume_file_path', [
  32. 'bert_middle_heur_volumes.txt',
  33. 'bert_right_hear_volumes.txt',
  34. 'bert_right_heur_volumes.nii',
  35. 'bert_left_lfseg_corr_usegray.nii.gz',
  36. ])
  37. def test_hippocampal_subfields_volume_file_init_invalid(volume_file_path):
  38. with pytest.raises(Exception):
  39. HippocampalSubfieldsVolumeFile(path=volume_file_path)