]> git-server-git.apps.pok.os.sepia.ceph.com Git - s3-tests.git/commitdiff
Add XML improvements.
authorRobin H. Johnson <robbat2@gentoo.org>
Sun, 21 Jun 2015 05:04:51 +0000 (05:04 +0000)
committerRobin H. Johnson <robin.johnson@dreamhost.com>
Wed, 20 Apr 2016 23:08:57 +0000 (16:08 -0700)
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
s3tests/common.py

index 7b5cb479b53b224bd5dbd05facda1ae1f742ba56..55e669a5327951ae97267531f732e089b260ce8b 100644 (file)
@@ -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","")
-
-    return etree.tostring(root, encoding="utf-8", xml_declaration=True, pretty_print=pretty_print)
+            element.tail = element.tail.strip().replace("\n", "").replace("\r", "")
+
+    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)