From 138f55cd9b13a85950559aa06f0f868dd088b248 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Mon, 30 Jan 2012 20:10:33 +0100 Subject: [PATCH] Spin off a test module. --- README | 2 +- rfc6266.py | 41 +---------------------------------------- setup.py | 2 +- test_rfc6266.py | 42 ++++++++++++++++++++++++++++++++++++++++++ tox.ini | 2 +- 5 files changed, 46 insertions(+), 43 deletions(-) create mode 100644 test_rfc6266.py diff --git a/README b/README index 88dec8b..1b00be7 100644 --- a/README +++ b/README @@ -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: diff --git a/rfc6266.py b/rfc6266.py index b066622..7398388 100644 --- a/rfc6266.py +++ b/rfc6266.py @@ -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 @@ -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!') - - diff --git a/setup.py b/setup.py index 3846a14..a1217f2 100644 --- a/setup.py +++ b/setup.py @@ -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, ) diff --git a/test_rfc6266.py b/test_rfc6266.py new file mode 100644 index 0000000..e293509 --- /dev/null +++ b/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!') + diff --git a/tox.ini b/tox.ini index cafcad1..37664a1 100644 --- a/tox.ini +++ b/tox.ini @@ -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