Refs #27804 -- Used subTest() in parse_accept_lang_header() test.

This commit is contained in:
Tom 2017-09-27 21:31:03 +01:00 committed by Tim Graham
parent 47016adbf5
commit f04e6732c3
1 changed files with 36 additions and 39 deletions

View File

@ -1098,45 +1098,42 @@ class MiscTests(SimpleTestCase):
values according to the spec (and that we extract all the pieces in values according to the spec (and that we extract all the pieces in
the right order). the right order).
""" """
p = trans_real.parse_accept_lang_header tests = [
# Good headers. # Good headers
self.assertEqual([('de', 1.0)], p('de')) ('de', [('de', 1.0)]),
self.assertEqual([('en-au', 1.0)], p('en-AU')) ('en-AU', [('en-au', 1.0)]),
self.assertEqual([('es-419', 1.0)], p('es-419')) ('es-419', [('es-419', 1.0)]),
self.assertEqual([('*', 1.0)], p('*;q=1.00')) ('*;q=1.00', [('*', 1.0)]),
self.assertEqual([('en-au', 0.123)], p('en-AU;q=0.123')) ('en-AU;q=0.123', [('en-au', 0.123)]),
self.assertEqual([('en-au', 0.5)], p('en-au;q=0.5')) ('en-au;q=0.5', [('en-au', 0.5)]),
self.assertEqual([('en-au', 1.0)], p('en-au;q=1.0')) ('en-au;q=1.0', [('en-au', 1.0)]),
self.assertEqual([('da', 1.0), ('en', 0.5), ('en-gb', 0.25)], p('da, en-gb;q=0.25, en;q=0.5')) ('da, en-gb;q=0.25, en;q=0.5', [('da', 1.0), ('en', 0.5), ('en-gb', 0.25)]),
self.assertEqual([('en-au-xx', 1.0)], p('en-au-xx')) ('en-au-xx', [('en-au-xx', 1.0)]),
self.assertEqual( ('de,en-au;q=0.75,en-us;q=0.5,en;q=0.25,es;q=0.125,fa;q=0.125',
[('de', 1.0), ('en-au', 0.75), ('en-us', 0.5), ('en', 0.25), ('es', 0.125), ('fa', 0.125)], [('de', 1.0), ('en-au', 0.75), ('en-us', 0.5), ('en', 0.25), ('es', 0.125), ('fa', 0.125)]),
p('de,en-au;q=0.75,en-us;q=0.5,en;q=0.25,es;q=0.125,fa;q=0.125') ('*', [('*', 1.0)]),
) ('de;q=0.', [('de', 0.0)]),
self.assertEqual([('*', 1.0)], p('*')) ('en; q=1,', [('en', 1.0)]),
self.assertEqual([('de', 0.0)], p('de;q=0.')) ('en; q=1.0, * ; q=0.5', [('en', 1.0), ('*', 0.5)]),
self.assertEqual([('en', 1.0), ('*', 0.5)], p('en; q=1.0, * ; q=0.5')) # Bad headers
self.assertEqual([('en', 1.0)], p('en; q=1,')) ('en-gb;q=1.0000', []),
self.assertEqual([], p('')) ('en;q=0.1234', [], ),
('en;q=.2', []),
# Bad headers; should always return []. ('abcdefghi-au', []),
self.assertEqual([], p('en-gb;q=1.0000')) ('**', []),
self.assertEqual([], p('en;q=0.1234')) ('en,,gb', []),
self.assertEqual([], p('en;q=.2')) ('en-au;q=0.1.0', []),
self.assertEqual([], p('abcdefghi-au')) (('X' * 97) + 'Z,en', []),
self.assertEqual([], p('**')) ('da, en-gb;q=0.8, en;q=0.7,#', []),
self.assertEqual([], p('en,,gb')) ('de;q=2.0', []),
self.assertEqual([], p('en-au;q=0.1.0')) ('de;q=0.a', []),
self.assertEqual( ('12-345', []),
[], ('', []),
p('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXZ,en') ('en;q=1e0', []),
) ]
self.assertEqual([], p('da, en-gb;q=0.8, en;q=0.7,#')) for value, expected in tests:
self.assertEqual([], p('de;q=2.0')) with self.subTest(value=value):
self.assertEqual([], p('de;q=0.a')) self.assertEqual(trans_real.parse_accept_lang_header(value), expected)
self.assertEqual([], p('12-345'))
self.assertEqual([], p(''))
self.assertEqual([], p('en;q=1e0'))
def test_parse_literal_http_header(self): def test_parse_literal_http_header(self):
""" """