From 6b2f99fa9a1f9552ca15767416136dddb512e573 Mon Sep 17 00:00:00 2001 From: david-sarah Date: Fri, 18 Jun 2010 19:26:20 -0700 Subject: [PATCH] test_backupdb.py: skip test_unicode if we can't represent the test filenames. --- src/allmydata/test/test_backupdb.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/allmydata/test/test_backupdb.py b/src/allmydata/test/test_backupdb.py index bf57b9f4..13c86792 100644 --- a/src/allmydata/test/test_backupdb.py +++ b/src/allmydata/test/test_backupdb.py @@ -4,7 +4,8 @@ from StringIO import StringIO from twisted.trial import unittest from allmydata.util import fileutil -from allmydata.util.stringutils import listdir_unicode +from allmydata.util.stringutils import listdir_unicode, get_filesystem_encoding, unicode_platform +from allmydata.util.assertutil import precondition from allmydata.scripts import backupdb class BackupDB(unittest.TestCase): @@ -16,6 +17,16 @@ class BackupDB(unittest.TestCase): raise unittest.SkipTest("sqlite unavailable, skipping test") return bdb + def skip_if_cannot_represent_filename(self, u): + precondition(isinstance(u, unicode)) + + enc = get_filesystem_encoding() + if not unicode_platform(): + try: + u.encode(enc) + except UnicodeEncodeError: + raise unittest.SkipTest("A non-ASCII filename could not be encoded on this platform.") + def test_basic(self): self.basedir = basedir = os.path.join("backupdb", "create") fileutil.make_dirs(basedir) @@ -77,7 +88,7 @@ class BackupDB(unittest.TestCase): def writeto(self, filename, data): - fn = os.path.join(self.basedir, filename) + fn = os.path.join(self.basedir, unicode(filename)) parentdir = os.path.dirname(fn) fileutil.make_dirs(parentdir) fileutil.write(fn, data) @@ -228,6 +239,9 @@ class BackupDB(unittest.TestCase): self.failIf(r.was_created()) def test_unicode(self): + self.skip_if_cannot_represent_filename(u"f\u00f6\u00f6.txt") + self.skip_if_cannot_represent_filename(u"b\u00e5r.txt") + self.basedir = basedir = os.path.join("backupdb", "unicode") fileutil.make_dirs(basedir) dbfile = os.path.join(basedir, "dbfile") -- 2.45.2