* morituri/image/toc.py:

* morituri/test/test_image_toc.py:
	  Add test for getRealPath.  Fix bug found by it for absolute paths.
This commit is contained in:
Thomas Vander Stichele
2012-11-19 08:50:09 +00:00
parent 76d587185d
commit 56f1de4c5c
3 changed files with 25 additions and 5 deletions

View File

@@ -1,3 +1,9 @@
2012-11-19 Thomas Vander Stichele <thomas at apestaart dot org>
* 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 <thomas at apestaart dot org>
* morituri/image/table.py:

View File

@@ -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(

View File

@@ -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