AudioLengthTest: adapt to new soxi backend
* Use extensions soxi understands (ie. ".flac") * Actually test for result correctness on files with odd characters in their names by copying the test track * Relax the requirements on the "track absent" task to only raise some TaskError (the previously tested behavior was backend dependent, and the application did not actually depend on that behavior)
This commit is contained in:
@@ -8,41 +8,41 @@ from morituri.extern.task import task
|
||||
from morituri.program.soxi import AudioLengthTask
|
||||
from morituri.test import common as tcommon
|
||||
|
||||
base_track_file = os.path.join(os.path.dirname(__file__), u'track.flac')
|
||||
base_track_length = 10 * common.SAMPLES_PER_FRAME
|
||||
|
||||
class AudioLengthTestCase(tcommon.TestCase):
|
||||
|
||||
def testLength(self):
|
||||
path = os.path.join(os.path.dirname(__file__), u'track.flac')
|
||||
path = base_track_file
|
||||
t = AudioLengthTask(path)
|
||||
runner = task.SyncRunner()
|
||||
runner.run(t, verbose=False)
|
||||
self.assertEquals(t.length, 10 * common.SAMPLES_PER_FRAME)
|
||||
self.assertEquals(t.length, base_track_length)
|
||||
|
||||
|
||||
class AudioLengthPathTestCase(tcommon.TestCase):
|
||||
|
||||
def _testSuffix(self, suffix):
|
||||
self.runner = task.SyncRunner(verbose=False)
|
||||
fd, path = tempfile.mkstemp(suffix=suffix)
|
||||
with os.fdopen(fd, "wb") as temptrack:
|
||||
temptrack.write(open(base_track_file, "rb").read())
|
||||
|
||||
t = AudioLengthTask(path)
|
||||
e = self.assertRaises(task.TaskException, self.runner.run,
|
||||
t, verbose=False)
|
||||
self.failUnless(isinstance(e.exception, gstreamer.GstException),
|
||||
"%r is not a gstreamer.GstException" % e.exceptionMessage)
|
||||
self.assertEquals(e.exception.gerror.domain, gst.STREAM_ERROR)
|
||||
# our empty file triggers TYPE_NOT_FOUND
|
||||
self.assertEquals(e.exception.gerror.code,
|
||||
gst.STREAM_ERROR_TYPE_NOT_FOUND)
|
||||
runner = task.SyncRunner()
|
||||
runner.run(t, verbose=False)
|
||||
self.assertEquals(t.length, base_track_length)
|
||||
os.unlink(path)
|
||||
|
||||
class NormalAudioLengthPathTestCase(AudioLengthPathTestCase):
|
||||
|
||||
def testSingleQuote(self):
|
||||
self._testSuffix(u"morituri.test.Guns 'N Roses")
|
||||
self._testSuffix(u"morituri.test.Guns 'N Roses.flac")
|
||||
|
||||
def testDoubleQuote(self):
|
||||
# This test makes sure we can checksum files with double quote in
|
||||
# their name
|
||||
self._testSuffix(u'morituri.test.12" edit')
|
||||
self._testSuffix(u'morituri.test.12" edit.flac')
|
||||
|
||||
|
||||
class UnicodeAudioLengthPathTestCase(AudioLengthPathTestCase,
|
||||
@@ -50,4 +50,16 @@ class UnicodeAudioLengthPathTestCase(AudioLengthPathTestCase,
|
||||
|
||||
def testUnicodePath(self):
|
||||
# this test makes sure we can checksum a unicode path
|
||||
self._testSuffix(u'morituri.test.B\xeate Noire.empty')
|
||||
self._testSuffix(u'morituri.test.B\xeate Noire.empty.flac')
|
||||
|
||||
class AbsentFileAudioLengthPathTestCase(AudioLengthPathTestCase):
|
||||
def testAbsentFile(self):
|
||||
tempdir = tempfile.mkdtemp()
|
||||
path = os.path.join(tempdir, u"nonexistent.flac")
|
||||
|
||||
t = AudioLengthTask(path)
|
||||
runner = task.SyncRunner()
|
||||
self.assertRaises(task.TaskException, runner.run,
|
||||
t, verbose=False)
|
||||
|
||||
os.rmdir(tempdir)
|
||||
|
||||
Reference in New Issue
Block a user