Add a few more tests for urllib.parse.urlencode.
Fix some long lines.
This commit is contained in:
parent
230feba5fd
commit
1ef7c6bc85
|
@ -379,7 +379,8 @@ class QuotingTests(unittest.TestCase):
|
|||
result = urllib.parse.quote(quote_by_default, safe=quote_by_default)
|
||||
self.assertEqual(quote_by_default, result,
|
||||
"using quote(): %r != %r" % (quote_by_default, result))
|
||||
result = urllib.parse.quote_plus(quote_by_default, safe=quote_by_default)
|
||||
result = urllib.parse.quote_plus(quote_by_default,
|
||||
safe=quote_by_default)
|
||||
self.assertEqual(quote_by_default, result,
|
||||
"using quote_plus(): %r != %r" %
|
||||
(quote_by_default, result))
|
||||
|
@ -411,7 +412,8 @@ class QuotingTests(unittest.TestCase):
|
|||
for char in should_quote:
|
||||
result = urllib.parse.quote(char)
|
||||
self.assertEqual(hexescape(char), result,
|
||||
"using quote(): %s should be escaped to %s, not %s" %
|
||||
"using quote(): "
|
||||
"%s should be escaped to %s, not %s" %
|
||||
(char, hexescape(char), result))
|
||||
result = urllib.parse.quote_plus(char)
|
||||
self.assertEqual(hexescape(char), result,
|
||||
|
@ -770,6 +772,21 @@ class urlencode_Tests(unittest.TestCase):
|
|||
self.assertEqual(result.count('&'), 2,
|
||||
"Expected 2 '&'s, got %s" % result.count('&'))
|
||||
|
||||
def test_empty_sequence(self):
|
||||
self.assertEqual("", urllib.parse.urlencode({}))
|
||||
self.assertEqual("", urllib.parse.urlencode([]))
|
||||
|
||||
def test_nonstring_values(self):
|
||||
self.assertEqual("a=1", urllib.parse.urlencode({"a": 1}))
|
||||
self.assertEqual("a=None", urllib.parse.urlencode({"a": None}))
|
||||
|
||||
def test_nonstring_seq_values(self):
|
||||
self.assertEqual("a=1&a=2", urllib.parse.urlencode({"a": [1, 2]}, True))
|
||||
self.assertEqual("a=None&a=a",
|
||||
urllib.parse.urlencode({"a": [None, "a"]}, True))
|
||||
self.assertEqual("a=a&a=b",
|
||||
urllib.parse.urlencode({"a": {"a": 1, "b": 1}}, True))
|
||||
|
||||
class Pathname_Tests(unittest.TestCase):
|
||||
"""Test pathname2url() and url2pathname()"""
|
||||
|
||||
|
|
Loading…
Reference in New Issue