3 new revisions:

Revision: 0c663f78b205
Branch:   default
Author:   Pekka Klärck
Date:     Tue Sep 18 13:07:11 2012
Log:      dos2unix
http://code.google.com/p/robotframework/source/detail?r=0c663f78b205

Revision: 2ee224848f92
Branch:   default
Author:   Pekka Klärck
Date:     Tue Sep 18 13:27:05 2012
Log:      XML lib: Copy Element keyword...
http://code.google.com/p/robotframework/source/detail?r=2ee224848f92

Revision: 9dbc14361aab
Branch:   default
Author:   Pekka Klärck
Date:     Tue Sep 18 13:59:04 2012
Log:      XML lib: Clear Element keyword...
http://code.google.com/p/robotframework/source/detail?r=9dbc14361aab

==============================================================================
Revision: 0c663f78b205
Branch:   default
Author:   Pekka Klärck
Date:     Tue Sep 18 13:07:11 2012
Log:      dos2unix
http://code.google.com/p/robotframework/source/detail?r=0c663f78b205

Modified:
 /atest/testdata/standard_libraries/xml/add_and_remove_elements.txt
 /atest/testdata/standard_libraries/xml/element_should_exist.txt


==============================================================================
Revision: 2ee224848f92
Branch:   default
Author:   Pekka Klärck
Date:     Tue Sep 18 13:27:05 2012
Log:      XML lib: Copy Element keyword

Update issue 1234
Added `Copy Element` keyword to make it possible to copy certain element and modify it without affecting the original.
http://code.google.com/p/robotframework/source/detail?r=2ee224848f92

Added:
 /atest/robot/standard_libraries/xml/copy_element.txt
 /atest/testdata/standard_libraries/xml/copy_element.txt
Modified:
 /src/robot/libraries/XML.py

=======================================
--- /dev/null
+++ /atest/robot/standard_libraries/xml/copy_element.txt Tue Sep 18 13:27:05 2012
@@ -0,0 +1,18 @@
+*** Settings ***
+Suite Setup Run Tests ${EMPTY} standard_libraries/xml/copy_element.txt
+Force Tags       regression    pybot    jybot
+Resource         atest_resource.txt
+
+*** Test Cases ***
+
+Elements Are Mutable
+    Check Test Case    ${TESTNAME}
+
+Copy Element
+    Check Test Case    ${TESTNAME}
+
+Copy Element Using Xpath
+    Check Test Case    ${TESTNAME}
+
+Copy Deeper Structure
+    Check Test Case    ${TESTNAME}
=======================================
--- /dev/null
+++ /atest/testdata/standard_libraries/xml/copy_element.txt Tue Sep 18 13:27:05 2012
@@ -0,0 +1,34 @@
+*** Settings ***
+Resource    resource.txt
+
+*** Test Cases ***
+Elements Are Mutable
+    ${xml} =    Parse XML    <r><child/></r>
+    ${child} =    Get Element    ${xml}    child
+    Add Element    ${xml}    ${child}
+    Elements Should Be Equal    ${xml}    <r><child/><child/></r>
+    Set Element Attribute    ${child}    a    1
+ Elements Should Be Equal ${xml} <r><child a="1"/><child a="1"/></r>
+
+Copy Element
+    ${xml} =    Parse XML    <r><child/></r>
+    ${child} =    Get Element    ${xml}    child
+    ${copy} =    Copy Element    ${child}
+    Add Element    ${xml}    ${copy}
+    Elements Should Be Equal    ${xml}    <r><child/><child/></r>
+    Set Element Attribute    ${child}    a    1
+    Elements Should Be Equal    ${xml}    <r><child a="1"/><child/></r>
+
+Copy Element Using Xpath
+    ${xml} =    Parse XML    <r><child/></r>
+    ${copy} =    Copy Element    ${xml}    xpath=child
+    Add Element    ${xml}    ${copy}
+    Elements Should Be Equal    ${xml}    <r><child/><child/></r>
+    Set Element Attribute    ${copy}    a    1
+    Elements Should Be Equal    ${xml}    <r><child/><child a="1"/></r>
+
+Copy Deeper Structure
+    ${xml} =    Parse XML    ${TEST}
+    ${copy} =    Copy Element    ${xml}    another
+    Set Element Text    ${copy}    new    xpath=child
+    Element Text Should Be    ${xml}    text    xpath=another/child
=======================================
--- /src/robot/libraries/XML.py Tue Sep 18 08:20:11 2012
+++ /src/robot/libraries/XML.py Tue Sep 18 13:27:05 2012
@@ -14,6 +14,7 @@

 from __future__ import with_statement

+import copy
 import re

 from robot.api import logger
@@ -753,6 +754,9 @@
                 if child is element:
                     return parent

+    def copy_element(self, source, xpath='.'):
+        return copy.deepcopy(self.get_element(source, xpath))
+
     def save_xml(self, source, path, encoding='UTF-8'):
         tree = ET.ElementTree(self.get_element(source))
         kwargs = {'xml_declaration': True} if ET.VERSION >= '1.3' else {}

==============================================================================
Revision: 9dbc14361aab
Branch:   default
Author:   Pekka Klärck
Date:     Tue Sep 18 13:59:04 2012
Log:      XML lib: Clear Element keyword

Update issue 1234
One more keyword: Clear Element.

Now I really think we have a good set of keywords from creating/modifying XML.
Documentation and customer feedback still missing.
http://code.google.com/p/robotframework/source/detail?r=9dbc14361aab

Added:
 /atest/robot/standard_libraries/xml/clear_element.txt
 /atest/testdata/standard_libraries/xml/clear_element.txt
Modified:
 /src/robot/libraries/XML.py

=======================================
--- /dev/null
+++ /atest/robot/standard_libraries/xml/clear_element.txt Tue Sep 18 13:59:04 2012
@@ -0,0 +1,15 @@
+*** Settings ***
+Suite Setup Run Tests ${EMPTY} standard_libraries/xml/clear_element.txt
+Force Tags       regression    pybot    jybot
+Resource         atest_resource.txt
+
+*** Test Cases ***
+
+Clear Element
+    Check Test Case    ${TESTNAME}
+
+Tail Text Is Not Cleared By Default
+    Check Test Case    ${TESTNAME}
+
+Tail Text Can Be Cleared
+    Check Test Case    ${TESTNAME}
=======================================
--- /dev/null
+++ /atest/testdata/standard_libraries/xml/clear_element.txt Tue Sep 18 13:59:04 2012
@@ -0,0 +1,18 @@
+*** Settings ***
+Resource    resource.txt
+
+*** Test Cases ***
+Clear Element
+    ${xml} =    Parse XML    ${TEST}
+    Clear Element    ${xml}
+    Elements Should Be Equal    ${xml}    <test/>
+
+Tail Text Is Not Cleared By Default
+ ${xml} = Parse XML <root><child attr="value">text</child>tail</root>
+    Clear Element    ${xml}    xpath=child
+    Elements Should Be Equal    ${xml}    <root><child/>tail</root>
+
+Tail Text Can Be Cleared
+ ${xml} = Parse XML <root><child attr="value">text</child>tail</root>
+    Clear Element    ${xml}    child    clear_tail=yes
+    Elements Should Be Equal    ${xml}    <root><child/></root>
=======================================
--- /src/robot/libraries/XML.py Tue Sep 18 13:27:05 2012
+++ /src/robot/libraries/XML.py Tue Sep 18 13:59:04 2012
@@ -757,6 +757,13 @@
     def copy_element(self, source, xpath='.'):
         return copy.deepcopy(self.get_element(source, xpath))

+    def clear_element(self, source, xpath='.', clear_tail=False):
+        element = self.get_element(source, xpath)
+        tail = element.tail
+        element.clear()
+        if not clear_tail:
+            element.tail = tail
+
     def save_xml(self, source, path, encoding='UTF-8'):
         tree = ET.ElementTree(self.get_element(source))
         kwargs = {'xml_declaration': True} if ET.VERSION >= '1.3' else {}

Reply via email to