pep8 fixes to get pep8 tox target passing
This is basic flake8 testing without any 'hacking' extensions. We may wish to add those later, but for the time being this code is so much of its own particular style that that would be painful. In any case, the hacking rules aren't that great. In the process some documentation adjustments were made while fixing line lenghts. A dead link was removed.
This commit is contained in:
@@ -12,8 +12,7 @@ env:
|
|||||||
- TOXENV=py34
|
- TOXENV=py34
|
||||||
- TOXENV=py35
|
- TOXENV=py35
|
||||||
- TOXENV=pypy
|
- TOXENV=pypy
|
||||||
# XXX: known to fail, fixes to follow
|
- TOXENV=pep8
|
||||||
#- TOXENV=pep8
|
|
||||||
- TOXENV=docs
|
- TOXENV=docs
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
|
|||||||
4
setup.py
4
setup.py
@@ -23,7 +23,9 @@ META = {
|
|||||||
'version': wsgi_intercept.__version__,
|
'version': wsgi_intercept.__version__,
|
||||||
'author': 'Titus Brown, Kumar McMillan, Chris Dent, Sasha Hart',
|
'author': 'Titus Brown, Kumar McMillan, Chris Dent, Sasha Hart',
|
||||||
'author_email': 'cdent@peermore.com',
|
'author_email': 'cdent@peermore.com',
|
||||||
'description': 'wsgi_intercept installs a WSGI application in place of a real URI for testing.',
|
'description':
|
||||||
|
'wsgi_intercept installs a WSGI application in place of a '
|
||||||
|
'real URI for testing.',
|
||||||
# What will the name be?
|
# What will the name be?
|
||||||
'url': 'http://pypi.python.org/pypi/wsgi_intercept',
|
'url': 'http://pypi.python.org/pypi/wsgi_intercept',
|
||||||
'long_description': wsgi_intercept.__doc__,
|
'long_description': wsgi_intercept.__doc__,
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ from .wsgi_app import simple_app
|
|||||||
|
|
||||||
httppool = urllib3.PoolManager()
|
httppool = urllib3.PoolManager()
|
||||||
|
|
||||||
|
|
||||||
def app():
|
def app():
|
||||||
return simple_app
|
return simple_app
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ def teardown_module(module):
|
|||||||
|
|
||||||
|
|
||||||
def test_simple_request():
|
def test_simple_request():
|
||||||
|
global host
|
||||||
http = Http()
|
http = Http()
|
||||||
response, content = http.request('http://%s/' % host)
|
response, content = http.request('http://%s/' % host)
|
||||||
assert response.status == 200
|
assert response.status == 200
|
||||||
@@ -30,6 +31,7 @@ def test_simple_request():
|
|||||||
|
|
||||||
|
|
||||||
def test_another_request():
|
def test_another_request():
|
||||||
|
global host
|
||||||
http = Http()
|
http = Http()
|
||||||
response, content = http.request('http://%s/foobar' % host)
|
response, content = http.request('http://%s/foobar' % host)
|
||||||
assert response.status == 200
|
assert response.status == 200
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
import py.test
|
import py.test
|
||||||
import socket
|
|
||||||
from wsgi_intercept import urllib3_intercept, WSGIAppError
|
from wsgi_intercept import urllib3_intercept, WSGIAppError
|
||||||
from test import wsgi_app
|
from test import wsgi_app
|
||||||
from test.install import installer_class, skipnetwork
|
from test.install import installer_class, skipnetwork
|
||||||
@@ -14,7 +13,8 @@ http = urllib3.PoolManager()
|
|||||||
|
|
||||||
def test_http():
|
def test_http():
|
||||||
with InstalledApp(wsgi_app.simple_app, host=HOST, port=80) as app:
|
with InstalledApp(wsgi_app.simple_app, host=HOST, port=80) as app:
|
||||||
resp = http.request('GET', 'http://some_hopefully_nonexistant_domain:80/')
|
resp = http.request(
|
||||||
|
'GET', 'http://some_hopefully_nonexistant_domain:80/')
|
||||||
assert resp.data == b'WSGI intercept successful!\n'
|
assert resp.data == b'WSGI intercept successful!\n'
|
||||||
assert app.success()
|
assert app.success()
|
||||||
|
|
||||||
@@ -28,7 +28,8 @@ def test_http_default_port():
|
|||||||
|
|
||||||
def test_http_other_port():
|
def test_http_other_port():
|
||||||
with InstalledApp(wsgi_app.simple_app, host=HOST, port=8080) as app:
|
with InstalledApp(wsgi_app.simple_app, host=HOST, port=8080) as app:
|
||||||
resp = http.request('GET', 'http://some_hopefully_nonexistant_domain:8080/')
|
resp = http.request(
|
||||||
|
'GET', 'http://some_hopefully_nonexistant_domain:8080/')
|
||||||
assert resp.data == b'WSGI intercept successful!\n'
|
assert resp.data == b'WSGI intercept successful!\n'
|
||||||
assert app.success()
|
assert app.success()
|
||||||
environ = app.get_internals()
|
environ = app.get_internals()
|
||||||
@@ -39,7 +40,8 @@ def test_bogus_domain():
|
|||||||
with InstalledApp(wsgi_app.simple_app, host=HOST, port=80):
|
with InstalledApp(wsgi_app.simple_app, host=HOST, port=80):
|
||||||
py.test.raises(
|
py.test.raises(
|
||||||
urllib3.exceptions.ProtocolError,
|
urllib3.exceptions.ProtocolError,
|
||||||
'http.request("GET", "http://_nonexistant_domain_", retries=False)')
|
'http.request("GET", "http://_nonexistant_domain_", '
|
||||||
|
'retries=False)')
|
||||||
|
|
||||||
|
|
||||||
def test_proxy_handling():
|
def test_proxy_handling():
|
||||||
@@ -56,14 +58,16 @@ def test_proxy_handling():
|
|||||||
|
|
||||||
def test_https():
|
def test_https():
|
||||||
with InstalledApp(wsgi_app.simple_app, host=HOST, port=443) as app:
|
with InstalledApp(wsgi_app.simple_app, host=HOST, port=443) as app:
|
||||||
resp = http.request('GET', 'https://some_hopefully_nonexistant_domain:443/')
|
resp = http.request(
|
||||||
|
'GET', 'https://some_hopefully_nonexistant_domain:443/')
|
||||||
assert resp.data == b'WSGI intercept successful!\n'
|
assert resp.data == b'WSGI intercept successful!\n'
|
||||||
assert app.success()
|
assert app.success()
|
||||||
|
|
||||||
|
|
||||||
def test_https_default_port():
|
def test_https_default_port():
|
||||||
with InstalledApp(wsgi_app.simple_app, host=HOST, port=443) as app:
|
with InstalledApp(wsgi_app.simple_app, host=HOST, port=443) as app:
|
||||||
resp = http.request('GET', 'https://some_hopefully_nonexistant_domain/')
|
resp = http.request(
|
||||||
|
'GET', 'https://some_hopefully_nonexistant_domain/')
|
||||||
assert resp.data == b'WSGI intercept successful!\n'
|
assert resp.data == b'WSGI intercept successful!\n'
|
||||||
assert app.success()
|
assert app.success()
|
||||||
environ = app.get_internals()
|
environ = app.get_internals()
|
||||||
|
|||||||
@@ -60,7 +60,13 @@ def test_more_interesting():
|
|||||||
assert internal_env['QUERY_STRING'] == 'bar=baz%20zoom'
|
assert internal_env['QUERY_STRING'] == 'bar=baz%20zoom'
|
||||||
assert internal_env['HTTP_ACCEPT'] == 'application/json'
|
assert internal_env['HTTP_ACCEPT'] == 'application/json'
|
||||||
assert internal_env['HTTP_COOKIE'] == 'foo=bar'
|
assert internal_env['HTTP_COOKIE'] == 'foo=bar'
|
||||||
assert type(internal_env['HTTP_COOKIE']) == type('')
|
# In this test we are ensuring the value, in the environ, of
|
||||||
|
# a request header has a value which is a str, as native to
|
||||||
|
# that version of Python. That means always a str, despite
|
||||||
|
# the fact that a str in Python 2 and 3 are different
|
||||||
|
# things! PEP 3333 requires this. isinstance is not used to
|
||||||
|
# avoid confusion over class hierarchies.
|
||||||
|
assert type(internal_env['HTTP_COOKIE']) == type('') # noqa E721
|
||||||
|
|
||||||
# Do the rather painful wsgi encoding dance.
|
# Do the rather painful wsgi encoding dance.
|
||||||
if sys.version_info[0] > 2:
|
if sys.version_info[0] > 2:
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
"""Installs a WSGI application in place of a real host for testing.
|
"""Installs a WSGI application in place of a real host for testing.
|
||||||
|
|
||||||
Introduction
|
Introduction
|
||||||
@@ -89,19 +88,21 @@ History
|
|||||||
|
|
||||||
Pursuant to Ian Bicking's `"best Web testing framework"`_ post, Titus
|
Pursuant to Ian Bicking's `"best Web testing framework"`_ post, Titus
|
||||||
Brown put together an `in-process HTTP-to-WSGI interception mechanism`_
|
Brown put together an `in-process HTTP-to-WSGI interception mechanism`_
|
||||||
for his own Web testing system, twill_. Because the mechanism is pretty
|
for his own Web testing system, twill. Because the mechanism is pretty
|
||||||
generic -- it works at the httplib level -- Titus decided to try adding
|
generic -- it works at the httplib level -- Titus decided to try adding
|
||||||
it into all of the *other* Python Web testing frameworks.
|
it into all of the *other* Python Web testing frameworks.
|
||||||
|
|
||||||
The Python 2 version of wsgi-intercept was the result. Kumar McMillan
|
The Python 2 version of wsgi-intercept was the result. Kumar McMillan
|
||||||
later took over maintenance.
|
later took over maintenance.
|
||||||
|
|
||||||
The current version works with Python 2.7, 3.3, 3.4 and 3.5 and was assembled
|
The current version is tested with Python 2.7, 3.3, 3.4, 3.5 and pypy
|
||||||
by `Chris Dent`_. Testing and documentation improvements from `Sasha Hart`_.
|
and was assembled by `Chris Dent`_. Testing and documentation improvements
|
||||||
|
from `Sasha Hart`_.
|
||||||
|
|
||||||
.. _twill: http://www.idyll.org/~t/www-tools/twill.html
|
.. _"best Web testing framework":
|
||||||
.. _"best Web testing framework": http://blog.ianbicking.org/best-of-the-web-app-test-frameworks.html
|
http://blog.ianbicking.org/best-of-the-web-app-test-frameworks.html
|
||||||
.. _in-process HTTP-to-WSGI interception mechanism: http://www.advogato.org/person/titus/diary.html?start=119
|
.. _in-process HTTP-to-WSGI interception mechanism:
|
||||||
|
http://www.advogato.org/person/titus/diary.html?start=119
|
||||||
.. _WSGI application: http://www.python.org/peps/pep-3333.html
|
.. _WSGI application: http://www.python.org/peps/pep-3333.html
|
||||||
.. _Chris Dent: https://github.com/cdent
|
.. _Chris Dent: https://github.com/cdent
|
||||||
.. _Sasha Hart: https://github.com/sashahart
|
.. _Sasha Hart: https://github.com/sashahart
|
||||||
@@ -120,10 +121,13 @@ Additional documentation is available on `Read The Docs`_.
|
|||||||
"""
|
"""
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
|
||||||
__version__ = '1.3.2'
|
__version__ = '1.3.2'
|
||||||
|
|
||||||
|
|
||||||
import sys
|
|
||||||
try:
|
try:
|
||||||
from http.client import HTTPConnection, HTTPSConnection
|
from http.client import HTTPConnection, HTTPSConnection
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@@ -139,7 +143,6 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
from urllib import unquote as url_unquote
|
from urllib import unquote as url_unquote
|
||||||
|
|
||||||
import traceback
|
|
||||||
|
|
||||||
debuglevel = 0
|
debuglevel = 0
|
||||||
# 1 basic
|
# 1 basic
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ def make_urllib3_override(HTTPConnectionPool, HTTPSConnectionPool,
|
|||||||
WSGI_HTTPConnection.__init__(self, *args, **kwargs)
|
WSGI_HTTPConnection.__init__(self, *args, **kwargs)
|
||||||
HTTPConnection.__init__(self, *args, **kwargs)
|
HTTPConnection.__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class HTTPS_WSGIInterceptor(WSGI_HTTPSConnection, HTTPSConnection):
|
class HTTPS_WSGIInterceptor(WSGI_HTTPSConnection, HTTPSConnection):
|
||||||
is_verified = True
|
is_verified = True
|
||||||
|
|
||||||
@@ -29,7 +28,6 @@ def make_urllib3_override(HTTPConnectionPool, HTTPSConnectionPool,
|
|||||||
WSGI_HTTPSConnection.__init__(self, *args, **kwargs)
|
WSGI_HTTPSConnection.__init__(self, *args, **kwargs)
|
||||||
HTTPSConnection.__init__(self, *args, **kwargs)
|
HTTPSConnection.__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def install():
|
def install():
|
||||||
if 'http_proxy' in os.environ or 'https_proxy' in os.environ:
|
if 'http_proxy' in os.environ or 'https_proxy' in os.environ:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
@@ -37,7 +35,6 @@ def make_urllib3_override(HTTPConnectionPool, HTTPSConnectionPool,
|
|||||||
HTTPConnectionPool.ConnectionCls = HTTP_WSGIInterceptor
|
HTTPConnectionPool.ConnectionCls = HTTP_WSGIInterceptor
|
||||||
HTTPSConnectionPool.ConnectionCls = HTTPS_WSGIInterceptor
|
HTTPSConnectionPool.ConnectionCls = HTTPS_WSGIInterceptor
|
||||||
|
|
||||||
|
|
||||||
def uninstall():
|
def uninstall():
|
||||||
HTTPConnectionPool.ConnectionCls = HTTPConnection
|
HTTPConnectionPool.ConnectionCls = HTTPConnection
|
||||||
HTTPSConnectionPool.ConnectionCls = HTTPSConnection
|
HTTPSConnectionPool.ConnectionCls = HTTPSConnection
|
||||||
|
|||||||
Reference in New Issue
Block a user