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