mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-29 17:28:53 +00:00
consolidate skip_if_cannot_represent_filename()
Remove duplicate copies of this utility, move it from a mixin/test-class method to being a simple function in common_util.py
This commit is contained in:
parent
d85d1ea499
commit
1877bd38b9
@ -1,10 +1,7 @@
|
||||
from cStringIO import StringIO
|
||||
from twisted.trial import unittest
|
||||
from twisted.internet import threads # CLI tests use deferToThread
|
||||
from ...util.assertutil import precondition
|
||||
from ...util.encodingutil import (unicode_platform,
|
||||
get_filesystem_encoding,
|
||||
unicode_to_argv)
|
||||
from ...util.encodingutil import unicode_to_argv
|
||||
from ...scripts import runner
|
||||
from ..common_util import ReallyEqualMixin
|
||||
|
||||
@ -36,13 +33,3 @@ class CLITestMixin(ReallyEqualMixin):
|
||||
return rc, stdout.getvalue(), stderr.getvalue()
|
||||
d.addCallback(_done)
|
||||
return d
|
||||
|
||||
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.")
|
||||
|
@ -29,7 +29,7 @@ from allmydata.scripts.common import DEFAULT_ALIAS, get_aliases, get_alias, \
|
||||
DefaultAliasMarker
|
||||
|
||||
from allmydata.scripts import cli, debug, runner
|
||||
from ..common_util import ReallyEqualMixin
|
||||
from ..common_util import ReallyEqualMixin, skip_if_cannot_represent_filename
|
||||
from ..no_network import GridTestMixin
|
||||
from .common import CLITestMixin, parse_options
|
||||
from twisted.internet import threads # CLI tests use deferToThread
|
||||
@ -493,7 +493,7 @@ class CLI(CLITestMixin, unittest.TestCase):
|
||||
filenames = [u'L\u00F4zane', u'Bern', u'Gen\u00E8ve'] # must be NFC
|
||||
|
||||
for name in filenames:
|
||||
self.skip_if_cannot_represent_filename(name)
|
||||
skip_if_cannot_represent_filename(name)
|
||||
|
||||
basedir = "cli/common/listdir_unicode_good"
|
||||
fileutil.make_dirs(basedir)
|
||||
|
@ -10,6 +10,7 @@ from allmydata.util.encodingutil import (quote_output, get_io_encoding,
|
||||
from allmydata.util.assertutil import _assert
|
||||
from ..no_network import GridTestMixin
|
||||
from .common import CLITestMixin
|
||||
from ..common_util import skip_if_cannot_represent_filename
|
||||
|
||||
timeout = 480 # deep_check takes 360s on Zandr's linksys box, others take > 240s
|
||||
|
||||
@ -30,7 +31,7 @@ class Cp(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
except UnicodeEncodeError:
|
||||
raise unittest.SkipTest("A non-ASCII command argument could not be encoded on this platform.")
|
||||
|
||||
self.skip_if_cannot_represent_filename(fn1)
|
||||
skip_if_cannot_represent_filename(fn1)
|
||||
|
||||
self.set_up_grid(oneshare=True)
|
||||
|
||||
@ -198,7 +199,7 @@ class Cp(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
except UnicodeEncodeError:
|
||||
raise unittest.SkipTest("A non-ASCII command argument could not be encoded on this platform.")
|
||||
|
||||
self.skip_if_cannot_represent_filename(fn1)
|
||||
skip_if_cannot_represent_filename(fn1)
|
||||
|
||||
self.set_up_grid(oneshare=True)
|
||||
|
||||
|
@ -6,6 +6,7 @@ from allmydata.util import fileutil
|
||||
from allmydata.scripts.common import get_aliases
|
||||
from allmydata.scripts import cli
|
||||
from ..no_network import GridTestMixin
|
||||
from ..common_util import skip_if_cannot_represent_filename
|
||||
from allmydata.util.encodingutil import get_io_encoding, unicode_to_argv
|
||||
from allmydata.util.fileutil import abspath_expanduser_unicode
|
||||
from .common import CLITestMixin
|
||||
@ -427,7 +428,7 @@ class Put(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
except UnicodeEncodeError:
|
||||
raise unittest.SkipTest("A non-ASCII command argument could not be encoded on this platform.")
|
||||
|
||||
self.skip_if_cannot_represent_filename(u"\u00E0 trier.txt")
|
||||
skip_if_cannot_represent_filename(u"\u00E0 trier.txt")
|
||||
|
||||
self.basedir = "cli/Put/immutable_from_file_unicode"
|
||||
self.set_up_grid(oneshare=True)
|
||||
|
@ -3,10 +3,21 @@ from random import randrange
|
||||
|
||||
from twisted.internet import reactor, defer
|
||||
from twisted.python import failure
|
||||
from twisted.trial import unittest
|
||||
|
||||
from allmydata.util import fileutil, log
|
||||
from ..util.assertutil import precondition
|
||||
from allmydata.util.encodingutil import unicode_platform, get_filesystem_encoding
|
||||
|
||||
def skip_if_cannot_represent_filename(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.")
|
||||
|
||||
class DevNullDictionary(dict):
|
||||
def __setitem__(self, key, value):
|
||||
|
@ -4,9 +4,9 @@ from StringIO import StringIO
|
||||
from twisted.trial import unittest
|
||||
|
||||
from allmydata.util import fileutil
|
||||
from allmydata.util.encodingutil import listdir_unicode, get_filesystem_encoding, unicode_platform
|
||||
from allmydata.util.assertutil import precondition
|
||||
from allmydata.util.encodingutil import listdir_unicode
|
||||
from allmydata.scripts import backupdb
|
||||
from .common_util import skip_if_cannot_represent_filename
|
||||
|
||||
class BackupDB(unittest.TestCase):
|
||||
def create(self, dbfile):
|
||||
@ -15,16 +15,6 @@ class BackupDB(unittest.TestCase):
|
||||
self.failUnless(bdb, "unable to create backupdb from %r" % (dbfile,))
|
||||
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)
|
||||
@ -222,8 +212,8 @@ 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")
|
||||
skip_if_cannot_represent_filename(u"f\u00f6\u00f6.txt")
|
||||
skip_if_cannot_represent_filename(u"b\u00e5r.txt")
|
||||
|
||||
self.basedir = basedir = os.path.join("backupdb", "unicode")
|
||||
fileutil.make_dirs(basedir)
|
||||
|
@ -71,7 +71,7 @@ from allmydata.util.encodingutil import argv_to_unicode, unicode_to_url, \
|
||||
get_io_encoding, get_filesystem_encoding, to_str, from_utf8_or_none, _reload, \
|
||||
to_filepath, extend_filepath, unicode_from_filepath, unicode_segments_from
|
||||
from allmydata.dirnode import normalize
|
||||
|
||||
from .common_util import skip_if_cannot_represent_filename
|
||||
from twisted.python import usage
|
||||
|
||||
|
||||
@ -265,16 +265,8 @@ class StdlibUnicode(unittest.TestCase):
|
||||
"""This mainly tests that some of the stdlib functions support Unicode paths, but also that
|
||||
listdir_unicode works for valid filenames."""
|
||||
|
||||
def skip_if_cannot_represent_filename(self, u):
|
||||
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_mkdir_open_exists_abspath_listdir_expanduser(self):
|
||||
self.skip_if_cannot_represent_filename(lumiere_nfc)
|
||||
skip_if_cannot_represent_filename(lumiere_nfc)
|
||||
|
||||
try:
|
||||
os.mkdir(lumiere_nfc)
|
||||
|
Loading…
Reference in New Issue
Block a user