From 233b3d17e9ac283be1a408d4f40d37f530e9b403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9D=94=93=F0=9D=94=A5=F0=9D=94=A6=F0=9D=94=A9?= =?UTF-8?q?=F0=9D=94=A6=F0=9D=94=AD=20=F0=9D=94=9A=F0=9D=94=A6=F0=9D=94=B1?= =?UTF-8?q?=F0=9D=94=A5=F0=9D=94=AB=F0=9D=94=9E=F0=9D=94=A9=F0=9D=94=A9?= Date: Wed, 15 Feb 2023 15:12:33 +0000 Subject: [PATCH 1/2] tests: Ignore UnicodeEncodeErrors when printing test environments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Printing the environment can fail on CI when running against a commit whose author name or commit message contains non-ASCII characters. These values are put into the CI environment in UTF-8 as, for example, the `CI_COMMIT_AUTHOR` environment variable, by GitLab. The CI environment on Windows is not set up with a UTF-8 codepage for console output, so when Python tries to print the environment, it fails with a `UnicodeEncodeError`. Arguably either (or both): * GitLab should be encoding the environment values in the same codepage as it subsequently runs the CI job in. * The CI configuration in `.gitlab-ci.yml` should switch to a UTF-8 codepage for the sanity of anyone who uses GLib’s CI system. But both of those are harder to fix, and this problem has blocked multiple pending merge requests in the last week. So this commit, which is more of a workaround, is proposed. Signed-off-by: Philip Withnall Helps: #2915 --- gio/tests/codegen.py | 7 ++++++- glib/tests/assert-msg-test.py | 14 ++++++++++++-- glib/tests/messages-low-memory.py | 7 ++++++- gobject/tests/genmarshal.py | 7 ++++++- gobject/tests/gobject-query.py | 7 ++++++- gobject/tests/mkenums.py | 7 ++++++- 6 files changed, 42 insertions(+), 7 deletions(-) diff --git a/gio/tests/codegen.py b/gio/tests/codegen.py index d2d8c72263..bee59eeb16 100644 --- a/gio/tests/codegen.py +++ b/gio/tests/codegen.py @@ -95,7 +95,12 @@ class TestCodegen(unittest.TestCase): env = os.environ.copy() env["LC_ALL"] = "C.UTF-8" - print("Environment:", env) + try: + print("Environment:", env) + except UnicodeEncodeError: + # Can happen if the environment contains non-ASCII bytes but the + # environment we’re running in wants output in a different locale. + pass # We want to ensure consistent line endings... info = subprocess.run( diff --git a/glib/tests/assert-msg-test.py b/glib/tests/assert-msg-test.py index 4936fa0832..f97ed59b03 100755 --- a/glib/tests/assert-msg-test.py +++ b/glib/tests/assert-msg-test.py @@ -78,7 +78,12 @@ class TestAssertMessage(unittest.TestCase): env = os.environ.copy() env["LC_ALL"] = "C.UTF-8" - print("Environment:", env) + try: + print("Environment:", env) + except UnicodeEncodeError: + # Can happen if the environment contains non-ASCII bytes but the + # environment we’re running in wants output in a different locale. + pass # We want to ensure consistent line endings... info = subprocess.run( @@ -108,7 +113,12 @@ class TestAssertMessage(unittest.TestCase): env = os.environ.copy() env["LC_ALL"] = "C.UTF-8" - print("Environment:", env) + try: + print("Environment:", env) + except UnicodeEncodeError: + # Can happen if the environment contains non-ASCII bytes but the + # environment we’re running in wants output in a different locale. + pass # We want to ensure consistent line endings... info = subprocess.run( diff --git a/glib/tests/messages-low-memory.py b/glib/tests/messages-low-memory.py index 8e071b1647..26f01275d9 100644 --- a/glib/tests/messages-low-memory.py +++ b/glib/tests/messages-low-memory.py @@ -63,7 +63,12 @@ class TestMessagesLowMemory(unittest.TestCase): env = os.environ.copy() env["LC_ALL"] = "C.UTF-8" - print("Environment:", env) + try: + print("Environment:", env) + except UnicodeEncodeError: + # Can happen if the environment contains non-ASCII bytes but the + # environment we’re running in wants output in a different locale. + pass # We want to ensure consistent line endings... info = subprocess.run( diff --git a/gobject/tests/genmarshal.py b/gobject/tests/genmarshal.py index 1062dfe625..68b074c5d1 100644 --- a/gobject/tests/genmarshal.py +++ b/gobject/tests/genmarshal.py @@ -88,7 +88,12 @@ class TestGenmarshal(unittest.TestCase): env = os.environ.copy() env["LC_ALL"] = "C.UTF-8" - print("Environment:", env) + try: + print("Environment:", env) + except UnicodeEncodeError: + # Can happen if the environment contains non-ASCII bytes but the + # environment we’re running in wants output in a different locale. + pass # We want to ensure consistent line endings... info = subprocess.run( diff --git a/gobject/tests/gobject-query.py b/gobject/tests/gobject-query.py index 618b6bae91..e69f1c79dc 100644 --- a/gobject/tests/gobject-query.py +++ b/gobject/tests/gobject-query.py @@ -59,7 +59,12 @@ class TestGobjectQuery(unittest.TestCase): env = os.environ.copy() env["LC_ALL"] = "C.UTF-8" - print("Environment:", env) + try: + print("Environment:", env) + except UnicodeEncodeError: + # Can happen if the environment contains non-ASCII bytes but the + # environment we’re running in wants output in a different locale. + pass # We want to ensure consistent line endings... info = subprocess.run( diff --git a/gobject/tests/mkenums.py b/gobject/tests/mkenums.py index b58d23e799..0e0b13f498 100644 --- a/gobject/tests/mkenums.py +++ b/gobject/tests/mkenums.py @@ -100,7 +100,12 @@ class TestMkenums(unittest.TestCase): env = os.environ.copy() env["LC_ALL"] = "C.UTF-8" - print("Environment:", env) + try: + print("Environment:", env) + except UnicodeEncodeError: + # Can happen if the environment contains non-ASCII bytes but the + # environment we’re running in wants output in a different locale. + pass # We want to ensure consistent line endings... info = subprocess.run( -- GitLab From e4a2982c2cd83d10a2bcfd9e03ac7e230fdf4ead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9D=94=93=F0=9D=94=A5=F0=9D=94=A6=F0=9D=94=A9?= =?UTF-8?q?=F0=9D=94=A6=F0=9D=94=AD=20=F0=9D=94=9A=F0=9D=94=A6=F0=9D=94=B1?= =?UTF-8?q?=F0=9D=94=A5=F0=9D=94=AB=F0=9D=94=9E=F0=9D=94=A9=F0=9D=94=A9?= Date: Wed, 15 Feb 2023 15:37:07 +0000 Subject: [PATCH 2/2] WIP Signed-off-by: Philip Withnall --- gobject/tests/taptestrunner.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gobject/tests/taptestrunner.py b/gobject/tests/taptestrunner.py index 9adbd8daa4..b7ed998709 100644 --- a/gobject/tests/taptestrunner.py +++ b/gobject/tests/taptestrunner.py @@ -68,6 +68,9 @@ class TAPTestResult(unittest.TestResult): else: self.test_output = StringIO() + self.message.encoding = sys.stdout.encoding + self.test_output.encoding = sys.stdout.encoding + if self.message_log == self.test_output_log: self.test_output = self.message sys.stdout = sys.stderr = self.test_output -- GitLab