Skip to content
This repository has been archived by the owner on May 20, 2023. It is now read-only.

Commit

Permalink
python-klein: add patches to make tests green
Browse files Browse the repository at this point in the history
Most of patches are home-grown instead of from upstream, as upstream fixes
are quite large and cannot be cleanly backported. Specifically, upstream
moves test strategies from Klein to Hyperlink [1] and drop Python 2.x
support [2,3]. The fix for Werkzeug 2.x in test_resource.py [3] is smaller,
while it cannot be cleanly backported, either.

[1] twisted/klein#393
[2] twisted/klein#328
[3] twisted/klein#355
[4] twisted/klein#499

git-svn-id: file:///srv/repos/svn-community/svn@965883 9fca08f4-af9d-4005-b8df-a31f2cc04f65
  • Loading branch information
yan12125 authored and svntogit committed Jun 20, 2021
1 parent 835e0d1 commit 8d6082a
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 6 deletions.
17 changes: 11 additions & 6 deletions trunk/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ license=(MIT)
depends=(python python-attrs python-hyperlink python-incremental python-six
python-tubes python-twisted python-werkzeug python-zope-interface)
makedepends=(python-setuptools)
checkdepends=(python-hypothesis python-mock python-treq python-pytest)
source=("https://github.com/twisted/klein/archive/$pkgver/klein-$pkgver.tar.gz")
sha512sums=('1cba04a365fd9c7185e2f2472f617f875ee9cec41ac97940dda4a145811cefcbbe34f11e1f306656dc43d88b49e66bfcb5efb72d25283bbc8a0729b2fc5e2fca')
checkdepends=(python-hypothesis python-treq python-pytest)
source=("https://github.com/twisted/klein/archive/$pkgver/klein-$pkgver.tar.gz"
"fix-tests.diff")
sha512sums=('1cba04a365fd9c7185e2f2472f617f875ee9cec41ac97940dda4a145811cefcbbe34f11e1f306656dc43d88b49e66bfcb5efb72d25283bbc8a0729b2fc5e2fca'
'bbe07e6c9f067265cb962654930632707d61b046709907711ceeaea8b1e691b6cee54b75b1602e2f636251e4a82dd662524dc12e6fb877ef12b7474b9e6e6874')

prepare() {
cd klein-$pkgver
patch -Np1 -i ../fix-tests.diff
}

build() {
cd klein-$pkgver
Expand All @@ -22,9 +29,7 @@ build() {

check() {
cd klein-$pkgver
# klein tests are broken with treq 20.4.1
# https://github.com/twisted/klein/issues/339
pytest -v src/klein/test -k 'not test_customParameterValidation and not test_handlingGET'
pytest src/klein/test
}

package() {
Expand Down
69 changes: 69 additions & 0 deletions trunk/fix-tests.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
diff -ur klein-20.6.0.orig/src/klein/test/_strategies.py klein-20.6.0/src/klein/test/_strategies.py
--- klein-20.6.0.orig/src/klein/test/_strategies.py 2020-06-08 10:52:04.000000000 +0800
+++ klein-20.6.0/src/klein/test/_strategies.py 2021-06-20 18:35:54.019437139 +0800
@@ -24,7 +24,6 @@

from idna import IDNAError, check_label, encode as idna_encode

-from twisted.python.compat import _PY3, unicode


__all__ = ()
@@ -34,8 +33,9 @@
DrawCallable = Callable[[Callable[..., T]], T]


-if _PY3:
+if True:
unichr = chr
+ unicode = str


def idna_characters(): # pragma: no cover
diff -ur klein-20.6.0.orig/src/klein/test/test_resource.py klein-20.6.0/src/klein/test/test_resource.py
--- klein-20.6.0.orig/src/klein/test/test_resource.py 2020-06-08 10:52:04.000000000 +0800
+++ klein-20.6.0/src/klein/test/test_resource.py 2021-06-20 18:42:53.065083517 +0800
@@ -13,7 +13,6 @@
from twisted.internet.defer import CancelledError, Deferred, fail, succeed
from twisted.internet.error import ConnectionLost
from twisted.internet.unix import Server
-from twisted.python.compat import _PY3, unicode
from twisted.trial.unittest import SynchronousTestCase
from twisted.web import server
from twisted.web.http_headers import Headers
@@ -34,6 +33,8 @@
ensure_utf8_bytes,
)

+unicode = str
+

def requestMock(
path,
@@ -610,7 +611,7 @@
request.setHeader.assert_has_calls(
[
call(b"Content-Type", b"text/html; charset=utf-8"),
- call(b"Content-Length", b"259"),
+ call(b"Content-Length", b"258"),
call(b"Location", b"http://localhost:8080/foo/"),
]
)
@@ -1116,7 +1117,7 @@
repr(_URLDecodeError(ValueError)),
)

- if _PY3:
+ if True:
test_urlDecodeErrorReprPy2.skip = "Only works on Py2" # type: ignore
else:
test_urlDecodeErrorReprPy3.skip = "Only works on Py3" # type: ignore
@@ -1319,7 +1320,7 @@
self.assertIdentical(resource.ensure_utf8_bytes, ensure_utf8_bytes)


-if _PY3:
+if True:
import sys

if sys.version_info >= (3, 5):

0 comments on commit 8d6082a

Please sign in to comment.