MCPcopy Index your code
hub / github.com/python/cpython / test_5027_2

Method test_5027_2

Lib/test/test_sax.py:737–763  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

735 '</a:g1>'))
736
737 def test_5027_2(self):
738 # The xml prefix (as in xml:lang below) is reserved and bound by
739 # definition to http://www.w3.org/XML/1998/namespace. XMLGenerator had
740 # a bug whereby a KeyError is raised because this namespace is missing
741 # from a dictionary.
742 #
743 # This test demonstrates the bug by direct manipulation of the
744 # XMLGenerator.
745 result = self.ioclass()
746 gen = XMLGenerator(result)
747
748 gen.startDocument()
749 gen.startPrefixMapping('a', 'http://example.com/ns')
750 gen.startElementNS(('http://example.com/ns', 'g1'), 'g1', {})
751 lang_attr = {('http://www.w3.org/XML/1998/namespace', 'lang'): 'en'}
752 gen.startElementNS(('http://example.com/ns', 'g2'), 'g2', lang_attr)
753 gen.characters('Hello')
754 gen.endElementNS(('http://example.com/ns', 'g2'), 'g2')
755 gen.endElementNS(('http://example.com/ns', 'g1'), 'g1')
756 gen.endPrefixMapping('a')
757 gen.endDocument()
758
759 self.assertEqual(result.getvalue(),
760 self.xml(
761 '<a:g1 xmlns:a="http://example.com/ns">'
762 '<a:g2 xml:lang="en">Hello</a:g2>'
763 '</a:g1>'))
764
765 def test_no_close_file(self):
766 result = self.ioclass()

Callers

nothing calls this directly

Calls 12

startDocumentMethod · 0.95
startPrefixMappingMethod · 0.95
startElementNSMethod · 0.95
charactersMethod · 0.95
endElementNSMethod · 0.95
endPrefixMappingMethod · 0.95
endDocumentMethod · 0.95
XMLGeneratorClass · 0.90
ioclassMethod · 0.45
assertEqualMethod · 0.45
getvalueMethod · 0.45
xmlMethod · 0.45

Tested by

no test coverage detected