On 18. 6. 25 03:29, Jun Omae wrote:
On 2025/06/18 9:19, Branko Čibej wrote:
On 17. 6. 25 20:31, rin...@apache.org 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.



I have two more questions about this change. I'm sorry I didn't notice them before.

+ @functools.wraps(f) + def wrapper(sbox: svntest.sandbox.Sandbox): + if _utf8_locale is None: + raise svntest.Skip + if _utf8_locale is not False:

Why not just "if _utf8_locale:"? You already checked for None, and the only other possible value besides False is a non-empty string.

+ orig = os.environ.get('LC_ALL') + os.environ['LC_ALL'] = _utf8_locale

I don't understand how why you modify os.environ here but use locale.setlocale() in _detect_utf8_locale(). Shouldn't it be locale.setlocale() in both places?

These two questions apply to the code after finally: as well.

+ 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

-- Brane

Reply via email to