diff mbox series

[meta-python] python3-click: Fix ptest failure

Message ID 20230428053724.3608477-1-raj.khem@gmail.com
State New
Headers show
Series [meta-python] python3-click: Fix ptest failure | expand

Commit Message

Khem Raj April 28, 2023, 5:37 a.m. UTC
test_bytes_args fails especially on musl, therefore use mocked sys.stdin.encoding

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 .../0001-tests-Fix-test_bytes_args.patch      | 41 +++++++++++++++++++
 .../python/python3-click_8.1.3.bb             |  1 +
 2 files changed, 42 insertions(+)
 create mode 100644 meta-python/recipes-devtools/python/python3-click/0001-tests-Fix-test_bytes_args.patch
diff mbox series

Patch

diff --git a/meta-python/recipes-devtools/python/python3-click/0001-tests-Fix-test_bytes_args.patch b/meta-python/recipes-devtools/python/python3-click/0001-tests-Fix-test_bytes_args.patch
new file mode 100644
index 0000000000..e69a37c405
--- /dev/null
+++ b/meta-python/recipes-devtools/python/python3-click/0001-tests-Fix-test_bytes_args.patch
@@ -0,0 +1,41 @@ 
+From da83bd7ca0959027086115f23534957b0917aaa5 Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+Date: Thu, 27 Apr 2023 22:21:24 -0700
+Subject: [PATCH] tests: Fix test_bytes_args
+
+sys.stdin.encoding is readonly therefore use Mocking to wrap it.
+Sourced from - Alpine
+
+Upstream-Status: Pending
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+---
+ tests/test_arguments.py | 6 +++++-
+ 1 file changed, 5 insertions(+), 1 deletion(-)
+
+diff --git a/tests/test_arguments.py b/tests/test_arguments.py
+index 735df4b..3395c55 100644
+--- a/tests/test_arguments.py
++++ b/tests/test_arguments.py
+@@ -1,4 +1,5 @@
+ import sys
++from unittest import mock
+ 
+ import pytest
+ 
+@@ -86,9 +87,12 @@ def test_bytes_args(runner, monkeypatch):
+         ), "UTF-8 encoded argument should be implicitly converted to Unicode"
+ 
+     # Simulate empty locale environment variables
+-    monkeypatch.setattr(sys.stdin, "encoding", "utf-8")
+     monkeypatch.setattr(sys, "getfilesystemencoding", lambda: "utf-8")
+     monkeypatch.setattr(sys, "getdefaultencoding", lambda: "utf-8")
++    # sys.stdin.encoding is readonly, needs some extra effort to patch.
++    stdin = mock.Mock(wraps=sys.stdin)
++    stdin.encoding = "utf-8"
++    monkeypatch.setattr(sys, "stdin", stdin)
+ 
+     runner.invoke(
+         from_bytes,
+-- 
+2.40.1
+
diff --git a/meta-python/recipes-devtools/python/python3-click_8.1.3.bb b/meta-python/recipes-devtools/python/python3-click_8.1.3.bb
index 006742f153..9b8ea94c2a 100644
--- a/meta-python/recipes-devtools/python/python3-click_8.1.3.bb
+++ b/meta-python/recipes-devtools/python/python3-click_8.1.3.bb
@@ -13,6 +13,7 @@  SRC_URI[sha256sum] = "7682dc8afb30297001674575ea00d1814d808d6a36af415a82bd481d37
 inherit pypi setuptools3 ptest
 
 SRC_URI += " \
+	file://0001-tests-Fix-test_bytes_args.patch \
 	file://run-ptest \
 "