On 2025/06/18 9:19, Branko Čibej wrote:
> On 17. 6. 25 20:31, [email protected] wrote:
>> Author: rinrab
>> Date: Tue Jun 17 18:31:22 2025
>> New Revision: 1926510
>>
>> URL: http://svn.apache.org/viewvc?rev=1926510&view=rev
>> Log:
>> On the 'utf8-cmdline-prototype' branch: Add RequireUtf8 decorator and
>> run the basic_tests#unicode_arguments_test test in UTF8 environment to fix
>> failure its constant failures on Unix platforms.
>
> I have a Unix platform and this test never fails. :)
>
> By the way: that whole file uses 2-column indents, this change uses 4-column
> indents, so, consistency FTW!
>
> [...]
>
>> @@ -349,3 +349,50 @@ def SkipDumpLoadCrossCheck_deco(cond_fun
>>
>> # Create a singular alias, for linguistic correctness
>> Issue_deco = Issues_deco
>> +
>> +
>> +# Determines the name of UTF-8 locale on the system, or returns None if one
>> +# couldn't be found.
>> +def _detect_utf8_locale():
>> + import locale
>
> It would be better to import this module at the top of the file.
>> +
>> + orig = None
>> + try:
>> + for name in ('C.UTF-8', 'en_US.UTF-8'):
>> + try:
>> + orig = locale.setlocale(locale.LC_ALL, name)
>> + except locale.Error:
>> + continue
>> + else:
>> + return name
>> + finally:
>> + if orig is not None:
>> + locale.setlocale(locale.LC_ALL, orig)
>> +
>> + return None # utf-8 locale unavailable
>> +
>> +_utf8_locale = _detect_utf8_locale() if os.name != 'nt' else False
>
> Too specific ... a better test would be: if os.name == 'posix', as there are
> other, non-Windows platforms out there that are also not POSIX-compliant.
> Even better, just put this at the top of _detect_utf8_locale() and don't
> complicate the assignment:
>
> if os.name != 'posix':
> return None
>
> This is correct because, as the Python docs[1] explicitly say:
>
>> The |locale|
>> <https://docs.python.org/3/library/locale.html#module-locale> module opens
>> access to the POSIX locale database and functionality.
>
>
>> +
>> +# Decorator that runs the test in UTF-8 environment. If there are no good
>> +# UTF-8 locales availible on the system, skips the test.
>> +def RequireUtf8_deco(f):
>> +
>> + import functools
>
> Import this at the top of the file, too.
>
>
> -- Brane
>
> [1] https://docs.python.org/3/library/locale.html
That's my fault as the original patch author. I created a patch for the review.
See the attached patch.
--
Jun Omae <[email protected]> (大前 潤)
diff --git a/subversion/tests/cmdline/svntest/testcase.py
b/subversion/tests/cmdline/svntest/testcase.py
index 237df56cc..49010ccf4 100644
--- a/subversion/tests/cmdline/svntest/testcase.py
+++ b/subversion/tests/cmdline/svntest/testcase.py
@@ -23,7 +23,7 @@
# under the License.
######################################################################
-import os, types, sys
+import os, types, sys, locale, functools
import svntest
@@ -351,48 +351,51 @@ def SkipDumpLoadCrossCheck_deco(cond_func = lambda: True):
Issue_deco = Issues_deco
-# Determines the name of UTF-8 locale on the system, or returns None if one
-# couldn't be found.
+# Determines the name of UTF-8 locale on the system, returns None if one
+# couldn't be found, or False if no need to change the locale.
def _detect_utf8_locale():
- import locale
+ if os.name == 'nt':
+ return False # The test will be run without changing locale
+ if os.name != 'posix':
+ return None # The test will be skipped
+
+ orig = None
+ try:
+ for name in ('C.UTF-8', 'en_US.UTF-8'):
+ try:
+ orig = locale.setlocale(locale.LC_ALL, name)
+ except locale.Error:
+ continue
+ else:
+ return name # The test will be run with this locale
+ finally:
+ if orig is not None:
+ locale.setlocale(locale.LC_ALL, orig)
+
+ return None # utf-8 locale unavailable, the test will be skipped
- orig = None
- try:
- for name in ('C.UTF-8', 'en_US.UTF-8'):
- try:
- orig = locale.setlocale(locale.LC_ALL, name)
- except locale.Error:
- continue
- else:
- return name
- finally:
- if orig is not None:
- locale.setlocale(locale.LC_ALL, orig)
- return None # utf-8 locale unavailable
+_utf8_locale = _detect_utf8_locale()
-_utf8_locale = _detect_utf8_locale() if os.name != 'nt' else False
# Decorator that runs the test in UTF-8 environment. If there are no good
# UTF-8 locales availible on the system, skips the test.
def RequireUtf8_deco(f):
- import functools
-
- @functools.wraps(f)
- def wrapper(sbox: svntest.sandbox.Sandbox):
- if _utf8_locale is None:
- raise svntest.Skip
- if _utf8_locale is not False:
- orig = os.environ.get('LC_ALL')
- os.environ['LC_ALL'] = _utf8_locale
- try:
- return f(sbox)
- finally:
- if _utf8_locale is not False:
- if orig is None:
- del os.environ['LC_ALL']
- else:
- os.environ['LC_ALL'] = orig
-
- return wrapper
+ @functools.wraps(f)
+ def wrapper(sbox: svntest.sandbox.Sandbox):
+ if _utf8_locale is None:
+ raise svntest.Skip
+ if _utf8_locale is not False:
+ orig = os.environ.get('LC_ALL')
+ os.environ['LC_ALL'] = _utf8_locale
+ try:
+ return f(sbox)
+ finally:
+ if _utf8_locale is not False:
+ if orig is None:
+ del os.environ['LC_ALL']
+ else:
+ os.environ['LC_ALL'] = orig
+
+ return wrapper