Merge pull request #44 from cdent/use-tox

Use tox
This commit is contained in:
Chris Dent 2016-09-23 12:57:01 +01:00 committed by GitHub
commit e58af412b6
20 changed files with 94 additions and 44 deletions

View File

@ -1,11 +1,19 @@
sudo: false
language: python
python:
- 2.7
- 3.3
- 3.4
- 3.5
script: make test
- "3.5"
install:
- pip install \
`python -c 'from setup import META; print(" ".join(META["extras_require"]["testing"]))'`
- pip install tox
script:
- tox
env:
- TOXENV=py27
- TOXENV=py33
- TOXENV=py34
- TOXENV=py35
- TOXENV=pypy
- TOXENV=pep8
- TOXENV=docs
notifications:
irc: "chat.freenode.net#gabbi"

View File

@ -1,3 +1,2 @@
include LICENSE Makefile
recursive-include test *
recursive-include docs *

View File

@ -24,7 +24,7 @@ reclean:
cd docs && make clean
test:
py.test --tb=short -x test
tox --skip-missing-interpreters
doctest:
cd docs && make doctest
@ -39,6 +39,6 @@ pypi:
python setup.py sdist upload
docs:
cd docs && $(MAKE) html
tox -edocs
release: clean test tagv reclean pypi

View File

@ -27,6 +27,6 @@ Example:
url = 'http://{0}:{1}/'.format(host, port)
urllib3_intercept.install()
add_wsgi_intercept(host, port, make_app)
resp = pool.requests('GET', url)
resp = pool.request('GET', url)
assert resp.data == b'Whee'
urllib3_intercept.uninstall()

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__,
@ -40,6 +42,9 @@ META = {
'requests>=2.0.1',
'urllib3>=1.11.0',
],
'docs': [
'sphinx',
],
},
}

25
tox.ini Normal file
View File

@ -0,0 +1,25 @@
[tox]
minversion = 1.6
skipsdist = True
envlist = py27,py33,py34,py35,pypy,pep8,docs
[testenv]
deps = .[testing]
commands = py.test --tb=short wsgi_intercept/tests
passenv = WSGI_INTERCEPT_*
[testenv:pep8]
deps = flake8
commands =
flake8 wsgi_intercept
[testenv:docs]
deps = .[docs,testing]
commands =
python setup.py build_sphinx
whitelist_externals =
rm
[flake8]
exclude=.venv,.git,.tox,dist,*egg,*.egg-info,build,examples,docs
show-source = True

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

View File

@ -1,7 +1,7 @@
import py.test
from wsgi_intercept import http_client_intercept, WSGIAppError
from test import wsgi_app
from test.install import installer_class, skipnetwork
from . import wsgi_app
from .install import installer_class, skipnetwork
try:
import http.client as http_lib
except ImportError:

View File

@ -1,7 +1,7 @@
import py.test
from wsgi_intercept import httplib2_intercept, WSGIAppError
from test import wsgi_app
from test.install import installer_class
from . import wsgi_app
from .install import installer_class
import httplib2
from socket import gaierror

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,8 +1,8 @@
import os
import py.test
from wsgi_intercept import requests_intercept, WSGIAppError
from test import wsgi_app
from test.install import installer_class, skipnetwork
from . import wsgi_app
from .install import installer_class, skipnetwork
import requests
from requests.exceptions import ConnectionError

View File

@ -1,8 +1,8 @@
import os
import py.test
from wsgi_intercept import urllib_intercept, WSGIAppError
from test import wsgi_app
from test.install import installer_class, skipnetwork
from . import wsgi_app
from .install import installer_class, skipnetwork
try:
import urllib.request as url_lib
except ImportError:

View File

@ -1,9 +1,8 @@
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
from . import wsgi_app
from .install import installer_class, skipnetwork
import urllib3
HOST = 'some_hopefully_nonexistant_domain'
@ -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

@ -5,8 +5,8 @@ try:
except ImportError:
from urllib import unquote
from wsgi_intercept import httplib2_intercept
from test import wsgi_app
from test.install import installer_class
from . import wsgi_app
from .install import installer_class
import httplib2
HOST = 'some_hopefully_nonexistant_domain'
@ -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: