From d52023968afd0124b0812a4c8d5b194b19c6e979 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 2 Feb 2013 10:31:17 +0200 Subject: =?UTF-8?q?Issue=20#11159:=20Add=20tests=20for=20testing=20SAX?= =?UTF-8?q?=C2=A0parser=20support=20of=20non-ascii=20file=20names.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lib/test/test_sax.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py index d6ed6db..7b989e8 100644 --- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -14,6 +14,8 @@ from xml.sax.expatreader import create_parser from xml.sax.handler import feature_namespaces from xml.sax.xmlreader import InputSource, AttributesImpl, AttributesNSImpl from io import StringIO +import shutil +from test import support from test.support import findfile, run_unittest import unittest @@ -481,6 +483,20 @@ class ExpatReaderTest(XmlTestBase): 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 class TestDTDHandler: @@ -620,6 +636,20 @@ class ExpatReaderTest(XmlTestBase): 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): parser = create_parser() result = StringIO() @@ -694,6 +724,20 @@ class ExpatReaderTest(XmlTestBase): self.assertEqual(parser.getSystemId(), TEST_XMLFILE) 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) + # =========================================================================== # -- cgit v0.12