init_test.py 2.0 KB

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