summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2009-03-26 16:57:30 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2009-03-26 16:57:30 (GMT)
commit1ef7c6bc85988092b7c4b964309b9e3f3a62afd9 (patch)
tree050ef436977c74ca3602ff7bc5f7ca1c06e7f3be /Lib/test
parent230feba5fd4ca3db18775d3cfa89e42284833aac (diff)
downloadcpython-1ef7c6bc85988092b7c4b964309b9e3f3a62afd9.zip
cpython-1ef7c6bc85988092b7c4b964309b9e3f3a62afd9.tar.gz
cpython-1ef7c6bc85988092b7c4b964309b9e3f3a62afd9.tar.bz2
Add a few more tests for urllib.parse.urlencode.
Fix some long lines.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_urllib.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
index a684ed4..79e901f 100644
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -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()"""