From 0186bd81db775573e4132cf49e41fd577d512aaf Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Sat, 1 May 2010 19:56:03 +0200 Subject: [PATCH] Expand path_to_uri functionality --- mopidy/utils.py | 3 ++- tests/utils_test.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mopidy/utils.py b/mopidy/utils.py index 3bde4a10..270079a3 100644 --- a/mopidy/utils.py +++ b/mopidy/utils.py @@ -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'): diff --git a/tests/utils_test.py b/tests/utils_test.py index 58d4becd..18ae0b8c 100644 --- a/tests/utils_test.py +++ b/tests/utils_test.py @@ -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')