Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(52)

Side by Side Diff: Lib/test/test_xml_etree.py

Issue 25047: xml.etree.ElementTree encoding declaration should be capital ('UTF-8') rather than lowercase ('utf-8')
Patch Set: Created 4 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Lib/xml/etree/ElementTree.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # IMPORTANT: the same tests are run from "test_xml_etree_c" in order 1 # IMPORTANT: the same tests are run from "test_xml_etree_c" in order
2 # to ensure consistency between the C implementation and the Python 2 # to ensure consistency between the C implementation and the Python
3 # implementation. 3 # implementation.
4 # 4 #
5 # For this purpose, the module-level "ET" symbol is temporarily 5 # For this purpose, the module-level "ET" symbol is temporarily
6 # monkey-patched when running the "test_xml_etree_c" test suite. 6 # monkey-patched when running the "test_xml_etree_c" test suite.
7 7
8 import html 8 import html
9 import io 9 import io
10 import operator 10 import operator
(...skipping 2378 matching lines...) Expand 10 before | Expand all | Expand 10 after
2389 2389
2390 class IOTest(unittest.TestCase): 2390 class IOTest(unittest.TestCase):
2391 def tearDown(self): 2391 def tearDown(self):
2392 support.unlink(TESTFN) 2392 support.unlink(TESTFN)
2393 2393
2394 def test_encoding(self): 2394 def test_encoding(self):
2395 # Test encoding issues. 2395 # Test encoding issues.
2396 elem = ET.Element("tag") 2396 elem = ET.Element("tag")
2397 elem.text = "abc" 2397 elem.text = "abc"
2398 self.assertEqual(serialize(elem), '<tag>abc</tag>') 2398 self.assertEqual(serialize(elem), '<tag>abc</tag>')
2399 self.assertEqual(serialize(elem, encoding="utf-8"), 2399 for enc in ("utf-8", "us-ascii"):
2400 b'<tag>abc</tag>') 2400 with self.subTest(enc):
2401 self.assertEqual(serialize(elem, encoding="us-ascii"), 2401 self.assertEqual(serialize(elem, encoding=enc),
2402 b'<tag>abc</tag>') 2402 b'<tag>abc</tag>')
2403 self.assertEqual(serialize(elem, encoding=enc.upper()),
2404 b'<tag>abc</tag>')
2403 for enc in ("iso-8859-1", "utf-16", "utf-32"): 2405 for enc in ("iso-8859-1", "utf-16", "utf-32"):
2404 self.assertEqual(serialize(elem, encoding=enc), 2406 with self.subTest(enc):
2405 ("<?xml version='1.0' encoding='%s'?>\n" 2407 self.assertEqual(serialize(elem, encoding=enc),
2406 "<tag>abc</tag>" % enc).encode(enc)) 2408 ("<?xml version='1.0' encoding='%s'?>\n"
2409 "<tag>abc</tag>" % enc).encode(enc))
2410 upper = enc.upper()
2411 self.assertEqual(serialize(elem, encoding=upper),
2412 ("<?xml version='1.0' encoding='%s'?>\n"
2413 "<tag>abc</tag>" % upper).encode(enc))
2407 2414
2408 elem = ET.Element("tag") 2415 elem = ET.Element("tag")
2409 elem.text = "<&\"\'>" 2416 elem.text = "<&\"\'>"
2410 self.assertEqual(serialize(elem), '<tag>&lt;&amp;"\'&gt;</tag>') 2417 self.assertEqual(serialize(elem), '<tag>&lt;&amp;"\'&gt;</tag>')
2411 self.assertEqual(serialize(elem, encoding="utf-8"), 2418 self.assertEqual(serialize(elem, encoding="utf-8"),
2412 b'<tag>&lt;&amp;"\'&gt;</tag>') 2419 b'<tag>&lt;&amp;"\'&gt;</tag>')
2413 self.assertEqual(serialize(elem, encoding="us-ascii"), 2420 self.assertEqual(serialize(elem, encoding="us-ascii"),
2414 b'<tag>&lt;&amp;"\'&gt;</tag>') 2421 b'<tag>&lt;&amp;"\'&gt;</tag>')
2415 for enc in ("iso-8859-1", "utf-16", "utf-32"): 2422 for enc in ("iso-8859-1", "utf-16", "utf-32"):
2416 self.assertEqual(serialize(elem, encoding=enc), 2423 self.assertEqual(serialize(elem, encoding=enc),
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
2744 # XXX the C module should give the same warnings as the Python module 2751 # XXX the C module should give the same warnings as the Python module
2745 with CleanContext(quiet=(pyET is not ET)): 2752 with CleanContext(quiet=(pyET is not ET)):
2746 support.run_unittest(*test_classes) 2753 support.run_unittest(*test_classes)
2747 finally: 2754 finally:
2748 # don't interfere with subsequent tests 2755 # don't interfere with subsequent tests
2749 ET = pyET = None 2756 ET = pyET = None
2750 2757
2751 2758
2752 if __name__ == '__main__': 2759 if __name__ == '__main__':
2753 test_main() 2760 test_main()
OLDNEW
« no previous file with comments | « no previous file | Lib/xml/etree/ElementTree.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+