init_test.py 2.1 KB

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