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

Method test_xml_c14n2

Lib/test/test_xml_etree.py:4698–4796  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

4696 # output, not roundtripped C14N (see above).
4697
4698 def test_xml_c14n2(self):
4699 datadir = findfile("c14n-20", subdir="xmltestdata")
4700 full_path = partial(os.path.join, datadir)
4701
4702 files = [filename[:-4] for filename in sorted(os.listdir(datadir))
4703 if filename.endswith('.xml')]
4704 input_files = [
4705 filename for filename in files
4706 if filename.startswith('in')
4707 ]
4708 configs = {
4709 filename: {
4710 # <c14n2:PrefixRewrite>sequential</c14n2:PrefixRewrite>
4711 option.tag.split('}')[-1]: ((option.text or '').strip(), option)
4712 for option in ET.parse(full_path(filename) + ".xml").getroot()
4713 }
4714 for filename in files
4715 if filename.startswith('c14n')
4716 }
4717
4718 tests = {
4719 input_file: [
4720 (filename, configs[filename.rsplit('_', 1)[-1]])
4721 for filename in files
4722 if filename.startswith(f'out_{input_file}_')
4723 and filename.rsplit('_', 1)[-1] in configs
4724 ]
4725 for input_file in input_files
4726 }
4727
4728 # Make sure we found all test cases.
4729 self.assertEqual(30, len([
4730 output_file for output_files in tests.values()
4731 for output_file in output_files]))
4732
4733 def get_option(config, option_name, default=None):
4734 return config.get(option_name, (default, ()))[0]
4735
4736 for input_file, output_files in tests.items():
4737 for output_file, config in output_files:
4738 keep_comments = get_option(
4739 config, 'IgnoreComments') == 'true' # no, it's right :)
4740 strip_text = get_option(
4741 config, 'TrimTextNodes') == 'true'
4742 rewrite_prefixes = get_option(
4743 config, 'PrefixRewrite') == 'sequential'
4744 if 'QNameAware' in config:
4745 qattrs = [
4746 f"{{{el.get('NS')}}}{el.get('Name')}"
4747 for el in config['QNameAware'][1].findall(
4748 '{http://www.w3.org/2010/xml-c14n2}QualifiedAttr')
4749 ]
4750 qtags = [
4751 f"{{{el.get('NS')}}}{el.get('Name')}"
4752 for el in config['QNameAware'][1].findall(
4753 '{http://www.w3.org/2010/xml-c14n2}Element')
4754 ]
4755 else:

Callers

nothing calls this directly

Calls 15

readMethod · 0.95
findfileFunction · 0.90
partialClass · 0.90
listdirMethod · 0.80
getrootMethod · 0.80
skipTestMethod · 0.80
openFunction · 0.50
endswithMethod · 0.45
startswithMethod · 0.45
splitMethod · 0.45
stripMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected