|
14 | 14 | from xml.sax.handler import feature_namespaces |
15 | 15 | from xml.sax.xmlreader import InputSource, AttributesImpl, AttributesNSImpl |
16 | 16 | from io import StringIO |
| 17 | +import os.path |
17 | 18 | import shutil |
18 | 19 | from test import support |
19 | 20 | from test.support import findfile, run_unittest |
|
27 | 28 | except UnicodeEncodeError: |
28 | 29 | raise unittest.SkipTest("filename is not encodable to utf8") |
29 | 30 |
|
| 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 | + |
30 | 43 | ns_uri = "http://www.python.org/xml-ns/saxtest/" |
31 | 44 |
|
32 | 45 | class XmlTestBase(unittest.TestCase): |
@@ -483,6 +496,7 @@ def test_expat_file(self): |
483 | 496 |
|
484 | 497 | self.assertEqual(result.getvalue(), xml_test_out) |
485 | 498 |
|
| 499 | + @requires_nonascii_filenames |
486 | 500 | def test_expat_file_nonascii(self): |
487 | 501 | fname = support.TESTFN_UNICODE |
488 | 502 | shutil.copyfile(TEST_XMLFILE, fname) |
@@ -636,6 +650,7 @@ def test_expat_inpsource_sysid(self): |
636 | 650 |
|
637 | 651 | self.assertEqual(result.getvalue(), xml_test_out) |
638 | 652 |
|
| 653 | + @requires_nonascii_filenames |
639 | 654 | def test_expat_inpsource_sysid_nonascii(self): |
640 | 655 | fname = support.TESTFN_UNICODE |
641 | 656 | shutil.copyfile(TEST_XMLFILE, fname) |
@@ -724,6 +739,7 @@ def test_expat_locator_withinfo(self): |
724 | 739 | self.assertEqual(parser.getSystemId(), TEST_XMLFILE) |
725 | 740 | self.assertEqual(parser.getPublicId(), None) |
726 | 741 |
|
| 742 | + @requires_nonascii_filenames |
727 | 743 | def test_expat_locator_withinfo_nonascii(self): |
728 | 744 | fname = support.TESTFN_UNICODE |
729 | 745 | shutil.copyfile(TEST_XMLFILE, fname) |
|
0 commit comments