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):
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)
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)
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")