test_setlocale.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # freesurfer-surface - Read and Write Surface Files in Freesurfer’s TriangularSurface Format
  2. #
  3. # Copyright (C) 2020 Fabian Peter Hammerle <fabian@hammerle.me>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. import locale
  18. import pytest
  19. from freesurfer_surface import UnsupportedLocaleSettingError, setlocale
  20. def test_set():
  21. system_locale = locale.setlocale(locale.LC_ALL)
  22. assert system_locale != "C"
  23. with setlocale("C"):
  24. assert locale.setlocale(locale.LC_ALL) == "C"
  25. assert locale.setlocale(locale.LC_ALL) == system_locale
  26. def test_unsupported():
  27. system_locale = locale.setlocale(locale.LC_ALL)
  28. with pytest.raises(UnsupportedLocaleSettingError):
  29. with setlocale("abcdef21"):
  30. pass
  31. assert locale.setlocale(locale.LC_ALL) == system_locale
  32. def test_other_error():
  33. system_locale = locale.setlocale(locale.LC_ALL)
  34. with pytest.raises(TypeError):
  35. with setlocale(42):
  36. pass
  37. assert locale.setlocale(locale.LC_ALL) == system_locale