From ddeb2bd42c292fa69203095560ec26f69b475218 Mon Sep 17 00:00:00 2001 From: caodongxia <315816521@qq.com> Date: Sat, 2 Apr 2022 11:14:55 +0800 Subject: [PATCH] fix test failed due to python3.10 --- fix-testresult-failed.patch | 37 ++++++++++++++++++++++++++++++ fix-testsuite-failed.patch | 45 +++++++++++++++++++++++++++++++++++++ python-testtools.spec | 10 ++++++++- 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 fix-testresult-failed.patch create mode 100644 fix-testsuite-failed.patch diff --git a/fix-testresult-failed.patch b/fix-testresult-failed.patch new file mode 100644 index 0000000..aef3ced --- /dev/null +++ b/fix-testresult-failed.patch @@ -0,0 +1,37 @@ +From 840f9230f9fc4433237517310b5b3958b7382f09 Mon Sep 17 00:00:00 2001 +From: caodongxia <315816521@qq.com> +Date: Sat, 2 Apr 2022 11:00:19 +0800 +Subject: [PATCH] fix for python3.10 +Refer: https://github.com/testing-cabal/testtools/commit/254998e2e88835eaa634d9729dddcc3d4b5bc32f +Refer: https://github.com/testing-cabal/testtools/commit/1d698cf91cb2205aedc018e465a2e17c5a6a3e94 + +--- + testtools/tests/test_testresult.py | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/testtools/tests/test_testresult.py b/testtools/tests/test_testresult.py +index d863794..e06ea03 100644 +--- a/testtools/tests/test_testresult.py ++++ b/testtools/tests/test_testresult.py +@@ -2681,6 +2681,8 @@ class TestNonAsciiResults(TestCase): + """Syntax errors should still have fancy special-case formatting""" + if platform.python_implementation() == "PyPy": + spaces = ' ' ++ elif sys.version_info >= (3, 10): ++ spaces = ' ' + else: + spaces = ' ' + textoutput = self._test_external_case("exec ('f(a, b c)')") +@@ -2755,6 +2757,9 @@ class TestNonAsciiResults(TestCase): + textoutput = self._setup_external_case("import bad") + self._write_module("bad", "utf-8", _u("\ufeff^ = 0 # %s\n") % text) + textoutput = self._run_external_case() ++ # Python 3.9 no longer prints the '\ufeff' ++ if sys.version_info >= (3,9): ++ textoutput = textoutput.replace('\ufeff', '') + self.assertThat( + textoutput, + MatchesRegex( +-- +2.27.0 + diff --git a/fix-testsuite-failed.patch b/fix-testsuite-failed.patch new file mode 100644 index 0000000..5e7b3da --- /dev/null +++ b/fix-testsuite-failed.patch @@ -0,0 +1,45 @@ +From d528842b99b16efce212e15dae3f0a54927d06d8 Mon Sep 17 00:00:00 2001 +From: Cyril Roelandt +Date: Fri, 19 Mar 2021 02:50:13 +0000 +Subject: [PATCH] Fix tests with Python 3.10 + +In Python 3, error messages have become a bit more precise. For +instance, the following code snippet: + +---- +class Foo(): + def bar(self, a): + pass + +try: + Foo().bar(1, 2) +except TypeError as e: + print(e) +---- + +will return: + +- in Python 3.9: "bar() takes 2 positional arguments but 3 were given" +- in Python 3.10: "Foo.bar() takes 2 positional arguments but 3 were + given" + +Fix our tests accordingly. +--- + testtools/tests/test_testsuite.py | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/testtools/tests/test_testsuite.py b/testtools/tests/test_testsuite.py +index 7ad5b74d..65cb88d7 100644 +--- a/testtools/tests/test_testsuite.py ++++ b/testtools/tests/test_testsuite.py +@@ -181,7 +181,7 @@ def run(self): + test.run(process_result) + """, doctest.ELLIPSIS)) + self.assertThat(events[3][6].decode('utf8'), DocTestMatches("""\ +-TypeError: run() takes ...1 ...argument...2...given... ++TypeError: ...run() takes ...1 ...argument...2...given... + """, doctest.ELLIPSIS)) + events = [event[0:10] + (None,) for event in events] + events[1] = events[1][:6] + (None,) + events[1][7:] + + \ No newline at end of file diff --git a/python-testtools.spec b/python-testtools.spec index 11600a4..68cd73f 100644 --- a/python-testtools.spec +++ b/python-testtools.spec @@ -1,6 +1,6 @@ Name: python-testtools Version: 2.4.0 -Release: 1 +Release: 2 Summary: Extensions to the Python unit testing framework License: MIT URL: https://launchpad.net/testtools @@ -10,6 +10,11 @@ BuildRequires: python3-extras python3-mimeparse python3-pbr python3-setuptools BuildRequires: python3-traceback2 python3-testscenarios python3-sphinx python3-devel BuildArch: noarch Patch0: testtools-2.4.0-fix-py3-compat.patch +#Refer: https://github.com/testing-cabal/testtools/commit/254998e2e88835eaa634d9729dddcc3d4b5bc32f +#Refer: https://github.com/testing-cabal/testtools/commit/1d698cf91cb2205aedc018e465a2e17c5a6a3e94 +Patch1: fix-testresult-failed.patch +#Refer: https://github.com/testing-cabal/testtools/commit/d528842b99b16efce212e15dae3f0a54927d06d8 +Patch2: fix-testsuite-failed.patch %description Testtools is a set of extensions to the Python standard library's unit testing framework. These @@ -56,6 +61,9 @@ make PYTHON=%{__python3} check %doc doc/_build/html/* %changelog +* Fri Apr 2 2022 caodongxia - 2.4.0-2 +- Fix test_testresult and test_testsuite failed due to python3.10 + * Fri Aug 06 2021 liusheng - 2.4.0-1 - Upgrade to version 2.4.0 -- Gitee