chore(tox): Fix errors due to new versions of flake8 and requests (#949)
Also fix Jython incompatibilities that were discovered in the process.
This commit is contained in:
committed by
John Vrbanac
parent
463593f194
commit
1379641638
@@ -329,5 +329,6 @@ def main():
|
||||
|
||||
print()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -33,8 +33,8 @@ WSGI callable, without having to stand up a WSGI server.
|
||||
"""
|
||||
|
||||
import json
|
||||
import platform
|
||||
import re
|
||||
import sys
|
||||
import wsgiref.validate
|
||||
|
||||
from six.moves import http_cookies
|
||||
@@ -43,6 +43,11 @@ from falcon.testing import helpers
|
||||
from falcon.testing.srmock import StartResponseMock
|
||||
from falcon.util import CaseInsensitiveDict, http_date_to_dt, to_query_str
|
||||
|
||||
_PYVER = platform.python_version_tuple()[:2]
|
||||
_PY26 = _PYVER == ('2', '6')
|
||||
_PY27 = _PYVER == ('2', '7')
|
||||
_JYTHON = platform.python_implementation() == 'Jython'
|
||||
|
||||
|
||||
class Result(object):
|
||||
"""Encapsulates the result of a simulated WSGI request.
|
||||
@@ -100,13 +105,13 @@ class Result(object):
|
||||
if name.lower() == 'set-cookie':
|
||||
cookies.load(value)
|
||||
|
||||
if sys.version_info < (2, 7):
|
||||
if _PY26 or (_PY27 and _JYTHON):
|
||||
match = re.match('([^=]+)=', value)
|
||||
assert match
|
||||
|
||||
cookie_name = match.group(1)
|
||||
|
||||
# NOTE(kgriffs): py26 has a bug that causes
|
||||
# NOTE(kgriffs): py26/Jython has a bug that causes
|
||||
# SimpleCookie to incorrectly parse the "expires"
|
||||
# attribute, so we have to do it ourselves. This
|
||||
# algorithm is obviously very naive, but it should
|
||||
@@ -116,9 +121,9 @@ class Result(object):
|
||||
if match:
|
||||
cookies[cookie_name]['expires'] = match.group(1)
|
||||
|
||||
# NOTE(kgriffs): py26's SimpleCookie won't parse
|
||||
# the "httponly" and "secure" attributes, so we
|
||||
# have to do it ourselves.
|
||||
# NOTE(kgriffs): py26/Jython's SimpleCookie won't
|
||||
# parse the "httponly" and "secure" attributes, so
|
||||
# we have to do it ourselves.
|
||||
if 'httponly' in value:
|
||||
cookies[cookie_name]['httponly'] = True
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import platform
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
import falcon
|
||||
|
||||
|
||||
@@ -10,3 +13,22 @@ import falcon
|
||||
def reset_request_stream_detection():
|
||||
falcon.Request._wsgi_input_type_known = False
|
||||
falcon.Request._always_wrap_wsgi_input = False
|
||||
|
||||
|
||||
# NOTE(kgriffs): Patch pytest to make it compatible with Jython. This
|
||||
# is necessary because val.encode() raises UnicodeEncodeError instead
|
||||
# of UnicodeDecodeError, and running under Jython triggers this buggy
|
||||
# code path in pytest.
|
||||
if platform.python_implementation() == 'Jython':
|
||||
import _pytest.python
|
||||
|
||||
def _escape_strings(val):
|
||||
if isinstance(val, bytes):
|
||||
try:
|
||||
return val.encode('ascii')
|
||||
except UnicodeEncodeError:
|
||||
return val.encode('string-escape')
|
||||
else:
|
||||
return val.encode('unicode-escape')
|
||||
|
||||
_pytest.python._escape_strings = _escape_strings
|
||||
|
||||
@@ -16,6 +16,7 @@ def application(environ, start_response):
|
||||
|
||||
return [body]
|
||||
|
||||
|
||||
app = application
|
||||
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ class TimezoneGMTPlus1(tzinfo):
|
||||
def dst(self, dt):
|
||||
return timedelta(hours=1)
|
||||
|
||||
|
||||
GMT_PLUS_ONE = TimezoneGMTPlus1()
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
if [ "$JYTHON" = "true" ]; then
|
||||
travis_scripts/install_jython2.7.sh
|
||||
|
||||
# NOTE(kgriffs): Use an older version of requests to work around a
|
||||
# "method code too large" bug that is triggered starting with
|
||||
# requests 2.11.1 under Jython 2.7.0 (see also the related Jython
|
||||
# bug: http://bugs.jython.org/issue527524).
|
||||
$HOME/jython/bin/pip install https://github.com/kennethreitz/requests/archive/v2.11.0.zip
|
||||
$HOME/jython/bin/pip install -r tools/test-requires
|
||||
else
|
||||
pip install tox coveralls
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
if [ "$JYTHON" = "true" ]; then
|
||||
set -e
|
||||
|
||||
$HOME/jython/bin/pytest tests
|
||||
|
||||
# Smoke test
|
||||
|
||||
Reference in New Issue
Block a user