init_test.py 2.9 KB

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