kopia lustrzana https://github.com/micropython/micropython-lib
urllib.urlparse: test_urlparse: Adapt for uPy.
Disable: byte/str mix tests, unicode handling, plus namedtuple reflection.pull/118/head
rodzic
f5a9ad2d61
commit
b2b2279561
|
@ -656,7 +656,7 @@ class UrlParseTestCase(unittest.TestCase):
|
||||||
self.assertEqual(urllib.parse.urlparse(b"x-newscheme://foo.com/stuff?query"),
|
self.assertEqual(urllib.parse.urlparse(b"x-newscheme://foo.com/stuff?query"),
|
||||||
(b'x-newscheme', b'foo.com', b'/stuff', b'', b'query', b''))
|
(b'x-newscheme', b'foo.com', b'/stuff', b'', b'query', b''))
|
||||||
|
|
||||||
def test_mixed_types_rejected(self):
|
def _test_mixed_types_rejected(self):
|
||||||
# Several functions that process either strings or ASCII encoded bytes
|
# Several functions that process either strings or ASCII encoded bytes
|
||||||
# accept multiple arguments. Check they reject mixed type input
|
# accept multiple arguments. Check they reject mixed type input
|
||||||
with self.assertRaisesRegex(TypeError, "Cannot mix str"):
|
with self.assertRaisesRegex(TypeError, "Cannot mix str"):
|
||||||
|
@ -680,8 +680,8 @@ class UrlParseTestCase(unittest.TestCase):
|
||||||
with self.assertRaisesRegex(TypeError, "Cannot mix str"):
|
with self.assertRaisesRegex(TypeError, "Cannot mix str"):
|
||||||
urllib.parse.urljoin(b"http://python.org", "http://python.org")
|
urllib.parse.urljoin(b"http://python.org", "http://python.org")
|
||||||
|
|
||||||
def _check_result_type(self, str_type):
|
def _check_result_type(self, str_type, num_args):
|
||||||
num_args = len(str_type._fields)
|
# num_args = len(str_type._fields)
|
||||||
bytes_type = str_type._encoded_counterpart
|
bytes_type = str_type._encoded_counterpart
|
||||||
self.assertIs(bytes_type._decoded_counterpart, str_type)
|
self.assertIs(bytes_type._decoded_counterpart, str_type)
|
||||||
str_args = ('',) * num_args
|
str_args = ('',) * num_args
|
||||||
|
@ -708,14 +708,14 @@ class UrlParseTestCase(unittest.TestCase):
|
||||||
def test_result_pairs(self):
|
def test_result_pairs(self):
|
||||||
# Check encoding and decoding between result pairs
|
# Check encoding and decoding between result pairs
|
||||||
result_types = [
|
result_types = [
|
||||||
urllib.parse.DefragResult,
|
(urllib.parse.DefragResult, 2),
|
||||||
urllib.parse.SplitResult,
|
(urllib.parse.SplitResult, 5),
|
||||||
urllib.parse.ParseResult,
|
(urllib.parse.ParseResult, 6),
|
||||||
]
|
]
|
||||||
for result_type in result_types:
|
for result_type in result_types:
|
||||||
self._check_result_type(result_type)
|
self._check_result_type(*result_type)
|
||||||
|
|
||||||
def test_parse_qs_encoding(self):
|
def _test_parse_qs_encoding(self):
|
||||||
result = urllib.parse.parse_qs("key=\u0141%E9", encoding="latin-1")
|
result = urllib.parse.parse_qs("key=\u0141%E9", encoding="latin-1")
|
||||||
self.assertEqual(result, {'key': ['\u0141\xE9']})
|
self.assertEqual(result, {'key': ['\u0141\xE9']})
|
||||||
result = urllib.parse.parse_qs("key=\u0141%C3%A9", encoding="utf-8")
|
result = urllib.parse.parse_qs("key=\u0141%C3%A9", encoding="utf-8")
|
||||||
|
@ -728,7 +728,7 @@ class UrlParseTestCase(unittest.TestCase):
|
||||||
errors="ignore")
|
errors="ignore")
|
||||||
self.assertEqual(result, {'key': ['\u0141-']})
|
self.assertEqual(result, {'key': ['\u0141-']})
|
||||||
|
|
||||||
def test_parse_qsl_encoding(self):
|
def _test_parse_qsl_encoding(self):
|
||||||
result = urllib.parse.parse_qsl("key=\u0141%E9", encoding="latin-1")
|
result = urllib.parse.parse_qsl("key=\u0141%E9", encoding="latin-1")
|
||||||
self.assertEqual(result, [('key', '\u0141\xE9')])
|
self.assertEqual(result, [('key', '\u0141\xE9')])
|
||||||
result = urllib.parse.parse_qsl("key=\u0141%C3%A9", encoding="utf-8")
|
result = urllib.parse.parse_qsl("key=\u0141%C3%A9", encoding="utf-8")
|
||||||
|
@ -776,8 +776,8 @@ class UrlParseTestCase(unittest.TestCase):
|
||||||
def test_to_bytes(self):
|
def test_to_bytes(self):
|
||||||
result = urllib.parse.to_bytes('http://www.python.org')
|
result = urllib.parse.to_bytes('http://www.python.org')
|
||||||
self.assertEqual(result, 'http://www.python.org')
|
self.assertEqual(result, 'http://www.python.org')
|
||||||
self.assertRaises(UnicodeError, urllib.parse.to_bytes,
|
# self.assertRaises(UnicodeError, urllib.parse.to_bytes,
|
||||||
'http://www.python.org/medi\u00e6val')
|
# 'http://www.python.org/medi\u00e6val')
|
||||||
|
|
||||||
def test_urlencode_sequences(self):
|
def test_urlencode_sequences(self):
|
||||||
# Other tests incidentally urlencode things; test non-covered cases:
|
# Other tests incidentally urlencode things; test non-covered cases:
|
||||||
|
|
Ładowanie…
Reference in New Issue