Expand path_to_uri functionality

This commit is contained in:
Thomas Adamcik 2010-05-01 19:56:03 +02:00
parent 03a453eb64
commit 0186bd81db
2 changed files with 14 additions and 1 deletions

View File

@ -33,7 +33,8 @@ def get_or_create_dotdir(dotdir):
os.mkdir(dotdir, 0755)
return dotdir
def path_to_uri(path):
def path_to_uri(*paths):
path = os.path.join(*paths)
return 'file://' + urllib.pathname2url(path)
def indent(string, places=4, linebreak='\n'):

View File

@ -18,12 +18,24 @@ class PathToFileURITest(unittest.TestCase):
result = path_to_uri('c:/WINDOWS/clock.avi')
self.assertEqual(result, 'file:///c:/WINDOWS/clock.avi')
def test_folder_prefix_unix(self):
if sys.platform != 'win32':
return
result = path_to_uri('c:/WINDOWS/', 'clock.avi')
self.assertEqual(result, 'file:///c:/WINDOWS/clock.avi')
def test_unix_paths(self):
if sys.platform == 'win32':
return
result = path_to_uri('/etc/fstab')
self.assertEqual(result, 'file:///etc/fstab')
def test_folder_prefix_unix(self):
if sys.platform == 'win32':
return
result = path_to_uri('/etc', 'fstab')
self.assertEqual(result, 'file:///etc/fstab')
song1_path = data_folder('song1.mp3')
song2_path = data_folder('song2.mp3')