MCPcopy Index your code
hub / github.com/python/cpython / test_quote_with_unicode

Method test_quote_with_unicode

Lib/test/test_urllib.py:933–973  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

931 % (expect, result))
932
933 def test_quote_with_unicode(self):
934 # Characters in Latin-1 range, encoded by default in UTF-8
935 given = "\xa2\xd8ab\xff"
936 expect = "%C2%A2%C3%98ab%C3%BF"
937 result = urllib.parse.quote(given)
938 self.assertEqual(expect, result,
939 "using quote(): %r != %r" % (expect, result))
940 # Characters in Latin-1 range, encoded by with None (default)
941 result = urllib.parse.quote(given, encoding=None, errors=None)
942 self.assertEqual(expect, result,
943 "using quote(): %r != %r" % (expect, result))
944 # Characters in Latin-1 range, encoded with Latin-1
945 given = "\xa2\xd8ab\xff"
946 expect = "%A2%D8ab%FF"
947 result = urllib.parse.quote(given, encoding="latin-1")
948 self.assertEqual(expect, result,
949 "using quote(): %r != %r" % (expect, result))
950 # Characters in BMP, encoded by default in UTF-8
951 given = "\u6f22\u5b57" # "Kanji"
952 expect = "%E6%BC%A2%E5%AD%97"
953 result = urllib.parse.quote(given)
954 self.assertEqual(expect, result,
955 "using quote(): %r != %r" % (expect, result))
956 # Characters in BMP, encoded with Latin-1
957 given = "\u6f22\u5b57"
958 self.assertRaises(UnicodeEncodeError, urllib.parse.quote, given,
959 encoding="latin-1")
960 # Characters in BMP, encoded with Latin-1, with replace error handling
961 given = "\u6f22\u5b57"
962 expect = "%3F%3F" # "??"
963 result = urllib.parse.quote(given, encoding="latin-1",
964 errors="replace")
965 self.assertEqual(expect, result,
966 "using quote(): %r != %r" % (expect, result))
967 # Characters in BMP, Latin-1, with xmlcharref error handling
968 given = "\u6f22\u5b57"
969 expect = "%26%2328450%3B%26%2323383%3B" # "漢字"
970 result = urllib.parse.quote(given, encoding="latin-1",
971 errors="xmlcharrefreplace")
972 self.assertEqual(expect, result,
973 "using quote(): %r != %r" % (expect, result))
974
975 def test_quote_plus_with_unicode(self):
976 # Encoding (latin-1) test for quote_plus

Callers

nothing calls this directly

Calls 3

quoteMethod · 0.80
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected