cpython: 7b3f1c6a67d9 (original) (raw)
--- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -11,10 +11,12 @@ from test import support import os import sys import tempfile +from nturl2path import url2pathname, pathname2url from base64 import b64encode import collections + def hexescape(char): """Escape char as RFC 2396 specifies""" hex_repr = hex(ord(char))[2:].upper() @@ -24,6 +26,8 @@ def hexescape(char):
Shortcut for testing FancyURLopener
_urlopener = None + + def urlopen(url, data=None, proxies=None): """urlopen(url [, data]) -> open file-like object""" global _urlopener @@ -1363,6 +1367,7 @@ class URLopener_Tests(unittest.TestCase)
self.assertEqual(ftp.ftp.sock.gettimeout(), 30)
ftp.close()
+ class RequestTests(unittest.TestCase): """Unit tests for urllib.request.Request.""" @@ -1387,25 +1392,60 @@ class RequestTests(unittest.TestCase): self.assertEqual(request.get_method(), 'HEAD') -def test_main():
- support.run_unittest(
urlopen_FileTests,[](#l1.39)
urlopen_HttpTests,[](#l1.40)
urlopen_DataTests,[](#l1.41)
urlretrieve_FileTests,[](#l1.42)
urlretrieve_HttpTests,[](#l1.43)
ProxyTests,[](#l1.44)
QuotingTests,[](#l1.45)
UnquotingTests,[](#l1.46)
urlencode_Tests,[](#l1.47)
Pathname_Tests,[](#l1.48)
Utility_Tests,[](#l1.49)
URLopener_Tests,[](#l1.50)
#FTPWrapperTests,[](#l1.51)
RequestTests,[](#l1.52)
- )
+class URL2PathNameTests(unittest.TestCase): +
- def test_converting_drive_letter(self):
self.assertEqual(url2pathname("///C|"), 'C:')[](#l1.57)
self.assertEqual(url2pathname("///C:"), 'C:')[](#l1.58)
self.assertEqual(url2pathname("///C|/"), 'C:\\')[](#l1.59)
- def test_converting_when_no_drive_letter(self):
# cannot end a raw string in \[](#l1.62)
self.assertEqual(url2pathname("///C/test/"), r'\\\C\test' '\\')[](#l1.63)
self.assertEqual(url2pathname("////C/test/"), r'\\C\test' '\\')[](#l1.64)
- def test_simple_compare(self):
self.assertEqual(url2pathname("///C|/foo/bar/spam.foo"),[](#l1.67)
r'C:\foo\bar\spam.foo')[](#l1.68)
- def test_non_ascii_drive_letter(self):
self.assertRaises(IOError, url2pathname, "///\u00e8|/")[](#l1.71)
- def test_roundtrip_url2pathname(self):
list_of_paths = ['C:',[](#l1.74)
r'\\\C\test\\',[](#l1.75)
r'C:\foo\bar\spam.foo'[](#l1.76)
][](#l1.77)
for path in list_of_paths:[](#l1.78)
self.assertEqual(url2pathname(pathname2url(path)), path)[](#l1.79)
+class PathName2URLTests(unittest.TestCase):
- def test_converting_drive_letter(self):
self.assertEqual(pathname2url("C:"), '///C:')[](#l1.84)
self.assertEqual(pathname2url("C:\\"), '///C:')[](#l1.85)
- def test_converting_when_no_drive_letter(self):
self.assertEqual(pathname2url(r"\\\folder\test" "\\"),[](#l1.88)
'/////folder/test/')[](#l1.89)
self.assertEqual(pathname2url(r"\\folder\test" "\\"),[](#l1.90)
'////folder/test/')[](#l1.91)
self.assertEqual(pathname2url(r"\folder\test" "\\"),[](#l1.92)
'/folder/test/')[](#l1.93)
- def test_simple_compare(self):
self.assertEqual(pathname2url(r'C:\foo\bar\spam.foo'),[](#l1.96)
"///C:/foo/bar/spam.foo" )[](#l1.97)