[Checkins] SVN: z3c.etree/trunk/ - Implemented two new flags: XMLDATA_IGNOREMISSINGATTRIBUTES and
Sidnei da Silva
sidnei at enfoldsystems.com
Wed Mar 11 12:00:25 EDT 2009
Log message for revision 97842:
- Implemented two new flags: XMLDATA_IGNOREMISSINGATTRIBUTES and
XMLDATA_IGNOREEXTRAATTRIBUTES, to allow specifying only the
attributes that matter.
Changed:
U z3c.etree/trunk/CHANGES.txt
U z3c.etree/trunk/src/z3c/etree/doctests.txt
U z3c.etree/trunk/src/z3c/etree/doctestssuccess.txt
U z3c.etree/trunk/src/z3c/etree/testing.py
-=-
Modified: z3c.etree/trunk/CHANGES.txt
===================================================================
--- z3c.etree/trunk/CHANGES.txt 2009-03-11 15:33:53 UTC (rev 97841)
+++ z3c.etree/trunk/CHANGES.txt 2009-03-11 16:00:25 UTC (rev 97842)
@@ -2,6 +2,12 @@
Changes in z3c.etree
====================
+In the next release:
+
+- Implemented two new flags: XMLDATA_IGNOREMISSINGATTRIBUTES and
+ XMLDATA_IGNOREEXTRAATTRIBUTES, to allow specifying only the
+ attributes that matter.
+
0.9.2
=====
Modified: z3c.etree/trunk/src/z3c/etree/doctests.txt
===================================================================
--- z3c.etree/trunk/src/z3c/etree/doctests.txt 2009-03-11 15:33:53 UTC (rev 97841)
+++ z3c.etree/trunk/src/z3c/etree/doctests.txt 2009-03-11 16:00:25 UTC (rev 97842)
@@ -6,7 +6,7 @@
Test different number of elements on a sub element
--------------------------------------------------
-
+
>>> '<test><subtest>Content</subtest></test>'
'<test><subtest><subtest-2/></subtest></test>'
Modified: z3c.etree/trunk/src/z3c/etree/doctestssuccess.txt
===================================================================
--- z3c.etree/trunk/src/z3c/etree/doctestssuccess.txt 2009-03-11 15:33:53 UTC (rev 97841)
+++ z3c.etree/trunk/src/z3c/etree/doctestssuccess.txt 2009-03-11 16:00:25 UTC (rev 97842)
@@ -31,6 +31,24 @@
</D:response>
</D:multistatus>
+Different attribute ordering
+----------------------------
+
+ >>> '<test><subtest a="b" c="d">XXX</subtest></test>' #doctest:+XMLDATA
+ '<test><subtest c="d" a="b">XXX</subtest></test>'
+
+Extra attributes doesn't matter with XMLDATA_IGNOREEXTRAATTRIBUTES
+------------------------------------------------------------------
+
+ >>> '<test><subtest a="b" c="d">XXX</subtest></test>' #doctest:+XMLDATA,+XMLDATA_IGNOREEXTRAATTRIBUTES
+ '<test><subtest c="d">XXX</subtest></test>'
+
+Missing attributes doesn't matter with XMLDATA_IGNOREMISSINGATTRIBUTES
+----------------------------------------------------------------------
+
+ >>> '<test><subtest c="d">XXX</subtest></test>' #doctest:+XMLDATA,+XMLDATA_IGNOREMISSINGATTRIBUTES
+ '<test><subtest c="d" a="b">XXX</subtest></test>'
+
Ellipsis's
----------
@@ -40,3 +58,4 @@
<test>
<a>Content ...</a>
</test>
+
Modified: z3c.etree/trunk/src/z3c/etree/testing.py
===================================================================
--- z3c.etree/trunk/src/z3c/etree/testing.py 2009-03-11 15:33:53 UTC (rev 97841)
+++ z3c.etree/trunk/src/z3c/etree/testing.py 2009-03-11 16:00:25 UTC (rev 97842)
@@ -207,8 +207,9 @@
def _assertXMLElementEqual(want, got, optionflags):
- # See assertXMLEqual for tests - it is easier to the tests with strings that
- # get converted to element tree objects in assertXMLEqual.
+ # See assertXMLEqual for tests - it is easier to the tests with
+ # strings that get converted to element tree objects in
+ # assertXMLEqual.
etree = z3c.etree.getEngine()
if want.tag != got.tag:
@@ -222,18 +223,29 @@
if not result:
return result, msg
- if len(want.attrib) != len(got.attrib):
+ if (not (optionflags & XMLDATA_IGNOREMISSINGATTRIBUTES or
+ optionflags & XMLDATA_IGNOREEXTRAATTRIBUTES)
+ and len(want.attrib) != len(got.attrib)):
return False, "%d != %d different number of attributes on %r." %(
len(want.attrib), len(got.attrib), want.tag)
+
for attrib, attrib_value in want.attrib.items():
if attrib not in got.attrib:
- return False, "%r expected to find the %r attribute." %(
- want.tag, attrib)
- if got.attrib[attrib] != attrib_value:
- return \
- False, "%r attribute has different value for the %r tag." %(
- attrib, want.tag)
+ if not optionflags & XMLDATA_IGNOREMISSINGATTRIBUTES:
+ return False, "%r expected to find the %r attribute." %(
+ want.tag, attrib)
+ else:
+ if got.attrib[attrib] != attrib_value:
+ return False, (
+ "%r attribute has different value for the %r tag." % (
+ attrib, want.tag))
+ for attrib, attrib_value in got.attrib.items():
+ if attrib not in want.attrib:
+ if not optionflags & XMLDATA_IGNOREEXTRAATTRIBUTES:
+ return False, "%r found the unexpected %r attribute." %(
+ got.tag, attrib)
+
if optionflags & XMLDATA_IGNOREORDER:
return _assertSubXMLElementsUnordered(want, got, optionflags)
else:
@@ -552,7 +564,12 @@
XMLDATA_IGNOREORDER = doctest.register_optionflag("XMLDATA_IGNOREORDER")
+XMLDATA_IGNOREMISSINGATTRIBUTES = doctest.register_optionflag(
+ "XMLDATA_IGNOREMISSINGATTRIBUTES")
+XMLDATA_IGNOREEXTRAATTRIBUTES = doctest.register_optionflag(
+ "XMLDATA_IGNOREEXTRAATTRIBUTES")
+
class XMLOutputChecker(doctest.OutputChecker):
def check_output(self, want, got, optionflags):
More information about the Checkins
mailing list