Commit ebdaa726 by Gabriel

Use pytest-localserver for http testing.

That means switching from nose to pytest.

pytest-localserver is a pytest plugin providing an http server
stub. The plugin doesn't work with Python3 however, and has to
be blacklisted in tox.
parent 138f55cd
...@@ -35,7 +35,7 @@ Currently tested under Python 2.7, Python 2.6, Python 3.2, and PyPy (1.7). ...@@ -35,7 +35,7 @@ Currently tested under Python 2.7, Python 2.6, Python 3.2, and PyPy (1.7).
To test in the current Python implementation: To test in the current Python implementation:
nosetests --detailed-errors py.test
To test with tox: To test with tox:
......
# vim: set fileencoding=utf-8 sw=4 ts=4 et : # vim: set fileencoding=utf-8 sw=4 ts=4 et :
from rfc6266 import parse_headers, build_header from rfc6266 import (
parse_headers, parse_httplib2_response, parse_requests_response,
build_header)
import pytest
def test_parsing(): def test_parsing():
...@@ -20,6 +23,25 @@ def test_parsing(): ...@@ -20,6 +23,25 @@ def test_parsing():
assert cd.filename_unsafe == u'€ rates' assert cd.filename_unsafe == u'€ rates'
@pytest.mark.skipif("sys.version_info >= (3,0)")
def test_httplib2(httpserver):
httplib2 = pytest.importorskip('httplib2')
http = httplib2.Http()
httpserver.serve_content('eep', headers={
'Content-Disposition': 'attachment; filename="a b="'})
resp, content = http.request(httpserver.url)
assert parse_httplib2_response(resp).filename_unsafe == 'a b='
@pytest.mark.skipif("sys.version_info >= (3,0)")
def test_requests(httpserver):
requests = pytest.importorskip('requests')
httpserver.serve_content('eep', headers={
'Content-Disposition': 'attachment; filename="a b="'})
resp = requests.get(httpserver.url)
assert parse_requests_response(resp).filename_unsafe == 'a b='
def test_location_fallback(): def test_location_fallback():
assert parse_headers( assert parse_headers(
None, location='https://foo/bar%c3%a9.py' None, location='https://foo/bar%c3%a9.py'
......
...@@ -2,9 +2,20 @@ ...@@ -2,9 +2,20 @@
envlist=py27,py26,py32,pypy envlist=py27,py26,py32,pypy
[testenv] [testenv]
deps=nose deps=
# changedir is a hack to prevent nose from finding the non-2to3 source pytest
# now nose will use import, which has the converted modules in its path pytest-localserver
httplib2
requests
commands=py.test --pyargs test_rfc6266
[testenv:py32]
# pytest-localserver isn't py3k-compatible;
# httplib2 and requests can't be tested
deps=
pytest
# Changedir is a hack to prevent test discovery from finding the non-2to3
# source. We want tests to be import-based only.
changedir=.tox changedir=.tox
commands=nosetests --detailed-errors test_rfc6266
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment