Ahh ... I see. I should have done a bit more digging to find where the
standard tests were.
I created a few new tests that could be included in that test suite --
see the attached file. Do you think that this would be sufficient?
- Dan
Bill Janssen wrote:
Dan Mahn <dan.m...@digidescorp.com> wrote:
Yes, that was a good idea. I found some problems, and attached a new
version. It looks more complicated than I wanted, but it is a very
regular repetition, so I hope it is generally readable.
That's great, but I was hoping for more tests in lib/test/test_urllib.py.
Bill
def test_encoding(self):
# Test for special character encoding
given = (("\u00a0", "\u00c1"),)
expect = '%3F=%3F'
result = urllib.parse.urlencode(given, encoding="ASCII",
errors="replace")
self.assertEqual(expect, result)
result = urllib.parse.urlencode(given, True, encoding="ASCII",
errors="replace")
self.assertEqual(expect, result)
given = (("\u00a0", (1, "\u00c1")),)
# ... now with default utf-8 ...
given = (("\u00a0", "\u00c1"),)
expect = '%C2%A0=%C3%81'
result = urllib.parse.urlencode(given)
self.assertEqual(expect, result)
# ... now with latin-1 ...
expect = '%A0=%C1'
result = urllib.parse.urlencode(given, encoding="latin-1")
self.assertEqual(expect, result)
# ... now with sequence ...
given = (("\u00a0", (1, "\u00c1")),)
expect = '%3F=1&%3F=%3F'
result = urllib.parse.urlencode(given, True, encoding="ASCII",
errors="replace")
self.assertEqual(expect, result)
# ... again with default utf-8 ...
given = (("\u00a0", "\u00c1"),)
expect = '%C2%A0=%C3%81'
result = urllib.parse.urlencode(given, True)
self.assertEqual(expect, result)
# ... again with latin-1 ...
expect = '%A0=%C1'
result = urllib.parse.urlencode(given, True, encoding="latin-1")
self.assertEqual(expect, result)
def test_bytes(self):
# Test for encoding bytes
given = ((b'\xa0\x24', b'\xc1\x24'),)
expect = '%A0%24=%C1%24'
result = urllib.parse.urlencode(given)
self.assertEqual(expect, result)
# ... now with sequence ...
result = urllib.parse.urlencode(given, True)
self.assertEqual(expect, result)
# ... now with safe and encoding ...
expect = '%A0$=%C1$'
result = urllib.parse.urlencode(given, safe=":$")
self.assertEqual(expect, result)
result = urllib.parse.urlencode(given, safe=":$", encoding="latin-1")
self.assertEqual(expect, result)
# ... again with sequence ...
result = urllib.parse.urlencode(given, True, safe=":$")
self.assertEqual(expect, result)
result = urllib.parse.urlencode(given, True, safe=":$",
encoding="latin-1")
self.assertEqual(expect, result)
# ... now with an actual sequence ...
given = ((b'\xa0\x24', (b'\xc1\x24', 0xd)),)
result = urllib.parse.urlencode(given, True, safe=":$")
self.assert_(expect in result,
"%s not found in %s" % (expect, result))
expect2 = '%A0$=1'
self.assert_(expect2 in result,
"%s not found in %s" % (expect2, result))
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com