mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Fix the minidom test.
In order to do this, I added an optional encoding argument to io.StringIO. The toprettyxml() function returns bytes when you specify an encoding now.
This commit is contained in:
parent
3992db81b6
commit
3e1f85eb5d
3 changed files with 21 additions and 24 deletions
|
@ -869,17 +869,17 @@ class MinidomTest(unittest.TestCase):
|
|||
|
||||
def testEncodings(self):
|
||||
doc = parseString('<foo>€</foo>')
|
||||
self.confirm(doc.toxml() == '<?xml version="1.0" ?><foo>\u20ac</foo>'
|
||||
and doc.toxml('utf-8') ==
|
||||
'<?xml version="1.0" encoding="utf-8"?><foo>\xe2\x82\xac</foo>'
|
||||
and doc.toxml('iso-8859-15') ==
|
||||
'<?xml version="1.0" encoding="iso-8859-15"?><foo>\xa4</foo>',
|
||||
"testEncodings - encoding EURO SIGN")
|
||||
self.assertEqual(doc.toxml(),
|
||||
'<?xml version="1.0" ?><foo>\u20ac</foo>')
|
||||
self.assertEqual(doc.toxml('utf-8'),
|
||||
b'<?xml version="1.0" encoding="utf-8"?><foo>\xe2\x82\xac</foo>')
|
||||
self.assertEqual(doc.toxml('iso-8859-15'),
|
||||
b'<?xml version="1.0" encoding="iso-8859-15"?><foo>\xa4</foo>')
|
||||
|
||||
# Verify that character decoding errors throw exceptions instead
|
||||
# of crashing
|
||||
self.assertRaises(UnicodeDecodeError, parseString,
|
||||
'<fran\xe7ais>Comment \xe7a va ? Tr\xe8s bien ?</fran\xe7ais>')
|
||||
b'<fran\xe7ais>Comment \xe7a va ? Tr\xe8s bien ?</fran\xe7ais>')
|
||||
|
||||
doc.unlink()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue