From 171621d06c307883c8d7530100a9939250539e14 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Sat, 17 Apr 2010 23:07:57 +0000 Subject: [PATCH] =?UTF-8?q?=09*=20morituri/test/Makefile.am:=20=09*=20mori?= =?UTF-8?q?turi/test/jose.toc=20(added):=20=09*=20morituri/test/Jos=C3=A9G?= =?UTF-8?q?onz=C3=A1lez.toc=20(deleted):=20=09=20=20Rename=20utf-8=20file?= =?UTF-8?q?=20to=20a=20normal=20file.=20=09*=20morituri/test/common.py:=20?= =?UTF-8?q?=09*=20morituri/test/test=5Fcommon=5Fchecksum.py:=20=09*=20mori?= =?UTF-8?q?turi/test/test=5Fcommon=5Fencode.py:=20=09*=20morituri/test/tes?= =?UTF-8?q?t=5Fimage=5Fimage.py:=20=09*=20morituri/test/test=5Fimage=5Ftoc?= =?UTF-8?q?.py:=20=09=20=20Copy=20the=20normal=20file=20first=20to=20the?= =?UTF-8?q?=20utf-8=20filename,=20if=20supported.=20=09=20=20Skip=20tests?= =?UTF-8?q?=20that=20need=20unicode=20when=20we=20are=20not=20in=20a=20utf?= =?UTF-8?q?-8=20locale.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ChangeLog | 14 +++++++++++ morituri/test/Makefile.am | 2 +- morituri/test/common.py | 15 ++++++++++- morituri/test/{JoséGonzález.toc => jose.toc} | 0 morituri/test/test_common_checksum.py | 2 ++ morituri/test/test_common_encode.py | 4 +-- morituri/test/test_image_image.py | 18 ++++++++------ morituri/test/test_image_toc.py | 26 ++++++++++++++------ 8 files changed, 61 insertions(+), 20 deletions(-) rename morituri/test/{JoséGonzález.toc => jose.toc} (100%) diff --git a/ChangeLog b/ChangeLog index d3fd2c9..795e863 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2010-04-18 Thomas Vander Stichele + + * morituri/test/Makefile.am: + * morituri/test/jose.toc (added): + * morituri/test/JoséGonzález.toc (deleted): + Rename utf-8 file to a normal file. + * morituri/test/common.py: + * morituri/test/test_common_checksum.py: + * morituri/test/test_common_encode.py: + * morituri/test/test_image_image.py: + * morituri/test/test_image_toc.py: + Copy the normal file first to the utf-8 filename, if supported. + Skip tests that need unicode when we are not in a utf-8 locale. + 2010-04-17 Thomas Vander Stichele * configure.ac: diff --git a/morituri/test/Makefile.am b/morituri/test/Makefile.am index 0c73b52..5d989f1 100644 --- a/morituri/test/Makefile.am +++ b/morituri/test/Makefile.am @@ -22,7 +22,7 @@ EXTRA_DIST = \ capital.2.toc \ cure.cue \ cure.toc \ - JoséGonzález.toc \ + jose.toc \ dBAR-011-0010e284-009228a3-9809ff0b.bin \ dBAR-020-002e5023-029d8e49-040eaa14.bin \ kanye.cue \ diff --git a/morituri/test/common.py b/morituri/test/common.py index 3d3c020..e28057f 100644 --- a/morituri/test/common.py +++ b/morituri/test/common.py @@ -1,8 +1,11 @@ # -*- Mode: Python -*- # vi:si:et:sw=4:sts=4:ts=4 +import os import sys -import unittest + +# twisted's unittests have skip support, standard unittest don't +from twisted.trial import unittest from morituri.common import log @@ -53,3 +56,13 @@ class TestCase(unittest.TestCase): % (exception.__name__, result)) assertRaises = failUnlessRaises + +class UnicodeTestMixin: + # A helper mixin to skip tests if we're not in a UTF-8 locale + try: + os.stat(u'morituri.test.B\xeate Noire.empty') + except UnicodeEncodeError: + skip = 'No UTF-8 locale' + except OSError: + pass + diff --git a/morituri/test/JoséGonzález.toc b/morituri/test/jose.toc similarity index 100% rename from morituri/test/JoséGonzález.toc rename to morituri/test/jose.toc diff --git a/morituri/test/test_common_checksum.py b/morituri/test/test_common_checksum.py index 8939c7a..d32b9d0 100644 --- a/morituri/test/test_common_checksum.py +++ b/morituri/test/test_common_checksum.py @@ -40,10 +40,12 @@ class PathTestCase(common.TestCase): self.failUnless(isinstance(e.exception, gst.QueryError)) os.unlink(path) +class UnicodePathTestCase(PathTestCase, common.UnicodeTestMixin): def testUnicodePath(self): # this test makes sure we can checksum a unicode path self._testSuffix(u'morituri.test.B\xeate Noire.empty') +class NormalPathTestCase(PathTestCase): def testSingleQuote(self): self._testSuffix(u"morituri.test.Guns 'N Roses") diff --git a/morituri/test/test_common_encode.py b/morituri/test/test_common_encode.py index 0549f5a..675b6bb 100644 --- a/morituri/test/test_common_encode.py +++ b/morituri/test/test_common_encode.py @@ -13,8 +13,6 @@ from morituri.test import common from morituri.common import task, encode, log -from morituri.test import common - class PathTestCase(common.TestCase): def _testSuffix(self, suffix): self.runner = task.SyncRunner(verbose=False) @@ -30,10 +28,12 @@ class PathTestCase(common.TestCase): os.unlink(path) os.unlink(path + '.out') +class UnicodePathTestCase(PathTestCase, common.UnicodeTestMixin): def testUnicodePath(self): # this test makes sure we can checksum a unicode path self._testSuffix(u'.morituri.test_encode.B\xeate Noire') +class NormalPathTestCase(PathTestCase): def testSingleQuote(self): self._testSuffix(u".morituri.test_encode.Guns 'N Roses") diff --git a/morituri/test/test_image_image.py b/morituri/test/test_image_image.py index f52ace0..392a660 100644 --- a/morituri/test/test_image_image.py +++ b/morituri/test/test_image_image.py @@ -3,7 +3,6 @@ import os import tempfile -import unittest import gobject gobject.threads_init() @@ -19,7 +18,7 @@ log.init() def h(i): return "0x%08x" % i -class TrackSingleTestCase(unittest.TestCase): +class TrackSingleTestCase(tcommon.TestCase): def setUp(self): self.image = image.Image(os.path.join(os.path.dirname(__file__), u'track-single.cue')) @@ -49,7 +48,7 @@ class TrackSingleTestCase(unittest.TestCase): self.assertEquals(self.image.table.getAccurateRipIds(), ( "00000016", "0000005b")) -class TrackSeparateTestCase(unittest.TestCase): +class TrackSeparateTestCase(tcommon.TestCase): def setUp(self): self.image = image.Image(os.path.join(os.path.dirname(__file__), u'track-separate.cue')) @@ -79,7 +78,7 @@ class TrackSeparateTestCase(unittest.TestCase): self.assertEquals(self.image.table.getAccurateRipIds(), ( "00000064", "00000191")) -class AudioLengthTestCase(unittest.TestCase): +class AudioLengthTestCase(tcommon.TestCase): def testLength(self): path = os.path.join(os.path.dirname(__file__), u'track.flac') t = image.AudioLengthTask(path) @@ -101,10 +100,7 @@ class AudioLengthPathTestCase(tcommon.TestCase): self.assertEquals(e.exception.code, gst.STREAM_ERROR_TYPE_NOT_FOUND) os.unlink(path) - def testUnicodePath(self): - # this test makes sure we can checksum a unicode path - self._testSuffix(u'morituri.test.B\xeate Noire.empty') - +class NormalAudioLengthPathTestCase(AudioLengthPathTestCase): def testSingleQuote(self): self._testSuffix(u"morituri.test.Guns 'N Roses") @@ -112,3 +108,9 @@ class AudioLengthPathTestCase(tcommon.TestCase): # This test makes sure we can checksum files with double quote in # their name self._testSuffix(u'morituri.test.12" edit') + +class UnicodeAudioLengthPathTestCase(AudioLengthPathTestCase, tcommon.UnicodeTestMixin): + def testUnicodePath(self): + # this test makes sure we can checksum a unicode path + self._testSuffix(u'morituri.test.B\xeate Noire.empty') + diff --git a/morituri/test/test_image_toc.py b/morituri/test/test_image_toc.py index cee03ba..461f9ce 100644 --- a/morituri/test/test_image_toc.py +++ b/morituri/test/test_image_toc.py @@ -3,13 +3,14 @@ import os import copy -import unittest +import shutil +import tempfile from morituri.image import toc from morituri.test import common -class CureTestCase(unittest.TestCase): +class CureTestCase(common.TestCase): def setUp(self): self.toc = toc.TocFile(os.path.join(os.path.dirname(__file__), u'cure.toc')) @@ -90,7 +91,7 @@ class CureTestCase(unittest.TestCase): '3/c/4/dBAR-013-0019d4c3-00fe8924-b90c650d.bin') # Bloc Party - Silent Alarm has a Hidden Track One Audio -class BlocTestCase(unittest.TestCase): +class BlocTestCase(common.TestCase): def setUp(self): self.toc = toc.TocFile(os.path.join(os.path.dirname(__file__), u'bloc.toc')) @@ -137,7 +138,7 @@ class BlocTestCase(unittest.TestCase): 'e/d/2/dBAR-013-001af2de-0105994e-ad0be00d.bin') # The Breeders - Mountain Battles has CDText -class BreedersTestCase(unittest.TestCase): +class BreedersTestCase(common.TestCase): def setUp(self): self.toc = toc.TocFile(os.path.join(os.path.dirname(__file__), u'breeders.toc')) @@ -163,7 +164,7 @@ class BreedersTestCase(unittest.TestCase): self.assertEquals(cue, ref) # Ladyhawke has a data track -class LadyhawkeTestCase(unittest.TestCase): +class LadyhawkeTestCase(common.TestCase): def setUp(self): self.toc = toc.TocFile(os.path.join(os.path.dirname(__file__), u'ladyhawke.toc')) @@ -179,7 +180,7 @@ class LadyhawkeTestCase(unittest.TestCase): # c60af50d 13 150 15687 31841 51016 66616 81352 99559 116070 133243 # 149997 161710 177832 207256 2807 -class CapitalMergeTestCase(unittest.TestCase): +class CapitalMergeTestCase(common.TestCase): def setUp(self): self.toc1 = toc.TocFile(os.path.join(os.path.dirname(__file__), u'capital.1.toc')) @@ -208,14 +209,23 @@ class CapitalMergeTestCase(unittest.TestCase): self.assertEquals(self.table.getMusicBrainzDiscId(), "MAj3xXf6QMy7G.BIFOyHyq4MySE-") -class UnicodeTestCase(unittest.TestCase): +class UnicodeTestCase(common.TestCase, common.UnicodeTestMixin): def setUp(self): + # we copy the normal non-utf8 filename to a utf-8 filename + # in this test because builds with LANG=C fail if we include + # utf-8 filenames in the dist path = u'Jos\xe9Gonz\xe1lez.toc' self._performer = u'Jos\xe9 Gonz\xe1lez' - self.toc = toc.TocFile(os.path.join(os.path.dirname(__file__), path)) + source = os.path.join(os.path.dirname(__file__), 'jose.toc') + self.dest = os.path.join(os.path.dirname(__file__), path) + shutil.copy(source, self.dest) + self.toc = toc.TocFile(self.dest) self.toc.parse() self.assertEquals(len(self.toc.table.tracks), 10) + def tearDown(self): + os.unlink(self.dest) + def testGetTrackLength(self): t = self.toc.table.tracks[0] # first track has known length because the .toc is a single file