Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1a4ed4c

Browse files
Fix tests for issue #11159.
1 parent 5a9c1a7 commit 1a4ed4c

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

Lib/test/test_sax.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from xml.sax.handler import feature_namespaces
1515
from xml.sax.xmlreader import InputSource, AttributesImpl, AttributesNSImpl
1616
from io import StringIO
17+
import os.path
1718
import shutil
1819
from test import support
1920
from test.support import findfile, run_unittest
@@ -27,6 +28,18 @@
2728
except UnicodeEncodeError:
2829
raise unittest.SkipTest("filename is not encodable to utf8")
2930

31+
supports_nonascii_filenames = True
32+
if not os.path.supports_unicode_filenames:
33+
try:
34+
support.TESTFN_UNICODE.encode(support.TESTFN_ENCODING)
35+
except (UnicodeError, TypeError):
36+
# Either the file system encoding is None, or the file name
37+
# cannot be encoded in the file system encoding.
38+
supports_nonascii_filenames = False
39+
requires_nonascii_filenames = unittest.skipUnless(
40+
supports_nonascii_filenames,
41+
'Requires non-ascii filenames support')
42+
3043
ns_uri = "http://www.python.org/xml-ns/saxtest/"
3144

3245
class XmlTestBase(unittest.TestCase):
@@ -483,6 +496,7 @@ def test_expat_file(self):
483496

484497
self.assertEqual(result.getvalue(), xml_test_out)
485498

499+
@requires_nonascii_filenames
486500
def test_expat_file_nonascii(self):
487501
fname = support.TESTFN_UNICODE
488502
shutil.copyfile(TEST_XMLFILE, fname)
@@ -636,6 +650,7 @@ def test_expat_inpsource_sysid(self):
636650

637651
self.assertEqual(result.getvalue(), xml_test_out)
638652

653+
@requires_nonascii_filenames
639654
def test_expat_inpsource_sysid_nonascii(self):
640655
fname = support.TESTFN_UNICODE
641656
shutil.copyfile(TEST_XMLFILE, fname)
@@ -724,6 +739,7 @@ def test_expat_locator_withinfo(self):
724739
self.assertEqual(parser.getSystemId(), TEST_XMLFILE)
725740
self.assertEqual(parser.getPublicId(), None)
726741

742+
@requires_nonascii_filenames
727743
def test_expat_locator_withinfo_nonascii(self):
728744
fname = support.TESTFN_UNICODE
729745
shutil.copyfile(TEST_XMLFILE, fname)

0 commit comments

Comments
 (0)