completely forget about mechanize

This commit is contained in:
Sasha Hart
2014-07-29 13:51:23 -05:00
parent e0739fd941
commit 992f5650bd
5 changed files with 2 additions and 140 deletions

View File

@@ -26,7 +26,6 @@ with a working implementation in Python 2 for:
* `httplib`
* `httplib2`
* `requests`
* `mechanize`
and in Python 3 for:

View File

@@ -35,7 +35,6 @@ META = {
'pytest>=2.4',
'httplib2',
'requests>=2.0.1',
'mechanize>=0.2.5',
],
},
}

View File

@@ -1,102 +0,0 @@
import sys
import platform
import py.test
from wsgi_intercept import WSGIAppError
from test import wsgi_app
from test.install import installer_class
try:
import urllib.request as url_lib
except ImportError:
import urllib2 as url_lib
# Without this conditional, the import of mechanize_intercept attempts
# to import mechanize, which cannot be installed on Python3 and throws
# exceptions on PyPy, resulting in a spurious error during test
# collection.
CAN_RUN_TESTS = (
sys.version_info < (3, 0) and platform.python_implementation() != 'PyPy'
)
if CAN_RUN_TESTS:
from wsgi_intercept import mechanize_intercept
import mechanize
InstalledApp = installer_class(mechanize_intercept)
else:
InstalledApp = None
HOST = 'some_hopefully_nonexistent_domain'
ONLY_PYTHON2_NOT_PYPY = py.test.mark.skipif(
not CAN_RUN_TESTS,
reason="mechanize is not ported from Python 2 and fails in PyPy")
@ONLY_PYTHON2_NOT_PYPY
def test_http():
with InstalledApp(wsgi_app.simple_app, host=HOST, port=80) as app:
browser = mechanize.Browser()
url = 'http://some_hopefully_nonexistent_domain:80'
response = browser.open(url)
content = response.read()
assert content == b'WSGI intercept successful!\n'
assert app.success()
@ONLY_PYTHON2_NOT_PYPY
def test_http_default_port():
with InstalledApp(wsgi_app.simple_app, host=HOST, port=80) as app:
browser = mechanize.Browser()
url = 'http://some_hopefully_nonexistent_domain'
response = browser.open(url)
content = response.read()
assert content == b'WSGI intercept successful!\n'
assert app.success()
@ONLY_PYTHON2_NOT_PYPY
def test_http_other_port():
with InstalledApp(wsgi_app.simple_app, host=HOST, port=8080) as app:
browser = mechanize.Browser()
url = 'http://some_hopefully_nonexistent_domain:8080'
response = browser.open(url)
content = response.read()
assert content == b'WSGI intercept successful!\n'
assert app.success()
@ONLY_PYTHON2_NOT_PYPY
def test_bogus_domain():
with InstalledApp(wsgi_app.simple_app, host=HOST, port=80):
browser = mechanize.Browser()
with py.test.raises(url_lib.URLError):
browser.open('https://_nonexistent_domain')
@ONLY_PYTHON2_NOT_PYPY
def test_https():
with InstalledApp(wsgi_app.simple_app, host=HOST, port=443) as app:
browser = mechanize.Browser()
response = browser.open('https://some_hopefully_nonexistent_domain')
content = response.read()
assert content == b'WSGI intercept successful!\n'
assert app.success()
@ONLY_PYTHON2_NOT_PYPY
def test_https_default_port():
with InstalledApp(wsgi_app.simple_app, host=HOST, port=443) as app:
browser = mechanize.Browser()
response = browser.open('https://some_hopefully_nonexistent_domain:443')
content = response.read()
assert content == b'WSGI intercept successful!\n'
assert app.success()
@ONLY_PYTHON2_NOT_PYPY
def test_app_error():
with InstalledApp(wsgi_app.raises_app, host=HOST, port=80):
with py.test.raises(WSGIAppError):
browser = mechanize.Browser()
response = browser.open('http://some_hopefully_nonexistent_domain')
response.read()

View File

@@ -40,9 +40,8 @@ Packages Intercepted
Unfortunately each of the Web testing frameworks uses its own specific
mechanism for making HTTP call-outs, so individual implementations are
needed. At this time there are implementations for ``httplib2`` and
``requests`` in both Python 2 and 3, ``urllib2``, ``httplib`` and
``mechanize`` in Python 2 and ``urllib.request`` and ``http.client`` in
Python 3.
``requests`` in both Python 2 and 3, ``urllib2`` and ``httplib``
in Python 2 and ``urllib.request`` and ``http.client`` in Python 3.
If you are using Python 2 and need support for a different HTTP
client, require a version of ``wsgi_intercept<0.6``. Earlier versions

View File

@@ -1,33 +0,0 @@
"""Intercept HTTP connections that use `mechanize <http://wwwsearch.sourceforge.net/mechanize/>`_.
"""
import sys
import platform
assert sys.version_info < (3, 0), "mechanize cannot be installed in Python 3"
assert platform.python_implementation() != "PyPy", (
"mechanize does not import on PyPy"
)
import mechanize
from wsgi_intercept.urllib_intercept import WSGI_HTTPHandler, WSGI_HTTPSHandler
_ORIGINAL_BROWSER = mechanize.Browser
class Browser(_ORIGINAL_BROWSER):
"""mechanize Browser class with our WSGI intercept handlers installed.
"""
handler_classes = _ORIGINAL_BROWSER.handler_classes.copy()
handler_classes['http'] = WSGI_HTTPHandler
handler_classes['https'] = WSGI_HTTPSHandler
def __init__(self, *args, **kwargs):
_ORIGINAL_BROWSER.__init__(self, *args, **kwargs)
def install():
mechanize.Browser = Browser
def uninstall():
if mechanize.Browser == Browser:
mechanize.Browser = _ORIGINAL_BROWSER