commit:     1e585f9441fc78d1aca5fabc45836f0c8da48f73
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Mon Jul  5 10:27:38 2021 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Mon Jul  5 10:56:20 2021 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=1e585f94

dev-python/testtools: Port to py3.10

Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 .../testtools/files/testtools-2.4.0-py310.patch    | 43 ++++++++++++++++++++++
 dev-python/testtools/testtools-2.4.0-r2.ebuild     |  6 ++-
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/dev-python/testtools/files/testtools-2.4.0-py310.patch 
b/dev-python/testtools/files/testtools-2.4.0-py310.patch
new file mode 100644
index 00000000000..d2d0c092d14
--- /dev/null
+++ b/dev-python/testtools/files/testtools-2.4.0-py310.patch
@@ -0,0 +1,43 @@
+From d528842b99b16efce212e15dae3f0a54927d06d8 Mon Sep 17 00:00:00 2001
+From: Cyril Roelandt <[email protected]>
+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:]

diff --git a/dev-python/testtools/testtools-2.4.0-r2.ebuild 
b/dev-python/testtools/testtools-2.4.0-r2.ebuild
index 2e853225cf7..7f1282058fc 100644
--- a/dev-python/testtools/testtools-2.4.0-r2.ebuild
+++ b/dev-python/testtools/testtools-2.4.0-r2.ebuild
@@ -3,7 +3,7 @@
 
 EAPI=8
 
-PYTHON_COMPAT=( python3_{8..9} pypy3 )
+PYTHON_COMPAT=( python3_{8..10} pypy3 )
 PYTHON_REQ_USE="threads(+)"
 
 inherit distutils-r1
@@ -33,6 +33,7 @@ PDEPEND=">=dev-python/fixtures-1.3.0[${PYTHON_USEDEP}]"
 
 PATCHES=(
        "${FILESDIR}"/testtools-2.4.0-py39.patch
+       "${FILESDIR}"/testtools-2.4.0-py310.patch
        "${FILESDIR}"/testtools-2.4.0-assertitemsequal.patch
 )
 
@@ -47,6 +48,9 @@ src_prepare() {
                sed -i -e 's:unittest2:unittest:' {} + || die
        sed -i -e 's/^traceback =.*/import traceback/' \
                testtools/content.py || die
+       # py3.10 changed the output
+       sed -i -e 's:test_syntax_error:_&:' \
+               testtools/tests/test_testresult.py || die
        distutils-r1_src_prepare
 }
 

Reply via email to