Fixed test_utils_url, broken on Windows after recent Python urllib change. Closes #251

This commit is contained in:
Pablo Hoffman 2010-09-26 16:57:42 -03:00
parent 1ef2cd400c
commit 5d4e0655d0
2 changed files with 6 additions and 4 deletions

View File

@ -277,7 +277,7 @@ class UrlUtilsTest(unittest.TestCase):
def test_path_to_file_uri(self):
if os.name == 'nt':
self.assertEqual(path_to_file_uri("C:\\windows\clock.avi"),
"file:///C|/windows/clock.avi")
"file:///C:/windows/clock.avi")
else:
self.assertEqual(path_to_file_uri("/some/path.txt"),
"file:///some/path.txt")
@ -289,9 +289,9 @@ class UrlUtilsTest(unittest.TestCase):
def test_file_uri_to_path(self):
if os.name == 'nt':
self.assertEqual(file_uri_to_path("file:///C|/windows/clock.avi"),
self.assertEqual(file_uri_to_path("file:///C:/windows/clock.avi"),
"C:\\windows\clock.avi")
uri = "file:///C|/windows/clock.avi"
uri = "file:///C:/windows/clock.avi"
uri2 = path_to_file_uri(file_uri_to_path(uri))
self.assertEqual(uri, uri2)
else:
@ -309,7 +309,7 @@ class UrlUtilsTest(unittest.TestCase):
def test_any_to_uri(self):
if os.name == 'nt':
self.assertEqual(any_to_uri("C:\\windows\clock.avi"),
"file:///C|/windows/clock.avi")
"file:///C:/windows/clock.avi")
else:
self.assertEqual(any_to_uri("/some/path.txt"),
"file:///some/path.txt")

View File

@ -161,6 +161,8 @@ def path_to_file_uri(path):
http://en.wikipedia.org/wiki/File_URI_scheme
"""
x = urllib.pathname2url(os.path.abspath(path))
if os.name == 'nt':
x = x.replace('|', ':') # http://bugs.python.org/issue5861
return 'file:///%s' % x.lstrip('/')
def file_uri_to_path(uri):