From 754d3f05b5909fa2bc081335bcb0dd0c3627e40a Mon Sep 17 00:00:00 2001 From: Corran Webster Date: Mon, 7 Mar 2022 16:52:02 +0000 Subject: [PATCH 1/8] Fix text locale test issue on Windows This attempts to set the locale to the current value before changing to the testing locale to ensure that a reset will work. On failure, it skips which matches previous behaviour. --- kiva/tests/agg/test_text.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kiva/tests/agg/test_text.py b/kiva/tests/agg/test_text.py index b41f2a216..bde2dc4b7 100644 --- a/kiva/tests/agg/test_text.py +++ b/kiva/tests/agg/test_text.py @@ -21,6 +21,9 @@ def locale_context(category, new=None): """ old = locale.getlocale(category) try: + # check that we can set the current locale to ensure finally will work + # see Enable #899 + locale.setlocale(category, old) locale.setlocale(category, new) except locale.Error as e: raise unittest.SkipTest(str(e)) From 8316b74c605f6a28eb7fbf5fa9b42e6bff04680c Mon Sep 17 00:00:00 2001 From: Corran Webster Date: Wed, 9 Mar 2022 10:09:21 +0000 Subject: [PATCH 2/8] Skip test on windows with explanation. --- kiva/tests/agg/test_text.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kiva/tests/agg/test_text.py b/kiva/tests/agg/test_text.py index bde2dc4b7..80311fa34 100644 --- a/kiva/tests/agg/test_text.py +++ b/kiva/tests/agg/test_text.py @@ -9,6 +9,7 @@ # Thanks for using Enthought open source! from contextlib import contextmanager import locale +import sys import unittest from kiva import agg @@ -21,9 +22,7 @@ def locale_context(category, new=None): """ old = locale.getlocale(category) try: - # check that we can set the current locale to ensure finally will work # see Enable #899 - locale.setlocale(category, old) locale.setlocale(category, new) except locale.Error as e: raise unittest.SkipTest(str(e)) @@ -34,6 +33,12 @@ def locale_context(category, new=None): class TestText(unittest.TestCase): + + @unittest.skipIf( + sys.platform == "win32", + "Skipping on windows due to issues with setlocale. " + "See https://bugs.python.org/issue38324", + ) def test_locale_independence(self): # Ensure that >ASCII Unicode text is decoded correctly regardless of # the locale. From 767f7c2b45919ddded85ac215910c095fa2c81a6 Mon Sep 17 00:00:00 2001 From: Corran Webster Date: Wed, 9 Mar 2022 10:10:51 +0000 Subject: [PATCH 3/8] Fail rather than skip if setlocale fails. --- kiva/tests/agg/test_text.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/kiva/tests/agg/test_text.py b/kiva/tests/agg/test_text.py index 80311fa34..ace364292 100644 --- a/kiva/tests/agg/test_text.py +++ b/kiva/tests/agg/test_text.py @@ -21,11 +21,7 @@ def locale_context(category, new=None): """ Temporarily set the locale. """ old = locale.getlocale(category) - try: - # see Enable #899 - locale.setlocale(category, new) - except locale.Error as e: - raise unittest.SkipTest(str(e)) + locale.setlocale(category, new) try: yield finally: @@ -37,7 +33,7 @@ class TestText(unittest.TestCase): @unittest.skipIf( sys.platform == "win32", "Skipping on windows due to issues with setlocale. " - "See https://bugs.python.org/issue38324", + "See issue #899 and https://bugs.python.org/issue38324", ) def test_locale_independence(self): # Ensure that >ASCII Unicode text is decoded correctly regardless of From 06d199e46a378350ff949466ee79308f4a2ee71c Mon Sep 17 00:00:00 2001 From: Corran Webster Date: Wed, 9 Mar 2022 11:20:33 +0000 Subject: [PATCH 4/8] Try ("C", "ASCII") locale instead of ("en", "ASCII") --- kiva/tests/agg/test_text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kiva/tests/agg/test_text.py b/kiva/tests/agg/test_text.py index ace364292..6a9df1cac 100644 --- a/kiva/tests/agg/test_text.py +++ b/kiva/tests/agg/test_text.py @@ -50,7 +50,7 @@ def test_locale_independence(self): gc.show_text(text) x0, _ = gc.get_text_position() - with locale_context(locale.LC_CTYPE, ("en", "ASCII")): + with locale_context(locale.LC_CTYPE, ("C", "ASCII")): gc = agg.GraphicsContextArray((200, 200)) f = Font("modern") with gc: From 5d842d465ce69af91515cb2ce3efbd7fecce8d2e Mon Sep 17 00:00:00 2001 From: Corran Webster Date: Wed, 9 Mar 2022 12:05:38 +0000 Subject: [PATCH 5/8] Try using ("C", "ASCII") instead of ("en", "ASCII") --- kiva/tests/agg/test_text.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/kiva/tests/agg/test_text.py b/kiva/tests/agg/test_text.py index 6a9df1cac..0ed4f0292 100644 --- a/kiva/tests/agg/test_text.py +++ b/kiva/tests/agg/test_text.py @@ -30,11 +30,6 @@ def locale_context(category, new=None): class TestText(unittest.TestCase): - @unittest.skipIf( - sys.platform == "win32", - "Skipping on windows due to issues with setlocale. " - "See issue #899 and https://bugs.python.org/issue38324", - ) def test_locale_independence(self): # Ensure that >ASCII Unicode text is decoded correctly regardless of # the locale. From e25a329e6e915efdbf003aabcf861ae8ae48b3e4 Mon Sep 17 00:00:00 2001 From: Corran Webster Date: Wed, 9 Mar 2022 12:17:24 +0000 Subject: [PATCH 6/8] Use 'utf8' rather then 'UTF-8' for locale encoding. --- kiva/tests/agg/test_text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kiva/tests/agg/test_text.py b/kiva/tests/agg/test_text.py index 0ed4f0292..928967c32 100644 --- a/kiva/tests/agg/test_text.py +++ b/kiva/tests/agg/test_text.py @@ -35,7 +35,7 @@ def test_locale_independence(self): # the locale. text = "\N{GREEK SMALL LETTER MU}" - with locale_context(locale.LC_CTYPE, ("en", "UTF-8")): + with locale_context(locale.LC_CTYPE, ("en", "utf8")): gc = agg.GraphicsContextArray((200, 200)) f = Font("modern") with gc: From a2bd871bf7b6c1a79cba97b12c9aeeed7dbe168f Mon Sep 17 00:00:00 2001 From: Corran Webster Date: Wed, 9 Mar 2022 12:31:07 +0000 Subject: [PATCH 7/8] Still issues on windows - skip --- kiva/tests/agg/test_text.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kiva/tests/agg/test_text.py b/kiva/tests/agg/test_text.py index 928967c32..3c7e5a08f 100644 --- a/kiva/tests/agg/test_text.py +++ b/kiva/tests/agg/test_text.py @@ -30,6 +30,11 @@ def locale_context(category, new=None): class TestText(unittest.TestCase): + @unittest.skipIf( + sys.platform == "win32", + "Skipping on windows due to issues with setlocale. " + "See issue #899 and https://bugs.python.org/issue38324", + ) def test_locale_independence(self): # Ensure that >ASCII Unicode text is decoded correctly regardless of # the locale. From 96fb5fe7ef2458ebae7dc80e695d73dde62696ff Mon Sep 17 00:00:00 2001 From: Corran Webster Date: Thu, 10 Mar 2022 10:42:13 +0000 Subject: [PATCH 8/8] Add back skip at Robert's suggestion. --- kiva/tests/agg/test_text.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kiva/tests/agg/test_text.py b/kiva/tests/agg/test_text.py index 3c7e5a08f..2151e69f8 100644 --- a/kiva/tests/agg/test_text.py +++ b/kiva/tests/agg/test_text.py @@ -21,7 +21,10 @@ def locale_context(category, new=None): """ Temporarily set the locale. """ old = locale.getlocale(category) - locale.setlocale(category, new) + try: + locale.setlocale(category, new) + except locale.Error as e: + raise unittest.SkipTest(str(e)) try: yield finally: