diff options
author | Senthil Kumaran <senthil@uthcode.com> | 2013-04-11 03:51:19 (GMT) |
---|---|---|
committer | Senthil Kumaran <senthil@uthcode.com> | 2013-04-11 03:51:19 (GMT) |
commit | 277e9090b0aaf1ad0c0104750262804efdc957f3 (patch) | |
tree | 7e090a65da4235e6346d6be8ca67b15339a7c8ca /Lib/test/test_urllib.py | |
parent | c9314d9e08309782010b56a41bb2d28c6a556302 (diff) | |
download | cpython-277e9090b0aaf1ad0c0104750262804efdc957f3.zip cpython-277e9090b0aaf1ad0c0104750262804efdc957f3.tar.gz cpython-277e9090b0aaf1ad0c0104750262804efdc957f3.tar.bz2 |
#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.py | 73 |
1 files changed, 56 insertions, 17 deletions
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py index 4f71b24..140e5c8 100644 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -11,6 +11,7 @@ from test import support import os import sys import tempfile +from nturl2path import url2pathname, pathname2url from base64 import b64encode import collections @@ -24,6 +25,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 @@ -1312,24 +1315,60 @@ class RequestTests(unittest.TestCase): self.assertEqual(request.get_method(), 'HEAD') -def test_main(): - support.run_unittest( - urlopen_FileTests, - urlopen_HttpTests, - 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() |