Work on tests.

Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
This commit is contained in:
Robin H. Johnson 2015-06-22 17:17:18 +00:00 committed by Robin H. Johnson
parent 5d158567fd
commit 819eecba5c
2 changed files with 172 additions and 72 deletions

View file

@ -258,7 +258,7 @@ def with_setup_kwargs(setup, teardown=None):
# yield _test_gen
def normalize_xml_whitespace(xml, pretty_print=True):
def normalize_xml(xml, pretty_print=True):
root = etree.fromstring(xml.encode(encoding='ascii'))
for element in root.iter('*'):
@ -271,10 +271,14 @@ def normalize_xml_whitespace(xml, pretty_print=True):
if element.tail is not None:
element.tail = element.tail.strip().replace("\n", "").replace("\r", "")
# Sort the elements
for parent in root.xpath('//*[./*]'): # Search for parent elements
parent[:] = sorted(parent,key=lambda x: x.tag)
xmlstr = etree.tostring(root, encoding="utf-8", xml_declaration=True, pretty_print=pretty_print)
# there are two different DTD URIs
xmlstr = re.sub(r'xmlns="[^"]+"', 'xmlns="DTD-URI"', xmlstr)
xmlstr = re.sub(r'xmlns=\'[^\']+\'', 'xmlns="DTD-URI"', xmlstr)
xmlstr = re.sub(r'xmlns="[^"]+"', 'xmlns="s3"', xmlstr)
xmlstr = re.sub(r'xmlns=\'[^\']+\'', 'xmlns="s3"', xmlstr)
for uri in ['http://doc.s3.amazonaws.com/doc/2006-03-01/', 'http://s3.amazonaws.com/doc/2006-03-01/']:
xmlstr = xmlstr.replace(uri, 'URI-DTD')
#xmlstr = re.sub(r'>\s+', '>', xmlstr, count=0, flags=re.MULTILINE)