forked from TrueCloudLab/s3-tests
Add XML improvements.
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
This commit is contained in:
parent
672e0ad0e4
commit
4d8c6bdb69
1 changed files with 20 additions and 3 deletions
|
@ -5,8 +5,12 @@ import os
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
import yaml
|
import yaml
|
||||||
|
import re
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
|
from doctest import Example
|
||||||
|
from lxml.doctestcompare import LXMLOutputChecker
|
||||||
|
|
||||||
s3 = bunch.Bunch()
|
s3 = bunch.Bunch()
|
||||||
config = bunch.Bunch()
|
config = bunch.Bunch()
|
||||||
prefix = ''
|
prefix = ''
|
||||||
|
@ -267,4 +271,17 @@ def normalize_xml_whitespace(xml, pretty_print=True):
|
||||||
if element.tail is not None:
|
if element.tail is not None:
|
||||||
element.tail = element.tail.strip().replace("\n", "").replace("\r", "")
|
element.tail = element.tail.strip().replace("\n", "").replace("\r", "")
|
||||||
|
|
||||||
return etree.tostring(root, encoding="utf-8", xml_declaration=True, pretty_print=pretty_print)
|
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)
|
||||||
|
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)
|
||||||
|
return xmlstr
|
||||||
|
|
||||||
|
def assert_xml_equal(got, want):
|
||||||
|
checker = LXMLOutputChecker()
|
||||||
|
if not checker.check_output(want, got, 0):
|
||||||
|
message = checker.output_difference(Example("", want), got, 0)
|
||||||
|
raise AssertionError(message)
|
||||||
|
|
Loading…
Reference in a new issue