Commit 138f55cd by Gabriel

Spin off a test module.

parent 3419ddbd
......@@ -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:
nosetests --all-modules --detailed-errors
nosetests --detailed-errors
To test with tox:
......
......@@ -277,8 +277,7 @@ qdtext = AnyBut('"' + ctl_chars)
char = Any(''.join(chr(i) for i in xrange(128))) # ascii range: 0-127
quoted_pair = Drop('\\') + char
quoted_string = (Drop('"') & (quoted_pair | qdtext)[:, ...] & Drop('"')
) #> parse_iso
quoted_string = Drop('"') & (quoted_pair | qdtext)[:, ...] & Drop('"')
value = token | quoted_string
......@@ -411,41 +410,3 @@ def build_header(
# This will only encode filename_compat, if it used non-ascii iso-8859-1.
return rv.encode('iso-8859-1')
def test_parsing():
assert parse_headers(None).disposition == 'inline'
assert parse_headers('attachment').disposition == 'attachment'
assert parse_headers('attachment; key=val').assocs['key'] == 'val'
assert parse_headers(
'attachment; filename=simple').filename_unsafe == 'simple'
# test ISO-8859-1
fname = parse_headers(u'attachment; filename="oyé"').filename_unsafe
assert fname == u'oyé', repr(fname)
cd = parse_headers(
'attachment; filename="EURO rates";'
' filename*=utf-8\'\'%e2%82%ac%20rates')
assert cd.filename_unsafe == u'€ rates'
def test_location_fallback():
assert parse_headers(
None, location='https://foo/bar%c3%a9.py').filename_unsafe == u'baré.py'
def test_roundtrip():
def roundtrip(filename):
return parse_headers(build_header(filename)).filename_unsafe
def assert_roundtrip(filename):
assert roundtrip(filename) == filename
assert_roundtrip('a b')
assert_roundtrip('a b')
assert_roundtrip('a b ')
assert_roundtrip(' a b')
assert_roundtrip('a\"b')
assert_roundtrip(u'aéio o♥u"qfsdf!')
......@@ -4,7 +4,7 @@ from setuptools import setup
setup(
name='rfc6266',
version='0.0.1', # symver
py_modules=['rfc6266'],
py_modules=['rfc6266', 'test_rfc6266'],
install_requires=['LEPL'],
use_2to3=True,
)
......
# vim: set fileencoding=utf-8 sw=4 ts=4 et :
from rfc6266 import parse_headers, build_header
def test_parsing():
assert parse_headers(None).disposition == 'inline'
assert parse_headers('attachment').disposition == 'attachment'
assert parse_headers('attachment; key=val').assocs['key'] == 'val'
assert parse_headers(
'attachment; filename=simple').filename_unsafe == 'simple'
# test ISO-8859-1
fname = parse_headers(u'attachment; filename="oyé"').filename_unsafe
assert fname == u'oyé', repr(fname)
cd = parse_headers(
'attachment; filename="EURO rates";'
' filename*=utf-8\'\'%e2%82%ac%20rates')
assert cd.filename_unsafe == u'€ rates'
def test_location_fallback():
assert parse_headers(
None, location='https://foo/bar%c3%a9.py'
).filename_unsafe == u'baré.py'
def test_roundtrip():
def roundtrip(filename):
return parse_headers(build_header(filename)).filename_unsafe
def assert_roundtrip(filename):
assert roundtrip(filename) == filename
assert_roundtrip('a b')
assert_roundtrip('a b')
assert_roundtrip('a b ')
assert_roundtrip(' a b')
assert_roundtrip('a\"b')
assert_roundtrip(u'aéio o♥u"qfsdf!')
......@@ -6,5 +6,5 @@ deps=nose
# changedir is a hack to prevent nose from finding the non-2to3 source
# now nose will use import, which has the converted modules in its path
changedir=.tox
commands=nosetests --detailed-errors rfc6266
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