init_test.py 2.6 KB

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