From 56f1de4c5ca3b6cf1f1e14b23300653e232337c7 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Mon, 19 Nov 2012 08:50:09 +0000 Subject: [PATCH] * morituri/image/toc.py: * morituri/test/test_image_toc.py: Add test for getRealPath. Fix bug found by it for absolute paths. --- ChangeLog | 6 ++++++ morituri/image/toc.py | 13 ++++++++----- morituri/test/test_image_toc.py | 11 +++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 734c92e..cb8237f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2012-11-19 Thomas Vander Stichele + + * morituri/image/toc.py: + * morituri/test/test_image_toc.py: + Add test for getRealPath. Fix bug found by it for absolute paths. + 2012-11-18 Thomas Vander Stichele * morituri/image/table.py: diff --git a/morituri/image/toc.py b/morituri/image/toc.py index 3b16476..70d5d0c 100644 --- a/morituri/image/toc.py +++ b/morituri/image/toc.py @@ -324,7 +324,7 @@ class TocFile(object, log.Loggable): def getRealPath(self, path): """ - Translate the .cue's FILE to an existing path. + Translate the .toc's FILE to an existing path. @type path: unicode """ @@ -334,15 +334,18 @@ class TocFile(object, log.Loggable): return path # .cue FILE statements have Windows-style path separators, so convert - tpath = os.path.join(*path.split('\\')) + parts = path.split('\\') + if parts[0] == '': + parts[0] = os.path.sep + tpath = os.path.join(*parts) candidatePaths = [] - # if the path is relative: - # - check relatively to the cue file - # - check only the filename part relative to the cue file if tpath == os.path.abspath(tpath): candidatePaths.append(tpath) else: + # if the path is relative: + # - check relatively to the cue file + # - check only the filename part relative to the cue file candidatePaths.append(os.path.join( os.path.dirname(self._path), tpath)) candidatePaths.append(os.path.join( diff --git a/morituri/test/test_image_toc.py b/morituri/test/test_image_toc.py index 67362ba..fb44a48 100644 --- a/morituri/test/test_image_toc.py +++ b/morituri/test/test_image_toc.py @@ -92,6 +92,17 @@ class CureTestCase(common.TestCase): 'http://www.accuraterip.com/accuraterip/' '3/c/4/dBAR-013-0019d4c3-00fe8924-b90c650d.bin') + + def testGetRealPath(self): + self.assertRaises(KeyError, self.toc.getRealPath, u'track01.wav') + (fd, path) = tempfile.mkstemp(suffix=u'.morituri.test.wav') + self.assertEquals(self.toc.getRealPath(path), path) + + winpath = path.replace('/', '\\') + self.assertEquals(self.toc.getRealPath(winpath), path) + os.close(fd) + os.unlink(path) + # Bloc Party - Silent Alarm has a Hidden Track One Audio