[Python-checkins] cpython (merge 3.3 -> default): merge from 3.3

senthil.kumaran python-checkins at python.org
Thu Apr 11 05:54:36 CEST 2013


http://hg.python.org/cpython/rev/7b3f1c6a67d9
changeset:   83242:7b3f1c6a67d9
parent:      83239:0b2d4089180c
parent:      83241:5f8fe382f9db
user:        Senthil Kumaran <senthil at uthcode.com>
date:        Wed Apr 10 20:53:12 2013 -0700
summary:
  merge from 3.3

#5609 - test_urllib coverage for url2pathname and pathname2url. Patch
contribution by Thomas Fenzl & Maksim Kozyarchuk

files:
  Lib/test/test_urllib.py |  76 ++++++++++++++++++++++------
  1 files changed, 58 insertions(+), 18 deletions(-)


diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -11,10 +11,12 @@
 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 @@
 
 # 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 @@
 #         self.assertEqual(ftp.ftp.sock.gettimeout(), 30)
 #         ftp.close()
 
+
 class RequestTests(unittest.TestCase):
     """Unit tests for urllib.request.Request."""
 
@@ -1387,25 +1392,60 @@
         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()

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list