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:
Chris Dent 2016-09-22 19:27:01 +01:00
parent b6ea4bce1b
commit 2504de1f73
8 changed files with 36 additions and 22 deletions

View File

@ -12,8 +12,7 @@ env:
- TOXENV=py34
- TOXENV=py35
- TOXENV=pypy
# XXX: known to fail, fixes to follow
#- TOXENV=pep8
- TOXENV=pep8
- TOXENV=docs
notifications:

View File

@ -23,7 +23,9 @@ META = {
'version': wsgi_intercept.__version__,
'author': 'Titus Brown, Kumar McMillan, Chris Dent, Sasha Hart',
'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?
'url': 'http://pypi.python.org/pypi/wsgi_intercept',
'long_description': wsgi_intercept.__doc__,

View File

@ -26,6 +26,7 @@ from .wsgi_app import simple_app
httppool = urllib3.PoolManager()
def app():
return simple_app

View File

@ -23,6 +23,7 @@ def teardown_module(module):
def test_simple_request():
global host
http = Http()
response, content = http.request('http://%s/' % host)
assert response.status == 200
@ -30,6 +31,7 @@ def test_simple_request():
def test_another_request():
global host
http = Http()
response, content = http.request('http://%s/foobar' % host)
assert response.status == 200

View File

@ -1,6 +1,5 @@
import os
import py.test
import socket
from wsgi_intercept import urllib3_intercept, WSGIAppError
from test import wsgi_app
from test.install import installer_class, skipnetwork
@ -14,7 +13,8 @@ http = urllib3.PoolManager()
def test_http():
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 app.success()
@ -28,7 +28,8 @@ def test_http_default_port():
def test_http_other_port():
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 app.success()
environ = app.get_internals()
@ -39,7 +40,8 @@ def test_bogus_domain():
with InstalledApp(wsgi_app.simple_app, host=HOST, port=80):
py.test.raises(
urllib3.exceptions.ProtocolError,
'http.request("GET", "http://_nonexistant_domain_", retries=False)')
'http.request("GET", "http://_nonexistant_domain_", '
'retries=False)')
def test_proxy_handling():
@ -56,14 +58,16 @@ def test_proxy_handling():
def test_https():
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 app.success()
def test_https_default_port():
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 app.success()
environ = app.get_internals()

View File

@ -60,7 +60,13 @@ def test_more_interesting():
assert internal_env['QUERY_STRING'] == 'bar=baz%20zoom'
assert internal_env['HTTP_ACCEPT'] == 'application/json'
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.
if sys.version_info[0] > 2:

View File

@ -1,4 +1,3 @@
"""Installs a WSGI application in place of a real host for testing.
Introduction
@ -89,19 +88,21 @@ History
Pursuant to Ian Bicking's `"best Web testing framework"`_ post, Titus
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
it into all of the *other* Python Web testing frameworks.
The Python 2 version of wsgi-intercept was the result. Kumar McMillan
later took over maintenance.
The current version works with Python 2.7, 3.3, 3.4 and 3.5 and was assembled
by `Chris Dent`_. Testing and documentation improvements from `Sasha Hart`_.
The current version is tested with Python 2.7, 3.3, 3.4, 3.5 and pypy
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": 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
.. _"best Web testing framework":
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
.. _WSGI application: http://www.python.org/peps/pep-3333.html
.. _Chris Dent: https://github.com/cdent
.. _Sasha Hart: https://github.com/sashahart
@ -120,10 +121,13 @@ Additional documentation is available on `Read The Docs`_.
"""
from __future__ import print_function
import sys
import traceback
__version__ = '1.3.2'
import sys
try:
from http.client import HTTPConnection, HTTPSConnection
except ImportError:
@ -139,7 +143,6 @@ try:
except ImportError:
from urllib import unquote as url_unquote
import traceback
debuglevel = 0
# 1 basic

View File

@ -19,7 +19,6 @@ def make_urllib3_override(HTTPConnectionPool, HTTPSConnectionPool,
WSGI_HTTPConnection.__init__(self, *args, **kwargs)
HTTPConnection.__init__(self, *args, **kwargs)
class HTTPS_WSGIInterceptor(WSGI_HTTPSConnection, HTTPSConnection):
is_verified = True
@ -29,7 +28,6 @@ def make_urllib3_override(HTTPConnectionPool, HTTPSConnectionPool,
WSGI_HTTPSConnection.__init__(self, *args, **kwargs)
HTTPSConnection.__init__(self, *args, **kwargs)
def install():
if 'http_proxy' in os.environ or 'https_proxy' in os.environ:
raise RuntimeError(
@ -37,7 +35,6 @@ def make_urllib3_override(HTTPConnectionPool, HTTPSConnectionPool,
HTTPConnectionPool.ConnectionCls = HTTP_WSGIInterceptor
HTTPSConnectionPool.ConnectionCls = HTTPS_WSGIInterceptor
def uninstall():
HTTPConnectionPool.ConnectionCls = HTTPConnection
HTTPSConnectionPool.ConnectionCls = HTTPSConnection