Commit d5202396 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #11159: Add tests for testing SAX parser support of non-ascii file names.

parent 9cd864dc
...@@ -14,6 +14,8 @@ from xml.sax.expatreader import create_parser ...@@ -14,6 +14,8 @@ from xml.sax.expatreader import create_parser
from xml.sax.handler import feature_namespaces from xml.sax.handler import feature_namespaces
from xml.sax.xmlreader import InputSource, AttributesImpl, AttributesNSImpl from xml.sax.xmlreader import InputSource, AttributesImpl, AttributesNSImpl
from io import StringIO from io import StringIO
import shutil
from test import support
from test.support import findfile, run_unittest from test.support import findfile, run_unittest
import unittest import unittest
...@@ -481,6 +483,20 @@ class ExpatReaderTest(XmlTestBase): ...@@ -481,6 +483,20 @@ class ExpatReaderTest(XmlTestBase):
self.assertEqual(result.getvalue(), xml_test_out) self.assertEqual(result.getvalue(), xml_test_out)
def test_expat_file_nonascii(self):
fname = support.TESTFN_UNICODE
shutil.copyfile(TEST_XMLFILE, fname)
self.addCleanup(support.unlink, fname)
parser = create_parser()
result = StringIO()
xmlgen = XMLGenerator(result)
parser.setContentHandler(xmlgen)
parser.parse(open(fname))
self.assertEqual(result.getvalue(), xml_test_out)
# ===== DTDHandler support # ===== DTDHandler support
class TestDTDHandler: class TestDTDHandler:
...@@ -620,6 +636,20 @@ class ExpatReaderTest(XmlTestBase): ...@@ -620,6 +636,20 @@ class ExpatReaderTest(XmlTestBase):
self.assertEqual(result.getvalue(), xml_test_out) self.assertEqual(result.getvalue(), xml_test_out)
def test_expat_inpsource_sysid_nonascii(self):
fname = support.TESTFN_UNICODE
shutil.copyfile(TEST_XMLFILE, fname)
self.addCleanup(support.unlink, fname)
parser = create_parser()
result = StringIO()
xmlgen = XMLGenerator(result)
parser.setContentHandler(xmlgen)
parser.parse(InputSource(fname))
self.assertEqual(result.getvalue(), xml_test_out)
def test_expat_inpsource_stream(self): def test_expat_inpsource_stream(self):
parser = create_parser() parser = create_parser()
result = StringIO() result = StringIO()
...@@ -694,6 +724,20 @@ class ExpatReaderTest(XmlTestBase): ...@@ -694,6 +724,20 @@ class ExpatReaderTest(XmlTestBase):
self.assertEqual(parser.getSystemId(), TEST_XMLFILE) self.assertEqual(parser.getSystemId(), TEST_XMLFILE)
self.assertEqual(parser.getPublicId(), None) self.assertEqual(parser.getPublicId(), None)
def test_expat_locator_withinfo_nonascii(self):
fname = support.TESTFN_UNICODE
shutil.copyfile(TEST_XMLFILE, fname)
self.addCleanup(support.unlink, fname)
result = StringIO()
xmlgen = XMLGenerator(result)
parser = create_parser()
parser.setContentHandler(xmlgen)
parser.parse(fname)
self.assertEqual(parser.getSystemId(), fname)
self.assertEqual(parser.getPublicId(), None)
# =========================================================================== # ===========================================================================
# #
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment