4 new revisions:

Revision: 4f2773569e74
Author:   Pekka Klärck
Date:     Sat Jun 30 22:30:06 2012
Log:      XML library tests: updated error messages
http://code.google.com/p/robotframework/source/detail?r=4f2773569e74

Revision: 095b00081711
Author:   Pekka Klärck
Date:     Sun Jul  1 14:05:25 2012
Log: BuiltIn.length_should_be: Don't call get_length again upon error to av...
http://code.google.com/p/robotframework/source/detail?r=095b00081711

Revision: 89e8a5f75c2d
Author:   Pekka Klärck
Date:     Sun Jul  1 14:35:54 2012
Log:      XML library: Explicit tests with non-ASCII content.
http://code.google.com/p/robotframework/source/detail?r=89e8a5f75c2d

Revision: d3a3a20cd2ad
Author:   Pekka Klärck
Date:     Sun Jul  1 15:36:45 2012
Log: XML library: Moved XPATH tests to separate suite and worked around ann...
http://code.google.com/p/robotframework/source/detail?r=d3a3a20cd2ad

==============================================================================
Revision: 4f2773569e74
Author:   Pekka Klärck
Date:     Sat Jun 30 22:30:06 2012
Log:      XML library tests: updated error messages
http://code.google.com/p/robotframework/source/detail?r=4f2773569e74

Modified:
 /atest/testdata/standard_libraries/xml/parsing.txt

=======================================
--- /atest/testdata/standard_libraries/xml/parsing.txt Wed Jun 27 11:56:37 2012 +++ /atest/testdata/standard_libraries/xml/parsing.txt Sat Jun 30 22:30:06 2012
@@ -12,13 +12,13 @@
     Should be equal     ${root.text}     päivää

 Parse invalid file
-    [Documentation]    FAIL
+    [Documentation]    FAIL REGEXP: (SyntaxError|ExpatError): .*
     Parse XML    ${CURDIR}/parsing.txt

 Parse invalid string
-    [Documentation]    FAIL
+    [Documentation]    FAIL REGEXP: (SyntaxError|ExpatError): .*
     Parse XML    <kekkonen>urho

 Parse non-existing file
-    [Documentation]    FAIL Source file 'non-existing.xml' does not exist.
+    [Documentation]    FAIL STARTS: IOError:
     Parse XML    non-existing.xml

==============================================================================
Revision: 095b00081711
Author:   Pekka Klärck
Date:     Sun Jul  1 14:05:25 2012
Log: BuiltIn.length_should_be: Don't call get_length again upon error to avoid logging the lenght twice. Also tuned the error message a little.
http://code.google.com/p/robotframework/source/detail?r=095b00081711

Modified:
 /atest/robot/standard_libraries/builtin/verify.txt
 /atest/testdata/standard_libraries/builtin/verify.txt
 /src/robot/libraries/BuiltIn.py

=======================================
--- /atest/robot/standard_libraries/builtin/verify.txt Mon Feb 13 05:22:51 2012 +++ /atest/robot/standard_libraries/builtin/verify.txt Sun Jul 1 14:05:25 2012
@@ -153,7 +153,10 @@
     Check Log Message  ${tc.kws[5].kws[0].msgs[0]}  Length is 0

 Length Should Be
-    Check Test Case  ${TESTNAME}
+    ${tc} =  Check Test Case  ${TESTNAME}
+    Check Log Message  ${tc.kws[-1].msgs[0]}  Length is 2
+ Check Log Message ${tc.kws[-1].msgs[1]} Length of '*' should be 3 but is 2 FAIL pattern=yep
+    Length Should Be  ${tc.kws[-1].msgs}  2

 Length Should Be With Non Default Message
     Check Test Case  ${TESTNAME}
=======================================
--- /atest/testdata/standard_libraries/builtin/verify.txt Mon Feb 13 05:22:51 2012 +++ /atest/testdata/standard_libraries/builtin/verify.txt Sun Jul 1 14:05:25 2012
@@ -272,7 +272,7 @@
     Verify Get Length  ${10}  Getting length from an int fails

 Length Should Be
-    [Documentation]  FAIL Length of '['a', 'b']' should be 3 but it is 2
+    [Documentation]  FAIL Length of '['a', 'b']' should be 3 but is 2
     :FOR  ${input}     ${expected}  IN
     ...   ${TUPLE 0}   0
     ...   ${LIST 0}    0
=======================================
--- /src/robot/libraries/BuiltIn.py     Wed Jun  6 07:36:52 2012
+++ /src/robot/libraries/BuiltIn.py     Sun Jul  1 14:05:25 2012
@@ -750,11 +750,10 @@
         default error message can be overridden with the `msg` argument.
         """
         length = self._convert_to_integer(length)
-        if self.get_length(item) != length:
-            if not msg:
-                msg = "Length of '%s' should be %d but it is %d" \
-                        % (item, length, self.get_length(item))
-            raise AssertionError(msg)
+        actual = self.get_length(item)
+        if actual != length:
+ raise AssertionError(msg or "Length of '%s' should be %d but is %d"
+                                        % (item, length, actual))

     def should_be_empty(self, item, msg=None):
         """Verifies that the given item is empty.

==============================================================================
Revision: 89e8a5f75c2d
Author:   Pekka Klärck
Date:     Sun Jul  1 14:35:54 2012
Log:      XML library: Explicit tests with non-ASCII content.
http://code.google.com/p/robotframework/source/detail?r=89e8a5f75c2d

Modified:
 /atest/testdata/standard_libraries/xml/element_attribute.txt
 /atest/testdata/standard_libraries/xml/element_text.txt
 /atest/testdata/standard_libraries/xml/get_elements.txt
 /atest/testdata/standard_libraries/xml/to_string.txt

=======================================
--- /atest/testdata/standard_libraries/xml/element_attribute.txt Thu Jun 28 03:19:47 2012 +++ /atest/testdata/standard_libraries/xml/element_attribute.txt Sun Jul 1 14:35:54 2012
@@ -61,3 +61,11 @@
 Element attribute should match with custom error message
     [Documentation]    FAIL Special
Element Attribute Should Match <tag a="1"/> a ?? message=Special
+
+Non-ASCII
+    ${attr}=    Get Element Attribute    <täg ä='ö'/>    ä
+    Should Be Equal    ${attr}    ö
+    ${attrs}=    Get Element Attribute    <täg ä='ö'/>
+    Should Be True    ${attrs} == {u'\\xf6': u'\\xe4'}
+    Element Attribute Should Be    <täg ä='ö'/>    ä    ö
+    Element Attribute Should Match    <täg ä='öö'/>    ä    ö?
=======================================
--- /atest/testdata/standard_libraries/xml/element_text.txt Wed Jun 27 12:02:04 2012 +++ /atest/testdata/standard_libraries/xml/element_text.txt Sun Jul 1 14:35:54 2012
@@ -78,3 +78,9 @@
 Element text should match failing with custom message
     [Documentation]    FAIL my message
Element Text Should Match <tag>text</tag> x*x message=my message
+
+Non-ASCII
+    ${text}=    Get Element Text    <p><i>hyvää</i> yötä</p>
+    Should Be Equal    ${text}    hyvää yötä
+    Element Text Should Be    <p><i>hyvää</i> yötä</p>    hyvää yötä
+    Element Text Should Match    <p><i>hyvää</i> yötä</p>    ???ää yö*tä
=======================================
--- /atest/testdata/standard_libraries/xml/get_elements.txt Wed Jun 27 07:13:55 2012 +++ /atest/testdata/standard_libraries/xml/get_elements.txt Sun Jul 1 14:35:54 2012
@@ -46,3 +46,10 @@
     Length Should Be    ${children}    3
     ${children}=    Get Elements    ${TEST}    non-existing
     Length Should Be    ${children}    0
+
+Non-ASCII
+    ${elem}=    Get Element    <root><täg/></root>    täg
+    Should Be Equal    ${elem.tag}    täg
+    ${elems}=    Get Elements    <root><täg/><other/></root>    täg
+    Length Should Be    ${elems}    1
+    Should Be Equal    ${elems[0].tag}    täg
=======================================
--- /atest/testdata/standard_libraries/xml/to_string.txt Sat Jun 30 08:12:38 2012 +++ /atest/testdata/standard_libraries/xml/to_string.txt Sun Jul 1 14:35:54 2012
@@ -3,7 +3,7 @@
 Resource     resource.txt

 *** Variables ***
-${XML}    <root>\n\t<tag attr="1">content</tag>\n</root>
+${XML}    <root>\n\t<täg attr="hyvä">sisältö</täg>\n</root>

 *** Test Cases ***
 Element to string

==============================================================================
Revision: d3a3a20cd2ad
Author:   Pekka Klärck
Date:     Sun Jul  1 15:36:45 2012
Log: XML library: Moved XPATH tests to separate suite and worked around annoying Unicode bug in ET 1.2 (i.e. Python < 2.7). Notice that tests for .., predicates, and more complex XPATHs with non-ASCII chars only work with Python >= 2.7. I have not actually run these tests in Python 2.7, though.
http://code.google.com/p/robotframework/source/detail?r=d3a3a20cd2ad

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

=======================================
--- /dev/null
+++ /atest/testdata/standard_libraries/xml/xpath.txt Sun Jul 1 15:36:45 2012
@@ -0,0 +1,82 @@
+*** Settings ***
+Documentation    Tests ET's XPATH support documented at
+...              http://effbot.org/zone/element-xpath.htm
+...              Notice that '..', predicates ('[stuff]'), and more complex
+...              expressions with non-ASCII characters require ET 1.3
+...              (i.e. interpreter version 2.7) or newer.
+Resource         resource.txt
+Test Template    Get element by xpath
+
+
+*** Test Cases ***
+Tag
+    another    another
+
+Path
+    another/child    child    text
+
+'*'
+    */grandchild    grandchild    grand child text
+
+'.'
+    .    test
+    ./another    another
+
+'//'
+    .//grandchild    grandchild
+
+'//' returning multiple elements
+    [Template]    NONE
+    @{elements}=    Get Elements    ${TEST}    .//child
+    Length Should Be    ${elements}    4
+    :FOR    ${elem}    IN    @{elements}
+    \    Should Be Equal    ${elem.tag}    child
+    Should Be Equal    ${elem.text}    text
+
+'..'
+    [Template]    NONE
+    ${child}=    Get Element    ${test}    .//grandchild
+    ${parent}=    Get Element    ${child}    ..
+    Should Be Equal    ${parent.attrib['id']}    2
+    ${another}=    Get Element    ${child}    ../../another
+    Should Be Equal    ${another.attrib['attr']}    value
+
+'[@attrib]'
+    [Documentation]    FAIL No element matching 'child[@nonex]' found.
+    child[@a2]    child    ${NONE}
+    child[@nonex]    not-found
+
+'[@attrib="value"]'
+    [Documentation]    FAIL No element matching 'child[@id="xxx"]' found.
+    child[@id="2"]    child    \n${SPACE*8}child 2 text\n${SPACE*8}
+    child[@a2='xxx']    child    ${NONE}
+    child[@id="xxx"]    not-found
+
+'[tag]'
+    [Documentation]    FAIL No element matching '.[nonex]' found.
+    .[grandchild]    child
+    .[nonex]    not-found
+
+'[position]'
+    [Documentation]    FAIL No element matching 'child[4]' found.
+    child[1]    child    child 1 text
+    child[3]    child    ${NONE}
+    child[4]    not-found
+
+Stacked predicates
+    child[@id][@a3='y']    child    ${NONE}
+
+Non-ASCII tag names
+    täg    täg    xml=<rööt><täg/></rööt>
+    täg/chïld    chïld    xml=<rööt><täg><chïld/></täg></rööt>
+
+More complex non-ASCII xpath
+    .//chïld    chïld    xml=<rööt><täg><chïld/></täg></rööt>
+
+
+*** Keywords ***
+Get element by xpath
+    [Arguments]    ${xpath}    ${tag}    ${text}=IGNORE    ${xml}=${TEST}
+    ${element}=     Get Element    ${xml}    ${xpath}
+    Should Be Equal    ${element.tag}    ${tag}
+ Run Keyword If '${text}' != 'IGNORE' Should Be Equal ${element.text} ${text}
=======================================
--- /atest/testdata/standard_libraries/xml/get_elements.txt Sun Jul 1 14:35:54 2012 +++ /atest/testdata/standard_libraries/xml/get_elements.txt Sun Jul 1 15:36:45 2012
@@ -1,9 +1,9 @@
 *** Settings ***
 Resource     resource.txt

-*** Test cases ***
+*** Test Cases ***
 Get element from parent element
-    ${root} =   Parse XML     ${TEST}
+    ${root}=   Parse XML     ${TEST}
     ${element}=    Get Element    ${root}    another
     Should Be Equal    ${element.tag}    another
     ${element}=    Get Element    ${element}    child
@@ -12,38 +12,27 @@
 Get element from xml file
     ${child}=    Get Element    ${TEST}    another
     Should Be Equal    ${child.tag}    another
+    ${child}=    Get Element    ${TEST}    child/grandchild
+    Should Be Equal    ${child.text}    grand child text

 Get element from xml string
     ${child}=    Get Element    <root><tag>text</tag></root>    tag
     Should Be Equal    ${child.text}    text

-Get grandchild element
-    ${child}=    Get Element    ${TEST}    child/grandchild
-    Should Be Equal    ${child.text}    grand child text
-
-Get element with index
-    [Documentation]    FAIL No element matching 'child[4]' found.
-    ${child}=    Get Element    ${TEST}    child[1]
-    Should Be Equal    ${child.text}    child 1 text
-    ${child}=    Get Element    ${TEST}    child[3]
-    Should Be Equal    ${child.text}    ${NONE}
-    Get Element    ${TEST}    child[4]
-
-Get element must match exactly one
+Get element fails when multiple elements match
     [Documentation]    FAIL Multiple elements (3) matching 'child' found.
     Get Element    ${TEST}    child

-Get element with attribute
-    ${child}=    Get Element    ${TEST}    child[@id="2"]
-    Should Be Equal    ${child.tag}    child
-
-Get non-existing element
+Get element fails when no elements match
     [Documentation]    FAIL No element matching 'non-existing' found.
     Get Element    ${TEST}    non-existing

 Get elements
     ${children}=    Get Elements    ${TEST}    child
     Length Should Be    ${children}    3
+    Should Be Equal    ${children[0].text}    child 1 text
+
+Get elements returns empty list when no elements match
     ${children}=    Get Elements    ${TEST}    non-existing
     Length Should Be    ${children}    0

=======================================
--- /src/robot/libraries/XML.py Sat Jun 30 13:13:45 2012
+++ /src/robot/libraries/XML.py Sun Jul  1 15:36:45 2012
@@ -15,6 +15,7 @@
 from __future__ import with_statement

 import re
+import sys

 from robot.api import logger
 from robot.libraries.BuiltIn import BuiltIn
@@ -55,7 +56,21 @@
         return source

     def get_elements(self, source, xpath):
-        return self._get_parent(source).findall(xpath)
+        return self._get_parent(source).findall(self._get_xpath(xpath))
+
+    if sys.version_info < (2, 7):
+        def _get_xpath(self, xpath):
+            try:
+                return str(xpath)
+            except UnicodeError:
+                if xpath.replace('/', '').isalnum():
+                    return xpath
+ raise RuntimeError('Non-ASCII XPATHs containing other than ' + 'tag names are not supported with Python '
+                                   'interpreters below 2.7.')
+    else:
+        def _get_xpath(self, xpath):
+            return xpath

def get_element_text(self, source, xpath='.', normalize_whitespace=False):
         element = self.get_element(source, xpath)

Reply via email to