summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_urllib.py
diff options
context:
space:
mode:
authorSenthil Kumaran <senthil@uthcode.com>2013-04-11 03:53:12 (GMT)
committerSenthil Kumaran <senthil@uthcode.com>2013-04-11 03:53:12 (GMT)
commit8b081b7ba1963c10b7c1a81241c6c7eee829b5b0 (patch)
treeb471887ef7235f6fae3a84888190040a8bb3e27f /Lib/test/test_urllib.py
parent34ad84d80a33c026c77389747c46e2aa272181c2 (diff)
parent277e9090b0aaf1ad0c0104750262804efdc957f3 (diff)
downloadcpython-8b081b7ba1963c10b7c1a81241c6c7eee829b5b0.zip
cpython-8b081b7ba1963c10b7c1a81241c6c7eee829b5b0.tar.gz
cpython-8b081b7ba1963c10b7c1a81241c6c7eee829b5b0.tar.bz2
merge from 3.3
#5609 - test_urllib coverage for url2pathname and pathname2url. Patch contribution by Thomas Fenzl & Maksim Kozyarchuk
Diffstat (limited to 'Lib/test/test_urllib.py')
-rw-r--r--Lib/test/test_urllib.py76
1 files changed, 58 insertions, 18 deletions
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
index cbe4327..cf57047 100644
--- 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,
- urlopen_HttpTests,
- urlopen_DataTests,
- urlretrieve_FileTests,
- urlretrieve_HttpTests,
- ProxyTests,
- QuotingTests,
- UnquotingTests,
- urlencode_Tests,
- Pathname_Tests,
- Utility_Tests,
- URLopener_Tests,
- #FTPWrapperTests,
- RequestTests,
- )
+class URL2PathNameTests(unittest.TestCase):
+
+ def test_converting_drive_letter(self):
+ self.assertEqual(url2pathname("///C|"), 'C:')
+ self.assertEqual(url2pathname("///C:"), 'C:')
+ self.assertEqual(url2pathname("///C|/"), 'C:\\')
+
+ def test_converting_when_no_drive_letter(self):
+ # cannot end a raw string in \
+ self.assertEqual(url2pathname("///C/test/"), r'\\\C\test' '\\')
+ self.assertEqual(url2pathname("////C/test/"), r'\\C\test' '\\')
+
+ def test_simple_compare(self):
+ self.assertEqual(url2pathname("///C|/foo/bar/spam.foo"),
+ r'C:\foo\bar\spam.foo')
+
+ def test_non_ascii_drive_letter(self):
+ self.assertRaises(IOError, url2pathname, "///\u00e8|/")
+
+ def test_roundtrip_url2pathname(self):
+ list_of_paths = ['C:',
+ r'\\\C\test\\',
+ r'C:\foo\bar\spam.foo'
+ ]
+ for path in list_of_paths:
+ self.assertEqual(url2pathname(pathname2url(path)), path)
+
+class PathName2URLTests(unittest.TestCase):
+
+ def test_converting_drive_letter(self):
+ self.assertEqual(pathname2url("C:"), '///C:')
+ self.assertEqual(pathname2url("C:\\"), '///C:')
+
+ def test_converting_when_no_drive_letter(self):
+ self.assertEqual(pathname2url(r"\\\folder\test" "\\"),
+ '/////folder/test/')
+ self.assertEqual(pathname2url(r"\\folder\test" "\\"),
+ '////folder/test/')
+ self.assertEqual(pathname2url(r"\folder\test" "\\"),
+ '/folder/test/')
+
+ def test_simple_compare(self):
+ self.assertEqual(pathname2url(r'C:\foo\bar\spam.foo'),
+ "///C:/foo/bar/spam.foo" )
+ def test_long_drive_letter(self):
+ self.assertRaises(IOError, pathname2url, "XX:\\")
+ def test_roundtrip_pathname2url(self):
+ list_of_paths = ['///C:',
+ '/////folder/test/',
+ '///C:/foo/bar/spam.foo']
+ for path in list_of_paths:
+ self.assertEqual(pathname2url(url2pathname(path)), path)
if __name__ == '__main__':
- test_main()
+ unittest.main()