summaryrefslogtreecommitdiffstats
path: root/testsuite/common.py
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2013-08-29 11:12:38 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2013-08-29 11:12:38 -0400
commit6d2304bb814a31f7e489ef6c6caca2d3a748ed0e (patch)
treeff7abb2f9f3407a7c221ae281916cfc6d8aab735 /testsuite/common.py
parent12d351a0213cdc39631acb143d9c2c8bf90e1d72 (diff)
downloadbcfg2-6d2304bb814a31f7e489ef6c6caca2d3a748ed0e.tar.gz
bcfg2-6d2304bb814a31f7e489ef6c6caca2d3a748ed0e.tar.bz2
bcfg2-6d2304bb814a31f7e489ef6c6caca2d3a748ed0e.zip
testsuite: rewrote Rules/Defaults tests to be actually useful
Diffstat (limited to 'testsuite/common.py')
-rw-r--r--testsuite/common.py42
1 files changed, 25 insertions, 17 deletions
diff --git a/testsuite/common.py b/testsuite/common.py
index b375d3703..9f46e01cc 100644
--- a/testsuite/common.py
+++ b/testsuite/common.py
@@ -282,31 +282,39 @@ class Bcfg2TestCase(unittest.TestCase):
"%s is not less than or equal to %s")
def assertXMLEqual(self, el1, el2, msg=None):
- """ Test that the two XML trees given are equal. Both
- elements and all children are expected to have ``name``
- attributes. """
+ """ Test that the two XML trees given are equal. """
if msg is None:
- msg = "XML trees were not equal"
+ msg = "XML trees are not equal: %s"
+ else:
+ msg += ": %s"
fullmsg = msg + "\nFirst: %s" % lxml.etree.tostring(el1) + \
"\nSecond: %s" % lxml.etree.tostring(el2)
- self.assertEqual(el1.tag, el2.tag, msg=fullmsg)
- self.assertEqual(el1.text, el2.text, msg=fullmsg)
+ self.assertEqual(el1.tag, el2.tag, msg=fullmsg % "Tags differ")
+ self.assertEqual(el1.text, el2.text,
+ msg=fullmsg % "Text content differs")
self.assertItemsEqual(el1.attrib.items(), el2.attrib.items(),
- msg=fullmsg)
+ msg=fullmsg % "Attributes differ")
self.assertEqual(len(el1.getchildren()),
len(el2.getchildren()),
- msg=fullmsg)
+ msg=fullmsg % "Different numbers of children")
+ matched = []
for child1 in el1.getchildren():
- cname = child1.get("name")
- self.assertIsNotNone(cname,
- msg="Element %s has no 'name' attribute" %
- child1.tag)
- children2 = el2.xpath("%s[@name='%s']" % (child1.tag, cname))
- self.assertEqual(len(children2), 1,
- msg="More than one %s element named %s" % \
- (child1.tag, cname))
- self.assertXMLEqual(child1, children2[0], msg=msg)
+ for child2 in el2.xpath(child1.tag):
+ if child2 in matched:
+ continue
+ try:
+ self.assertXMLEqual(child1, child2)
+ matched.append(child2)
+ break
+ except AssertionError:
+ continue
+ else:
+ assert False, \
+ fullmsg % ("Element %s is missing from second" %
+ lxml.etree.tostring(child1))
+ self.assertItemsEqual(el2.getchildren(), matched,
+ msg=fullmsg % "Second has extra element(s)")
class DBModelTestCase(Bcfg2TestCase):