mirror of
https://github.com/ceph/s3-tests.git
synced 2024-12-25 13:56:37 +00:00
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 string
|
||||
import yaml
|
||||
import re
|
||||
from lxml import etree
|
||||
|
||||
from doctest import Example
|
||||
from lxml.doctestcompare import LXMLOutputChecker
|
||||
|
||||
s3 = bunch.Bunch()
|
||||
config = bunch.Bunch()
|
||||
prefix = ''
|
||||
|
@ -261,10 +265,23 @@ def normalize_xml_whitespace(xml, pretty_print=True):
|
|||
if element.text is not None and not element.text.strip():
|
||||
element.text = None
|
||||
if element.text is not None:
|
||||
element.text = element.text.strip().replace("\n","").replace("\r","")
|
||||
element.text = element.text.strip().replace("\n", "").replace("\r", "")
|
||||
if element.tail is not None and not element.tail.strip():
|
||||
element.tail = 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