Merge daira/2807.magic-folder-unicode-test-fail.1

refs ticket:2807

This allows tests to pass under an odd environment: our OS-X buildslave.
That process is started as a LaunchDaemon that doesn't provide any
Environment dictionary in the .plist file, so it runs with an empty
environment. On OS-X, this causes filesystem.encoding to default to
"utf-8", but locale.getpreferredencoding() returns "US-ASCII". The tests
previously assumed that any platform which used unicode for the
filesystem pathnames would also use it for sys.argv .

To simulate this without involving launchd, use "unset LANG", and
double-check that locale.getpreferredencoding() has changed.

This fix tolerates such platforms.
This commit is contained in:
Brian Warner 2016-09-27 10:26:03 -07:00
commit e8c246f346
2 changed files with 18 additions and 11 deletions

View File

@ -22,8 +22,8 @@ from allmydata import uri
class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin, NonASCIIPathMixin):
def setUp(self):
GridTestMixin.setUp(self)
self.alice_nickname = self.unicode_or_fallback(u"Alice\u00F8", u"Alice")
self.bob_nickname = self.unicode_or_fallback(u"Bob\u00F8", u"Bob")
self.alice_nickname = self.unicode_or_fallback(u"Alice\u00F8", u"Alice", io_as_well=True)
self.bob_nickname = self.unicode_or_fallback(u"Bob\u00F8", u"Bob", io_as_well=True)
def do_create_magic_folder(self, client_num):
d = self.do_cli("magic-folder", "create", "magic:", client_num=client_num)

View File

@ -8,7 +8,8 @@ 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
from allmydata.util.encodingutil import (unicode_platform, get_filesystem_encoding,
get_io_encoding)
from ..scripts import runner
def skip_if_cannot_represent_filename(u):
@ -95,14 +96,20 @@ class NonASCIIPathMixin:
self.addCleanup(_cleanup)
os.mkdir(dirpath)
def unicode_or_fallback(self, unicode_name, fallback_name):
if unicode_platform():
return unicode_name
try:
unicode_name.encode(get_filesystem_encoding())
return unicode_name
except UnicodeEncodeError:
return fallback_name
def unicode_or_fallback(self, unicode_name, fallback_name, io_as_well=False):
if not unicode_platform():
try:
unicode_name.encode(get_filesystem_encoding())
except UnicodeEncodeError:
return fallback_name
if io_as_well:
try:
unicode_name.encode(get_io_encoding())
except UnicodeEncodeError:
return fallback_name
return unicode_name
class SignalMixin: