Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
erp5diff
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
erp5diff
Commits
79d944af
Commit
79d944af
authored
Aug 09, 2011
by
Nicolas Delaby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support of deletion/addition for tailed text nodes
parent
0f6d2730
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
15 deletions
+48
-15
CHANGES.txt
CHANGES.txt
+2
-0
src/ERP5Diff/ERP5Diff.py
src/ERP5Diff/ERP5Diff.py
+31
-14
src/tests/erp5diff_test_suite.py
src/tests/erp5diff_test_suite.py
+15
-1
No files found.
CHANGES.txt
View file @
79d944af
0.8.1.6 (unreleased)
--------------------
* Bug fix
* Add support of deletion/addition for tailed text nodes
0.8.1.5 (2011/08/08)
--------------------
...
...
src/ERP5Diff/ERP5Diff.py
View file @
79d944af
...
...
@@ -202,8 +202,7 @@ class ERP5Diff:
for
child
in
element
:
clone_node
=
deepcopy
(
child
)
update_element
.
append
(
clone_node
)
else
:
update_element
.
text
=
element
.
text
update_element
.
text
=
element
.
text
root
.
append
(
update_element
)
def
_xupdateUpdateTextNode
(
self
,
element
,
text
,
path
,
nsmap
=
None
):
...
...
@@ -215,6 +214,16 @@ class ERP5Diff:
update_element
.
text
=
text
root
.
append
(
update_element
)
def
_xupdateInsertAfterTextNode
(
self
,
element
,
path
,
nsmap
=
None
):
"""insert new tail text node
"""
root
=
self
.
_getResultRoot
()
insert_element
=
etree
.
Element
(
'{%s}insert-after'
%
self
.
_ns
,
nsmap
=
nsmap
)
insert_element
.
attrib
[
'select'
]
=
path
text_element
=
etree
.
SubElement
(
insert_element
,
'{%s}text'
%
self
.
_ns
,
nsmap
=
nsmap
)
text_element
.
text
=
element
.
tail
root
.
append
(
insert_element
)
def
_xupdateRemoveElement
(
self
,
path
,
nsmap
=
None
):
"""
Remove an element at 'path'.
...
...
@@ -607,20 +616,28 @@ class ERP5Diff:
self
.
_testAttributes
(
old_node
,
new_node
,
child_path
)
if
not
old_ignore_text
and
len
(
old_element
):
# Mixed Content
if
old_node
.
text
and
old_node
.
text
.
strip
()
and
new_node
.
text
\
and
new_node
.
text
.
strip
()
and
old_node
.
text
!=
new_node
.
text
:
text_path
=
child_path
+
'/text()[%i]'
%
(
new_node
.
getparent
().
index
(
new_node
))
if
((
old_node
.
text
and
old_node
.
text
.
strip
())
or
(
new_node
.
text
\
and
new_node
.
text
.
strip
()))
and
old_node
.
text
!=
new_node
.
text
\
and
(
self
.
_checkIgnoreText
(
new_node
)
==
self
.
_checkIgnoreText
(
old_node
)):
text_path
=
child_path
+
'/text()[1]'
self
.
_xupdateUpdateTextNode
(
new_node
,
new_node
.
text
,
text_path
,
nsmap
=
new_element
.
nsmap
)
if
old_node
.
tail
and
old_node
.
tail
.
strip
()
and
new_node
.
tail
\
and
new_node
.
tail
.
strip
()
and
old_node
.
tail
!=
new_node
.
tail
:
position
=
1
if
new_node
.
getparent
().
text
:
position
+=
1
position
+=
len
([
sibling
for
sibling
in
old_node
.
itersiblings
(
preceding
=
True
)
if
sibling
.
tail
])
text_path
=
path
+
'/text()[%i]'
%
(
position
)
self
.
_xupdateUpdateTextNode
(
new_node
,
new_node
.
tail
,
text_path
,
nsmap
=
new_element
.
nsmap
)
if
((
old_node
.
tail
and
old_node
.
tail
.
strip
())
or
(
new_node
.
tail
\
and
new_node
.
tail
.
strip
()))
and
old_node
.
tail
!=
new_node
.
tail
:
if
old_node
.
tail
:
# case 1: edit existing text node, usage of position should works to reach
# expected text node
position
=
1
position
+=
len
([
sibling
for
sibling
in
old_node
.
itersiblings
(
preceding
=
True
)
if
sibling
.
tail
])
if
old_node
.
getparent
().
text
:
position
+=
1
text_path
=
path
+
'/text()[%i]'
%
(
position
)
self
.
_xupdateUpdateTextNode
(
new_node
,
new_node
.
tail
,
text_path
,
nsmap
=
new_element
.
nsmap
)
else
:
# case 2: Means adding a new text node, the position is ambiguous,
# so use insert-after instead
self
.
_xupdateInsertAfterTextNode
(
new_node
,
child_path
,
nsmap
=
new_element
.
nsmap
)
self
.
_compareChildNodes
(
old_node
,
new_node
,
child_path
)
new_start
=
new_current
+
1
if
new_current
in
new_object_left_index_set
:
...
...
src/tests/erp5diff_test_suite.py
View file @
79d944af
...
...
@@ -1120,6 +1120,10 @@ class TestERP5Diff(unittest.TestCase):
<node>AAA<blank/>BBB</node>
<node>AAA<blank/>BBB</node>
<node>AAA<blank/>BBB<blank/>BBB</node>CCC
<a_node/>AAA
<b_node/>
<b_node/>
<node/>
</ul>
"""
new_xml
=
"""
...
...
@@ -1128,6 +1132,10 @@ class TestERP5Diff(unittest.TestCase):
<node>C<blank/>BBB</node>
<node>AAA<blank/>D</node>
<node>AAA<blank/>BBB<blank/>E</node>F
<a_node/>
<b_node/>
<b_node/>G
<node>BBB<blank/>H</node>
</ul>
"""
expected_result_string
=
"""<xupdate:modifications xmlns:xupdate="http://www.xmldb.org/xupdate" version="1.0">
...
...
@@ -1136,8 +1144,14 @@ class TestERP5Diff(unittest.TestCase):
<xupdate:update select="/ul/node[2]/text()[1]">C</xupdate:update>
<xupdate:update select="/ul/node[3]/text()[2]">D</xupdate:update>
<xupdate:update select="/ul/text()[2]">F
</xupdate:update>
</xupdate:update>
<xupdate:update select="/ul/node[4]/text()[3]">E</xupdate:update>
<xupdate:update select="/ul/text()[3]"/>
<xupdate:insert-after select="/ul/b_node[2]">
<xupdate:text>G
</xupdate:text>
</xupdate:insert-after>
<xupdate:update select="/ul/node[5]">BBB<blank/>H</xupdate:update>
</xupdate:modifications>
"""
self
.
_assertERP5DiffWorks
(
old_xml
,
new_xml
,
expected_result_string
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment