test_locale.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """Test locale independence of WKT"""
  2. import locale
  3. import sys
  4. import unittest
  5. from shapely.wkt import dumps, loads
  6. # Set locale to one that uses a comma as decimal separator
  7. # TODO: try a few other common locales
  8. if sys.platform == "win32":
  9. test_locales = {"Portuguese": "portuguese_brazil", "Italian": "italian_italy"}
  10. else:
  11. test_locales = {
  12. "Portuguese": "pt_BR.UTF-8",
  13. "Italian": "it_IT.UTF-8",
  14. }
  15. do_test_locale = False
  16. def setUpModule():
  17. global do_test_locale
  18. for name in test_locales:
  19. try:
  20. test_locale = test_locales[name]
  21. locale.setlocale(locale.LC_ALL, test_locale)
  22. do_test_locale = True
  23. break
  24. except Exception:
  25. pass
  26. if not do_test_locale:
  27. raise unittest.SkipTest("test locale not found")
  28. def tearDownModule():
  29. if sys.platform == "win32" or sys.version_info[0:2] >= (3, 11):
  30. locale.setlocale(locale.LC_ALL, "")
  31. else:
  32. # Deprecated since version 3.11, will be removed in version 3.13
  33. locale.resetlocale()
  34. class LocaleTestCase(unittest.TestCase):
  35. # @unittest.skipIf(not do_test_locale, 'test locale not found')
  36. def test_wkt_locale(self):
  37. # Test reading and writing
  38. p = loads("POINT (0.0 0.0)")
  39. assert p.x == 0.0
  40. assert p.y == 0.0
  41. wkt = dumps(p)
  42. assert wkt.startswith("POINT")
  43. assert "," not in wkt