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 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 test_unicode_platform(self): matrix = { 'linux2': False, 'openbsd4': False, 'win32': True, 'darwin': True, } _reload() self.failUnlessReallyEqual(unicode_platform(), matrix[self.platform])
def test_open_unrepresentable(self): if unicode_platform(): raise unittest.SkipTest("This test is not applicable to platforms that represent filenames as Unicode.") enc = get_filesystem_encoding() fn = u'\u2621.txt' try: fn.encode(enc) raise unittest.SkipTest("This test cannot be run unless we know a filename that is not representable.") except UnicodeEncodeError: self.failUnlessRaises(UnicodeEncodeError, open, fn, 'wb')
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
def test_unicode_platform_py3(self): _reload() self.failUnlessReallyEqual(unicode_platform(), True)
def test_unicode_platform(self): matrix = {"linux2": False, "linux3": False, "openbsd4": False, "win32": True, "darwin": True} _reload() self.failUnlessReallyEqual(unicode_platform(), matrix[self.platform])