4 new revisions:

Revision: e14e0d8606c3
Branch:   default
Author:   Pekka Klärck
Date:     Tue Sep 18 01:17:25 2012
Log: Dialogs: Own module for IPy version. No real IPy code yet, though....
http://code.google.com/p/robotframework/source/detail?r=e14e0d8606c3

Revision: 9ca3c557e0b1
Branch:   default
Author:   Pekka Klärck
Date:     Tue Sep 18 01:21:55 2012
Log:      XML library: Support for saving XML....
http://code.google.com/p/robotframework/source/detail?r=9ca3c557e0b1

Revision: d77c1c79a5ed
Branch:   default
Author:   Pekka Klärck
Date:     Tue Sep 18 01:48:39 2012
Log:      XML lib: Default value for xpath given to `Get Element`....
http://code.google.com/p/robotframework/source/detail?r=d77c1c79a5ed

Revision: f36a0026ce81
Branch:   default
Author:   Pekka Klärck
Date:     Tue Sep 18 02:08:30 2012
Log: XML lib: Implemented keywords for modifying element information....
http://code.google.com/p/robotframework/source/detail?r=f36a0026ce81

==============================================================================
Revision: e14e0d8606c3
Branch:   default
Author:   Pekka Klärck
Date:     Tue Sep 18 01:17:25 2012
Log:      Dialogs: Own module for IPy version. No real IPy code yet, though.

Update issue 1235
Status: Started
Now there is a separate `dialogs_ipy.py` file where IronPython code belongs to.
This change also makes it possible to import Dialogs with IPy. None of the
keywords work yet, though.
http://code.google.com/p/robotframework/source/detail?r=e14e0d8606c3

Added:
 /src/robot/libraries/dialogs_ipy.py
Modified:
 /src/robot/libraries/Dialogs.py

=======================================
--- /dev/null
+++ /src/robot/libraries/dialogs_ipy.py Tue Sep 18 01:17:25 2012
@@ -0,0 +1,43 @@
+#  Copyright 2008-2012 Nokia Siemens Networks Oyj
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+
+class _AbstractWinformsDialog:
+
+    def __init__(self):
+ raise RuntimeError('This keyword is not yet implemented with IronPython')
+
+
+class MessageDialog(_AbstractWinformsDialog):
+
+    def __init__(self, message):
+        _AbstractWinformsDialog.__init__(self)
+
+
+class InputDialog(_AbstractWinformsDialog):
+
+    def __init__(self, message, default):
+        _AbstractWinformsDialog.__init__(self)
+
+
+class SelectionDialog(_AbstractWinformsDialog):
+
+    def __init__(self, message, options):
+        _AbstractWinformsDialog.__init__(self)
+
+
+class PassFailDialog(_AbstractWinformsDialog):
+
+    def __init__(self, message):
+        _AbstractWinformsDialog.__init__(self)
=======================================
--- /src/robot/libraries/Dialogs.py     Tue Mar  6 00:46:30 2012
+++ /src/robot/libraries/Dialogs.py     Tue Sep 18 01:17:25 2012
@@ -21,17 +21,17 @@

 The library has following two limitations:
 - It is not compatible with IronPython.
-- It cannot be used with timeouts in Python.
+- It cannot be used with timeouts on Python.
 """

 import sys

 if sys.platform.startswith('java'):
- from dialogs_jy import MessageDialog, PassFailDialog, InputDialog, SelectionDialog + from .dialogs_jy import MessageDialog, PassFailDialog, InputDialog, SelectionDialog
 elif sys.platform == 'cli':
-    raise ImportError('Dialogs library is not supported on IronPython')
+ from .dialogs_ipy import MessageDialog, PassFailDialog, InputDialog, SelectionDialog
 else:
- from dialogs_py import MessageDialog, PassFailDialog, InputDialog, SelectionDialog + from .dialogs_py import MessageDialog, PassFailDialog, InputDialog, SelectionDialog

 try:
     from robot.version import get_version

==============================================================================
Revision: 9ca3c557e0b1
Branch:   default
Author:   Pekka Klärck
Date:     Tue Sep 18 01:21:55 2012
Log:      XML library: Support for saving XML.

Update issue 1234
Status: Started
Implemented and tested `Save XML` keyword. Docs missing.
http://code.google.com/p/robotframework/source/detail?r=9ca3c557e0b1

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

=======================================
--- /dev/null
+++ /atest/robot/standard_libraries/xml/save_xml.txt Tue Sep 18 01:21:55 2012
@@ -0,0 +1,33 @@
+*** Settings ***
+Suite Setup Run Tests ${EMPTY} standard_libraries/xml/save_xml.txt
+Force Tags       regression    pybot    jybot
+Resource         atest_resource.txt
+
+*** Test Cases ***
+
+Save XML Element
+    Check Test Case    ${TESTNAME}
+
+Save XML String
+    Check Test Case    ${TESTNAME}
+
+Save XML File
+    Check Test Case    ${TESTNAME}
+
+Save XML Using Custom Encoding
+    Check Test Case    ${TESTNAME}
+
+Save Non-ASCII XML
+    Check Test Case    ${TESTNAME}
+
+Save Non-ASCII XML Using Custom Encoding
+    Check Test Case    ${TESTNAME}
+
+Save to Invalid File
+    Check Test Case    ${TESTNAME}
+
+Save Using Invalid Encoding
+    Check Test Case    ${TESTNAME}
+
+Save Non-ASCII Using ASCII
+    Check Test Case    ${TESTNAME}
=======================================
--- /dev/null
+++ /atest/testdata/standard_libraries/xml/save_xml.txt Tue Sep 18 01:21:55 2012
@@ -0,0 +1,56 @@
+*** Settings ***
+Resource        resource.txt
+Library         OperatingSystem
+Test Setup      Remove File    ${OUTPUT}
+
+*** Variables ***
+${OUTPUT}       %{TEMPDIR}/xmllib.xml
+${SIMPLE}       <root><child a="1" /><child>text</child></root>
+${NON-ASCII}    <hyvää>yötä</hyvää>
+
+*** Test Cases ***
+
+Save XML Element
+    ${xml} =    Parse XML    ${SIMPLE}
+    Save XML    ${xml}    ${OUTPUT}
+    XML Content Should Be    ${SIMPLE}
+
+Save XML String
+    Save XML    ${SIMPLE}    ${OUTPUT}
+    XML Content Should Be    ${SIMPLE}
+
+Save XML File
+    Save XML    ${TEST}    ${OUTPUT}
+    Elements Should Be Equal    ${TEST}    ${OUTPUT}
+
+Save XML Using Custom Encoding
+    Save XML    ${SIMPLE}    ${OUTPUT}    encoding=US-ASCII
+    XML Content Should Be    ${SIMPLE}    encoding=US-ASCII
+
+Save Non-ASCII XML
+    Save XML    ${NON-ASCII}    ${OUTPUT}
+    XML Content Should Be    ${NON-ASCII}
+
+Save Non-ASCII XML Using Custom Encoding
+    Save XML    ${NON-ASCII}    ${OUTPUT}    iso-8859-1
+    XML Content Should Be    ${NON-ASCII}    iso-8859-1
+
+Save to Invalid File
+    [Documentation]    FAIL STARTS: IOError:
+    Save XML    ${SIMPLE}    %{TEMPDIR}
+
+Save Using Invalid Encoding
+    [Documentation]    FAIL STARTS: LookupError:
+    Save XML    ${SIMPLE}    ${OUTPUT}    encoding=invalid
+
+Save Non-ASCII Using ASCII
+    [Documentation]    FAIL STARTS: UnicodeEncodeError:
+    Save XML    ${NON-ASCII}    ${OUTPUT}    ASCII
+
+
+*** Keywords ***
+
+XML Content Should Be
+    [Arguments]    ${expected}    ${encoding}=UTF-8
+    ${actual} =    Get File    ${OUTPUT}    ${encoding}
+ Should Be Equal ${actual} <?xml version='1.0' encoding='${encoding}'?>\n${expected}
=======================================
--- /src/robot/libraries/XML.py Thu Sep 13 05:46:24 2012
+++ /src/robot/libraries/XML.py Tue Sep 18 01:21:55 2012
@@ -285,6 +285,11 @@
         with ETSource(source) as source:
             return ET.parse(source).getroot()

+    def save_xml(self, source, path, encoding='UTF-8'):
+        tree = ET.ElementTree(self.get_element(source, xpath='.'))
+        kwargs = {'xml_declaration': True} if ET.VERSION >= '1.3' else {}
+        tree.write(path, encoding, **kwargs)
+
     def get_element(self, source, xpath):
         """Returns an element in the `source` matching the `xpath`.


==============================================================================
Revision: d77c1c79a5ed
Branch:   default
Author:   Pekka Klärck
Date:     Tue Sep 18 01:48:39 2012
Log:      XML lib: Default value for xpath given to `Get Element`.

Most importantly this allows using the keyword using named arguments:

| Get Elements | ${XML} | xpath=what/ever |
http://code.google.com/p/robotframework/source/detail?r=d77c1c79a5ed

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

=======================================
--- /atest/robot/standard_libraries/xml/get_elements.txt Thu Jul 5 04:48:26 2012 +++ /atest/robot/standard_libraries/xml/get_elements.txt Tue Sep 18 01:48:39 2012
@@ -13,6 +13,12 @@

 Get element from xml string
     Check Test Case    ${TESTNAME}
+
+Get element with named xpath
+    Check Test Case    ${TESTNAME}
+
+Get element without xpath
+    Check Test Case    ${TESTNAME}

 Get element fails when multiple elements match
     Check Test Case    ${TESTNAME}
=======================================
--- /atest/testdata/standard_libraries/xml/get_elements.txt Thu Jul 5 05:03:56 2012 +++ /atest/testdata/standard_libraries/xml/get_elements.txt Tue Sep 18 01:48:39 2012
@@ -19,6 +19,14 @@
     ${child}=    Get Element    <root><tag>text</tag></root>    tag
     Should Be Equal    ${child.text}    text

+Get element with named xpath
+    ${child}=    Get Element    <root><tag>text</tag></root>    xpath=tag
+    Should Be Equal    ${child.text}    text
+
+Get element without xpath
+    ${root}=    Get Element    <root><tag>text</tag></root>
+    Should Be Equal    ${root.tag}    root
+
 Get element fails when multiple elements match
     [Documentation]    FAIL Multiple elements (3) matching 'child' found.
     Get Element    ${TEST}    child
=======================================
--- /src/robot/libraries/XML.py Tue Sep 18 01:21:55 2012
+++ /src/robot/libraries/XML.py Tue Sep 18 01:48:39 2012
@@ -286,11 +286,11 @@
             return ET.parse(source).getroot()

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

-    def get_element(self, source, xpath):
+    def get_element(self, source, xpath='.'):
         """Returns an element in the `source` matching the `xpath`.

The `source` can be a path to an XML file, a string containing XML, or
@@ -652,8 +652,8 @@
                           normalize_whitespace):
normalizer = self._normalize_whitespace if normalize_whitespace else None comparator = ElementComparator(comparator, normalizer, exclude_children)
-        comparator.compare(self.get_element(source, xpath='.'),
-                           self.get_element(expected, xpath='.'))
+        comparator.compare(self.get_element(source),
+                           self.get_element(expected))

     def element_to_string(self, source, xpath='.'):
         """Returns the string representation of the specified element.

==============================================================================
Revision: f36a0026ce81
Branch:   default
Author:   Pekka Klärck
Date:     Tue Sep 18 02:08:30 2012
Log:      XML lib: Implemented keywords for modifying element information.

Update issue 1234
Implemented, and tested, following keywords. Docs missing.

Set Element Tag
Set Element Text (allows also setting tail text)
Set Element Attribute
Remove Element Attribute
Remove Element Attributes
http://code.google.com/p/robotframework/source/detail?r=f36a0026ce81

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

=======================================
--- /dev/null
+++ /atest/robot/standard_libraries/xml/set_element_information.txt Tue Sep 18 02:08:30 2012
@@ -0,0 +1,33 @@
+*** Settings ***
+Suite Setup Run Tests ${EMPTY} standard_libraries/xml/set_element_information.txt
+Force Tags       regression    pybot    jybot
+Resource         atest_resource.txt
+
+*** Test Cases ***
+
+Set Element Tag
+    Check Test Case    ${TESTNAME}
+
+Set Tag Using Xpath
+    Check Test Case    ${TESTNAME}
+
+Set Element Text
+    Check Test Case    ${TESTNAME}
+
+Set Element Text And Tail
+    Check Test Case    ${TESTNAME}
+
+Set Element Attribute
+    Check Test Case    ${TESTNAME}
+
+Overwrite Element Attribute
+    Check Test Case    ${TESTNAME}
+
+Remove Element Attribute
+    Check Test Case    ${TESTNAME}
+
+Removing Non-Existing Attribute Passes
+    Check Test Case    ${TESTNAME}
+
+Remove Element Attributes
+    Check Test Case    ${TESTNAME}
=======================================
--- /dev/null
+++ /atest/testdata/standard_libraries/xml/set_element_information.txt Tue Sep 18 02:08:30 2012
@@ -0,0 +1,62 @@
+*** Settings ***
+Resource        resource.txt
+Test Setup      Parse Simple XML
+
+*** Variables ***
+${SIMPLE}       <root><child id="1">text</child></root>
+
+*** Test Cases ***
+
+Set Element Tag
+    Set Element Tag    ${XML}    kekkonen
+    Should Be Equal    ${XML.tag}    kekkonen
+
+Set Tag Using Xpath
+    Set Element Tag    ${XML}    kekkonen    xpath=child
+    Should Be Equal    ${XML.tag}    root
+    Element Text Should Be    ${XML}    text    xpath=kekkonen
+
+Set Element Text
+    Set Element Text    ${XML}    new    xpath=child
+    Element Text Should Be    ${XML}    new    xpath=child
+
+Set Element Text And Tail
+    ${child} =    Get Element    ${XML}    child
+    Set Element Text    ${XML}    new text    new tail    xpath=child
+    Should Be Equal    ${child.text}    new text
+    Should Be Equal    ${child.tail}    new tail
+    Set Element Text    ${child}    tail=
+    Should Be Equal    ${child.text}    new text
+    Should Be Equal    ${child.tail}    ${EMPTY}
+    Set Element Text    ${child}    text=final value
+    Should Be Equal    ${child.text}    final value
+    Should Be Equal    ${child.tail}    ${EMPTY}
+
+Set Element Attribute
+    Set Element Attribute    ${XML}    attr    value
+    Element Attribute Should Be    ${XML}    attr    value
+
+Overwrite Element Attribute
+    Set Element Attribute    ${XML}    id    new    xpath=child
+    Element Attribute Should Be    ${XML}    id    new    xpath=child
+
+Remove Element Attribute
+    Remove Element Attribute    ${XML}    id    xpath=child
+    Element Attribute Should Be    ${XML}    id    ${NONE}    xpath=child
+
+Removing Non-Existing Attribute Passes
+    Remove Element Attribute    ${XML}    nonex
+    Should Be Empty    ${XML.attrib}
+
+Remove Element Attributes
+    Remove Element Attributes    ${XML}
+    Should Be Empty    ${XML.attrib}
+    Remove Element Attributes    ${XML}    xpath=child
+    ${attrib} =    Get Element Attributes    ${XML}    xpath=child
+    Should Be Empty    ${attrib}
+
+
+*** Keywords ***
+Parse Simple XML
+    ${XML} =    Parse XML    ${SIMPLE}
+    Set Test Variable    ${XML}
=======================================
--- /src/robot/libraries/XML.py Tue Sep 18 01:48:39 2012
+++ /src/robot/libraries/XML.py Tue Sep 18 02:08:30 2012
@@ -285,11 +285,6 @@
         with ETSource(source) as source:
             return ET.parse(source).getroot()

-    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 {}
-        tree.write(path, encoding, **kwargs)
-
     def get_element(self, source, xpath='.'):
         """Returns an element in the `source` matching the `xpath`.

@@ -683,6 +678,33 @@
         logger.write(string, level)
         return string

+    def set_element_tag(self, source, tag, xpath='.'):
+        self.get_element(source, xpath).tag = tag
+
+    def set_element_text(self, source, text=None, tail=None, xpath='.'):
+        element = self.get_element(source, xpath)
+        if text is not None:
+            element.text = text
+        if tail is not None:
+            element.tail = tail
+
+    def set_element_attribute(self, source, name, value, xpath='.'):
+        self.get_element(source, xpath).attrib[name] = value
+
+    def remove_element_attribute(self, source, name, xpath='.'):
+        try:
+            self.get_element(source, xpath).attrib.pop(name)
+        except KeyError:
+            pass
+
+    def remove_element_attributes(self, source, xpath='.'):
+        self.get_element(source, xpath).attrib.clear()
+
+    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 {}
+        tree.write(path, encoding, **kwargs)
+

 class ElementComparator(object):

Reply via email to