Skip to content

Commit

Permalink
Spin off a test module.
Browse files Browse the repository at this point in the history
  • Loading branch information
g2p committed Feb 1, 2012
1 parent 3419ddb commit 138f55c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 43 deletions.
2 changes: 1 addition & 1 deletion README
Expand Up @@ -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:

Expand Down
41 changes: 1 addition & 40 deletions rfc6266.py
Expand Up @@ -277,8 +277,7 @@ def CaseInsensitiveLiteral(lit):
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

Expand Down Expand Up @@ -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!')


2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -4,7 +4,7 @@
setup(
name='rfc6266',
version='0.0.1', # symver
py_modules=['rfc6266'],
py_modules=['rfc6266', 'test_rfc6266'],
install_requires=['LEPL'],
use_2to3=True,
)
Expand Down
42 changes: 42 additions & 0 deletions test_rfc6266.py
@@ -0,0 +1,42 @@
# 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!')

2 changes: 1 addition & 1 deletion tox.ini
Expand Up @@ -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

0 comments on commit 138f55c

Please sign in to comment.