init_test.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import pytest
  2. from freesurfer_volume_reader import \
  3. __version__, parse_version_string, remove_group_names_from_regex, \
  4. VolumeFile, SubfieldVolumeFile
  5. def test_module_version():
  6. assert len(__version__) >= len('0.1.0')
  7. @pytest.mark.parametrize(('version_string', 'expected_tuple'), [
  8. ('0.24.2', (0, 24, 2)),
  9. ('0.21.0', (0, 21, 0)),
  10. ('0.2.2.dev28+g526f05c.d20190504', (0, 2, 2, 'dev28+g526f05c', 'd20190504')),
  11. ])
  12. def test_parse_version_string(version_string, expected_tuple):
  13. assert expected_tuple == parse_version_string(version_string)
  14. def test_parse_version_string_comparison():
  15. assert parse_version_string('0.24.2') == (0, 24, 2)
  16. assert parse_version_string('0.24.2') < (0, 25)
  17. assert parse_version_string('0.24.2') < (0, 24, 3)
  18. assert parse_version_string('0.24.2') <= (0, 24, 2)
  19. assert parse_version_string('0.24.2') >= (0, 24, 2)
  20. assert parse_version_string('0.24.2') > (0, 24, 1)
  21. assert parse_version_string('0.24.2') > (0, 24)
  22. assert parse_version_string('0.2.2.dev28+g526f05c.d20190504') > (0, 2, 2)
  23. assert parse_version_string('0.2.2.dev28+g526f05c.d20190504') < (0, 2, 3)
  24. @pytest.mark.parametrize(('source_pattern', 'expected_pattern'), [
  25. (r'^(?P<h>[lr])h\.hippoSfVolumes', r'^([lr])h\.hippoSfVolumes'),
  26. (r'(?P<a>a(?P<b>b))', r'(a(b))'),
  27. ])
  28. def test_remove_group_names_from_regex(source_pattern, expected_pattern):
  29. assert expected_pattern == remove_group_names_from_regex(regex_pattern=source_pattern)
  30. class DummyVolumeFile(VolumeFile):
  31. # pylint: disable=useless-super-delegation
  32. @property
  33. def absolute_path(self):
  34. return super().absolute_path
  35. def test_volume_file_abstractmethod():
  36. volume_file = DummyVolumeFile()
  37. with pytest.raises(NotImplementedError):
  38. assert volume_file.absolute_path
  39. class DummySubfieldVolumeFile(SubfieldVolumeFile):
  40. # pylint: disable=useless-super-delegation
  41. @property
  42. def absolute_path(self):
  43. return super().absolute_path
  44. def read_volumes_mm3(self):
  45. return super().read_volumes_mm3()
  46. def read_volumes_dataframe(self):
  47. return super().read_volumes_dataframe()
  48. def test_subfield_volume_file_abstractmethod():
  49. volume_file = DummySubfieldVolumeFile()
  50. with pytest.raises(NotImplementedError):
  51. assert volume_file.absolute_path
  52. with pytest.raises(NotImplementedError):
  53. volume_file.read_volumes_mm3()
  54. with pytest.raises(NotImplementedError):
  55. volume_file.read_volumes_dataframe()