init_test.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. def __init__(self, path: str) -> None:
  46. super().__init__(path=path)
  47. @property
  48. def absolute_path(self):
  49. return super().absolute_path
  50. def test_volume_file_abstractmethod():
  51. volume_file = DummyVolumeFile(path="dummy")
  52. with pytest.raises(NotImplementedError):
  53. assert volume_file.absolute_path
  54. class DummySubfieldVolumeFile(SubfieldVolumeFile):
  55. # pylint: disable=useless-super-delegation
  56. def __init__(self, path: str) -> None:
  57. super().__init__(path=path)
  58. @property
  59. def absolute_path(self):
  60. return super().absolute_path
  61. def read_volumes_mm3(self):
  62. return super().read_volumes_mm3()
  63. def read_volumes_dataframe(self):
  64. return super().read_volumes_dataframe()
  65. def test_subfield_volume_file_abstractmethod():
  66. volume_file = DummySubfieldVolumeFile(path="subfield-dummy")
  67. with pytest.raises(NotImplementedError):
  68. assert volume_file.absolute_path
  69. with pytest.raises(NotImplementedError):
  70. volume_file.read_volumes_mm3()
  71. with pytest.raises(NotImplementedError):
  72. volume_file.read_volumes_dataframe()