Commit 6d753a49 authored by Nicolas Delaby's avatar Nicolas Delaby

* In node comparaison discard text nodes with only withe-spaces.

* Add tests
parent c9ecea0b
......@@ -394,11 +394,19 @@ class ERP5Diff:
"""
Determine if text should be ignored by heuristics,
because ERP5 does not define any schema at the moment.
We ignore white-space text nodes between elements.
pseudo code:
tree = parse("
<node>
</node>")
tree.node.text == '\n '
"""
for child in element:
if type(child) == etree._Element:
return True
return False
if element.text is None:
return True
return bool(element.text.strip()) is False or False
def _makeRelativePathList(self, element_list, before=0):
"""
......@@ -555,10 +563,6 @@ class ERP5Diff:
# Nothing to do.
self._p("Both are empty.")
pass
elif old_is_empty or new_is_empty:
# Perhaps they are very different.
self._p("One of them is empty, so just update all the contents.")
self._xupdateUpdateElement(new_element, path, nsmap=new_element.nsmap)
else:
# Second, determine if text should be ignored.
old_ignore_text = self._checkIgnoreText(old_element)
......
......@@ -941,5 +941,64 @@ does not work as bellow example. This is a known bug.
</xupdate:insert-after>
</xupdate:modifications>
29. Delete children with white-space as text nodes
>>> old_xml = """
... <object>
... <local_permission type="tokens" id="View">
... <marshal:marshal xmlns:marshal="http://www.erp5.org/namespaces/marshaller">
... <marshal:tuple>
... <marshal:string>Assignee</marshal:string>
... <marshal:string>Assignor</marshal:string>
... </marshal:tuple>
... </marshal:marshal>
... </local_permission>
... </object>
... """
>>> new_xml = """
... <object>
... <local_permission type="tokens" id="View">
... <marshal:marshal xmlns:marshal="http://www.erp5.org/namespaces/marshaller">
... <marshal:tuple>
... </marshal:tuple>
... </marshal:marshal>
... </local_permission>
... </object>
... """
>>> erp5diff.compare(old_xml, new_xml)
>>> erp5diff.output()
<xupdate:modifications xmlns:xupdate="http://www.xmldb.org/xupdate" version="1.0">
<xupdate:remove xmlns:marshal="http://www.erp5.org/namespaces/marshaller" select="/object/local_permission[@id='View']/marshal:marshal/marshal:tuple/marshal:string[1]"/>
<xupdate:remove xmlns:marshal="http://www.erp5.org/namespaces/marshaller" select="/object/local_permission[@id='View']/marshal:marshal/marshal:tuple/marshal:string[2]"/>
</xupdate:modifications>
29Bis. Delete childrens with auto-closing nodes
>>> old_xml = """
... <object>
... <local_permission type="tokens" id="View">
... <marshal:marshal xmlns:marshal="http://www.erp5.org/namespaces/marshaller">
... <marshal:tuple>
... <marshal:string>Assignee</marshal:string>
... <marshal:string>Assignor</marshal:string>
... </marshal:tuple>
... </marshal:marshal>
... </local_permission>
... </object>
... """
>>> new_xml = """
... <object>
... <local_permission type="tokens" id="View">
... <marshal:marshal xmlns:marshal="http://www.erp5.org/namespaces/marshaller">
... <marshal:tuple/>
... </marshal:marshal>
... </local_permission>
... </object>
... """
>>> erp5diff.compare(old_xml, new_xml)
>>> erp5diff.output()
<xupdate:modifications xmlns:xupdate="http://www.xmldb.org/xupdate" version="1.0">
<xupdate:remove xmlns:marshal="http://www.erp5.org/namespaces/marshaller" select="/object/local_permission[@id='View']/marshal:marshal/marshal:tuple/marshal:string[1]"/>
<xupdate:remove xmlns:marshal="http://www.erp5.org/namespaces/marshaller" select="/object/local_permission[@id='View']/marshal:marshal/marshal:tuple/marshal:string[2]"/>
</xupdate:modifications>
- 2003-12-04, Yoshinori OKUJI <yo@nexedi.com>
- 2009-09-15, Tatuya Kamada <tatuya@nexedi.com>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment