Author: hwright
Date: Tue Jul 27 19:16:19 2010
New Revision: 979814
URL: http://svn.apache.org/viewvc?rev=979814&view=rev
Log:
Add an element comparator for help in running Mouse tests.
* tests/test_mouse.py
(attributes_are_same, elements_are_same): New.
(TestReport.test_greek_vanilla_xml): Use the new method.
Modified:
labs/mouse/tests/test_mouse.py
Modified: labs/mouse/tests/test_mouse.py
URL:
http://svn.apache.org/viewvc/labs/mouse/tests/test_mouse.py?rev=979814&r1=979813&r2=979814&view=diff
==============================================================================
--- labs/mouse/tests/test_mouse.py (original)
+++ labs/mouse/tests/test_mouse.py Tue Jul 27 19:16:19 2010
@@ -36,6 +36,50 @@ data_path = os.path.join(sys.path[0], 'd
resources_path = os.path.join(os.path.dirname(sys.path[0]), 'resources')
+def attributes_are_same(elem1, elem2):
+ '''Return True if both elements share the same attribute dicts and values.'''
+ attrib1 = elem1.attrib
+ attrib2 = elem2.attrib
+
+ if len(attrib1) != len(attrib2):
+ return False
+
+ for key in attrib1.keys():
+ if not attrib2.has_key(key):
+ return False
+ if attrib1[key] != attrib2[key]:
+ return False
+
+ return True
+
+
+def elements_are_same(elem1, elem2):
+ '''Return True if these elements are the same, disreguarding unimportant
+ ordering concerns. (What those are is left as an exercise for the
+ reader.)'''
+
+ # Check the attributes are the same
+ if not attributes_are_same(elem1, elem2):
+ return False
+
+ # Check the content of these elements
+ if elem1.text != elem2.text:
+ return False
+
+ # Finally recursively check the children
+ children1 = elem1.getchildren()
+ children2 = elem2.getchildren()
+
+ if len(children1) != len(children2):
+ return False
+
+ for child1, child2 in zip(children1, children2):
+ if not elements_are_same(child1,child2):
+ return False
+
+ return True
+
+
def _count_items(items):
'Return the number of items generated by ITEMS'
i = 0
@@ -55,7 +99,7 @@ class TestReport(unittest.TestCase):
target_xml = open(os.path.join(data_path, 'expected_output',
'greek_vanilla.xml')).read()
target_element = ElementTree.XML(target_xml)
- self.assertEqual(output_element, target_element)
+ self.assertTrue(elements_are_same(output_element, target_element))
def test_greek_vanilla(self):
items = mouse.get_items(os.path.join(data_path, 'greek'))
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]