2 new revisions:

Revision: 50e022e66cea
Branch:   default
Author:   Pekka Klärck
Date:     Thu May 29 08:17:10 2014 UTC
Log:      XML: Tuning how to enable lxml support....
http://code.google.com/p/robotframework/source/detail?r=50e022e66cea

Revision: 9cca66a2fc0b
Branch:   default
Author:   Pekka Klärck
Date:     Thu May 29 10:22:37 2014 UTC
Log:      XML: Documented lxml support....
http://code.google.com/p/robotframework/source/detail?r=9cca66a2fc0b

==============================================================================
Revision: 50e022e66cea
Branch:   default
Author:   Pekka Klärck
Date:     Thu May 29 08:17:10 2014 UTC
Log:      XML: Tuning how to enable lxml support.

Update issue 1623
Changed `lxml` attribute given to __init__ to `use_lxml` and tuned warning when lxml is not availabe.
http://code.google.com/p/robotframework/source/detail?r=50e022e66cea

Modified:
 /atest/robot/standard_libraries/xml/xml_resource.txt
/atest/testdata/standard_libraries/xml/add_and_remove_elements_with_lxml.txt
 /atest/testdata/standard_libraries/xml/clear_element_with_lxml.txt
 /atest/testdata/standard_libraries/xml/copy_element_with_lxml.txt
 /atest/testdata/standard_libraries/xml/element_attribute_with_lxml.txt
 /atest/testdata/standard_libraries/xml/element_should_exist_with_lxml.txt
 /atest/testdata/standard_libraries/xml/element_text_with_lxml.txt
/atest/testdata/standard_libraries/xml/elements_should_be_equal_with_lxml.txt
 /atest/testdata/standard_libraries/xml/elements_should_match_with_lxml.txt
 /atest/testdata/standard_libraries/xml/etree_namespaces_with_lxml.txt
 /atest/testdata/standard_libraries/xml/get_elements_with_lxml.txt
 /atest/testdata/standard_libraries/xml/namespaces_with_lxml.txt
 /atest/testdata/standard_libraries/xml/parsing_with_lxml.txt
 /atest/testdata/standard_libraries/xml/save_xml_with_lxml.txt
/atest/testdata/standard_libraries/xml/set_element_information_with_lxml.txt
 /atest/testdata/standard_libraries/xml/to_string_with_lxml.txt
 /atest/testdata/standard_libraries/xml/xpath_with_lxml.txt
 /src/robot/libraries/XML.py

=======================================
--- /atest/robot/standard_libraries/xml/xml_resource.txt Tue May 27 21:37:32 2014 UTC +++ /atest/robot/standard_libraries/xml/xml_resource.txt Thu May 29 08:17:10 2014 UTC
@@ -2,7 +2,7 @@
 Resource         atest_resource.txt

 *** Variables ***
-${NO LXML} XML library reverted to use standard ElementTree because requested lxml is not installed. +${NO LXML} XML library reverted to use standard ElementTree because lxml module is not installed.

 *** Keywords ***
 Make test non-critical if lxml not available
=======================================
--- /atest/testdata/standard_libraries/xml/add_and_remove_elements_with_lxml.txt Tue May 27 21:29:24 2014 UTC +++ /atest/testdata/standard_libraries/xml/add_and_remove_elements_with_lxml.txt Thu May 29 08:17:10 2014 UTC
@@ -1,6 +1,6 @@
 *** Settings ***
 Suite Setup       Set lxml availability to suite metadata
-Library           XML    lxml=yes
+Library           XML    use_lxml=yes
 Resource          resource.txt
 Test Setup        Parse XML To Test Variable    ${SIMPLE}    \${XML}

=======================================
--- /atest/testdata/standard_libraries/xml/clear_element_with_lxml.txt Tue May 27 21:29:24 2014 UTC +++ /atest/testdata/standard_libraries/xml/clear_element_with_lxml.txt Thu May 29 08:17:10 2014 UTC
@@ -1,6 +1,6 @@
 *** Settings ***
 Suite Setup       Set lxml availability to suite metadata
-Library           XML    lxml=yes
+Library           XML    use_lxml=yes
 Resource          resource.txt

 *** Variables ***
=======================================
--- /atest/testdata/standard_libraries/xml/copy_element_with_lxml.txt Tue May 27 21:29:24 2014 UTC +++ /atest/testdata/standard_libraries/xml/copy_element_with_lxml.txt Thu May 29 08:17:10 2014 UTC
@@ -1,6 +1,6 @@
 *** Settings ***
 Suite Setup       Set lxml availability to suite metadata
-Library           XML    lxml=yes
+Library           XML    use_lxml=yes
 Resource          resource.txt

 *** Test Cases ***
=======================================
--- /atest/testdata/standard_libraries/xml/element_attribute_with_lxml.txt Tue May 27 21:29:24 2014 UTC +++ /atest/testdata/standard_libraries/xml/element_attribute_with_lxml.txt Thu May 29 08:17:10 2014 UTC
@@ -1,6 +1,6 @@
 *** Settings ***
 Suite Setup       Set lxml availability to suite metadata
-Library           XML    lxml=yes
+Library           XML    use_lxml=yes
 Resource          resource.txt

 *** Test Cases ***
=======================================
--- /atest/testdata/standard_libraries/xml/element_should_exist_with_lxml.txt Tue May 27 21:29:24 2014 UTC +++ /atest/testdata/standard_libraries/xml/element_should_exist_with_lxml.txt Thu May 29 08:17:10 2014 UTC
@@ -1,6 +1,6 @@
 *** Settings ***
 Suite Setup       Set lxml availability to suite metadata
-Library           XML    lxml=yes
+Library           XML    use_lxml=yes
 Resource          resource.txt

 *** Test Cases ***
=======================================
--- /atest/testdata/standard_libraries/xml/element_text_with_lxml.txt Tue May 27 21:29:24 2014 UTC +++ /atest/testdata/standard_libraries/xml/element_text_with_lxml.txt Thu May 29 08:17:10 2014 UTC
@@ -1,6 +1,6 @@
 *** Settings ***
 Suite Setup       Set lxml availability to suite metadata
-Library           XML    lxml=yes
+Library           XML    use_lxml=yes
 Resource          resource.txt

 *** Test cases ***
=======================================
--- /atest/testdata/standard_libraries/xml/elements_should_be_equal_with_lxml.txt Tue May 27 21:29:24 2014 UTC +++ /atest/testdata/standard_libraries/xml/elements_should_be_equal_with_lxml.txt Thu May 29 08:17:10 2014 UTC
@@ -1,7 +1,7 @@
 *** Settings ***
 Suite Setup       Set lxml availability to suite metadata
 Test Template     Elements should not be equal
-Library           XML    lxml=yes
+Library           XML    use_lxml=yes
 Resource          resource.txt

 *** Test Cases ***
=======================================
--- /atest/testdata/standard_libraries/xml/elements_should_match_with_lxml.txt Tue May 27 21:29:24 2014 UTC +++ /atest/testdata/standard_libraries/xml/elements_should_match_with_lxml.txt Thu May 29 08:17:10 2014 UTC
@@ -1,7 +1,7 @@
 *** Settings ***
 Suite Setup       Set lxml availability to suite metadata
 Test Template     Elements should not match
-Library           XML    lxml=yes
+Library           XML    use_lxml=yes
 Resource          resource.txt

 *** Test cases ***
=======================================
--- /atest/testdata/standard_libraries/xml/etree_namespaces_with_lxml.txt Tue May 27 21:29:24 2014 UTC +++ /atest/testdata/standard_libraries/xml/etree_namespaces_with_lxml.txt Thu May 29 08:17:10 2014 UTC
@@ -3,7 +3,7 @@
 ...               AND    Remove File    ${OUTPUT}
Test Setup Parse XML To Test Variable ${NS} \${ROOT} etree namespaces
 Test Teardown     Remove File    ${OUTPUT}
-Library           XML    lxml=yes
+Library           XML    use_lxml=yes
 Resource          resource.txt

 *** Test Cases ***
=======================================
--- /atest/testdata/standard_libraries/xml/get_elements_with_lxml.txt Tue May 27 21:29:24 2014 UTC +++ /atest/testdata/standard_libraries/xml/get_elements_with_lxml.txt Thu May 29 08:17:10 2014 UTC
@@ -1,6 +1,6 @@
 *** Settings ***
 Suite Setup       Set lxml availability to suite metadata
-Library           XML    lxml=yes
+Library           XML    use_lxml=yes
 Resource          resource.txt

 *** Test Cases ***
=======================================
--- /atest/testdata/standard_libraries/xml/namespaces_with_lxml.txt Tue May 27 21:29:24 2014 UTC +++ /atest/testdata/standard_libraries/xml/namespaces_with_lxml.txt Thu May 29 08:17:10 2014 UTC
@@ -2,7 +2,7 @@
 Suite Setup       Set lxml availability to suite metadata
 Test Setup        Remove File    ${OUTPUT}
 Suite Teardown    Remove File    ${OUTPUT}
-Library           XML    lxml=yes
+Library           XML    use_lxml=yes
 Resource          resource.txt

 *** Test Cases ***
=======================================
--- /atest/testdata/standard_libraries/xml/parsing_with_lxml.txt Tue May 27 21:29:24 2014 UTC +++ /atest/testdata/standard_libraries/xml/parsing_with_lxml.txt Thu May 29 08:17:10 2014 UTC
@@ -1,6 +1,6 @@
 *** Settings ***
 Suite Setup       Set lxml availability to suite metadata
-Library           XML    lxml=yes
+Library           XML    use_lxml=yes
 Resource          resource.txt

 *** Test Cases ***
=======================================
--- /atest/testdata/standard_libraries/xml/save_xml_with_lxml.txt Tue May 27 21:29:24 2014 UTC +++ /atest/testdata/standard_libraries/xml/save_xml_with_lxml.txt Thu May 29 08:17:10 2014 UTC
@@ -2,7 +2,7 @@
 Suite Setup       Set lxml availability to suite metadata
 Test Setup        Remove File    ${OUTPUT}
 Suite Teardown    Remove File    ${OUTPUT}
-Library           XML    lxml=yes
+Library           XML    use_lxml=yes
 Resource          resource.txt

 *** Variables ***
=======================================
--- /atest/testdata/standard_libraries/xml/set_element_information_with_lxml.txt Tue May 27 21:29:24 2014 UTC +++ /atest/testdata/standard_libraries/xml/set_element_information_with_lxml.txt Thu May 29 08:17:10 2014 UTC
@@ -1,7 +1,7 @@
 *** Settings ***
 Suite Setup       Set lxml availability to suite metadata
 Test Setup        Parse XML To Test Variable    ${SIMPLE}    \${XML}
-Library           XML    lxml=yes
+Library           XML    use_lxml=yes
 Resource          resource.txt

 *** Test Cases ***
=======================================
--- /atest/testdata/standard_libraries/xml/to_string_with_lxml.txt Tue May 27 21:29:24 2014 UTC +++ /atest/testdata/standard_libraries/xml/to_string_with_lxml.txt Thu May 29 08:17:10 2014 UTC
@@ -1,6 +1,6 @@
 *** Settings ***
 Suite Setup       Set lxml availability to suite metadata
-Library           XML    lxml=yes
+Library           XML    use_lxml=yes
 Resource          resource.txt

 *** Variables ***
=======================================
--- /atest/testdata/standard_libraries/xml/xpath_with_lxml.txt Wed May 28 20:07:28 2014 UTC +++ /atest/testdata/standard_libraries/xml/xpath_with_lxml.txt Thu May 29 08:17:10 2014 UTC
@@ -1,7 +1,7 @@
 *** Settings ***
 Suite Setup       Set lxml availability to suite metadata
 Test Template     Xpath should match element
-Library           XML    lxml=true
+Library           XML    use_lxml=true
 Resource          resource.txt

 *** Test Cases ***
=======================================
--- /src/robot/libraries/XML.py Wed May 28 20:07:28 2014 UTC
+++ /src/robot/libraries/XML.py Thu May 29 08:17:10 2014 UTC
@@ -370,18 +370,18 @@
     _whitespace = re.compile('\s+')
     _xml_declaration = re.compile('^<\?xml .*\?>\n')

-    def __init__(self, lxml=False):
-        if lxml and lxml_etree:
+    def __init__(self, use_lxml=False):
+        if use_lxml and lxml_etree:
             self.etree = lxml_etree
             self.modern_etree = True
             self.lxml_etree = True
         else:
-            if lxml and not lxml_etree:
- logger.warn('XML library reverted to use standard ElementTree '
-                            'because requested lxml is not installed.')
             self.etree = ET
             self.modern_etree = ET.VERSION >= '1.3'
             self.lxml_etree = False
+        if use_lxml and not lxml_etree:
+            logger.warn('XML library reverted to use standard ElementTree '
+                        'because lxml module is not installed.')

     def parse_xml(self, source, keep_clark_notation=False):
         """Parses the given XML file or string into an element structure.

==============================================================================
Revision: 9cca66a2fc0b
Branch:   default
Author:   Pekka Klärck
Date:     Thu May 29 10:22:37 2014 UTC
Log:      XML: Documented lxml support.

Update issue 1623
Documented lxml usage. Documenting new Evaluate Xpath keyword still todo.
http://code.google.com/p/robotframework/source/detail?r=9cca66a2fc0b

Modified:
 /src/robot/libraries/XML.py

=======================================
--- /src/robot/libraries/XML.py Thu May 29 08:17:10 2014 UTC
+++ /src/robot/libraries/XML.py Thu May 29 10:22:37 2014 UTC
@@ -37,7 +37,7 @@

As the name implies, `XML` is a test library for verifying contents of XML
     files. In practice it is a pretty thin wrapper on top of Python's
- [http://docs.python.org/library/xml.etree.elementtree.html|ElementTree XML API]. + [https://docs.python.org/2/library/xml.etree.elementtree.html| ElementTree XML API].

     The library has the following main usages:

@@ -51,6 +51,13 @@
     - Modifying XML and saving it (e.g. `Set Element Text`, `Add Element`
       and `Save XML`).

+    By default this library uses ElementTree module for parsing XML, but it
+    can be configured to use [http://lxml.de|lxml] instead when `importing`
+    the library. The main benefit of using lxml is that it supports richer
+    xpath syntax than the standard ElementTree. It also enables using
+    `Evaluate Xpath` keyword and preserves possible namespace prefixes when
+    saving XML. The lxml support is new in Robot Framework 2.8.5.
+
     == Table of contents ==

     - `Parsing XML`
@@ -131,14 +138,18 @@
ElementTree, and thus also this library, supports finding elements using xpath expressions. ElementTree does not, however, support the full xpath syntax, and what is supported depends on its version. ElementTree 1.3 that
-    is distributed with Python and Jython 2.7 supports richer syntax than
-    versions distributed with earlier Python interpreters.
+ is distributed with Python 2.7 supports richer syntax than earlier versions.

     The supported xpath syntax is explained below and
     [http://effbot.org/zone/element-xpath.htm|ElementTree documentation]
     provides more details. In the examples `${XML}` refers to the same XML
     structure as in the earlier example.

+    If lxml support is enabled when `importing` the library, the whole
+    [http://www.w3.org/TR/xpath/|xpath 1.0 standard] is supported.
+    That includes everything listed below but also lot of other useful
+    constructs.
+
     == Tag names ==

     When just a single tag name is used, xpath matches all direct child
@@ -275,8 +286,8 @@

     = Handling XML namespaces =

-    ElementTree handles possible namespaces in XML documents by adding the
-    namespace URI to tag names in so called Clark Notation. That is
+ ElementTree and lxml handle possible namespaces in XML documents by adding
+    the namespace URI to tag names in so called Clark Notation. That is
     inconvenient especially with xpaths, and by default this library strips
those namespaces away and moves them to `xmlns` attribute instead. That can be avoided by passing `keep_clark_notation` argument to `Parse XML` keyword.
@@ -286,7 +297,7 @@

If an XML document has namespaces, ElementTree adds namespace information
     to tag names in [http://www.jclark.com/xml/xmlns.htm|Clark Notation]
- (e.g. `{http://ns.uri}tag` and removes original `xmlns` attributes. This + (e.g. `{http://ns.uri}tag`) and removes original `xmlns` attributes. This
     is done both with default namespaces and with namespaces with a prefix.
     How it works in practice is illustrated by the following example, where
     `${NS}` variable contains this XML document:
@@ -346,7 +357,13 @@
     | </stylesheet>

Also this output is semantically same as the original. If the original XML
-    had only default namespaces, the output would also looks identical.
+    had only default namespaces, the output would also look identical.
+
+    == Namespaces with lxml ==
+
+    Namespaces are handled the same way also if lxml mode is enabled when
+ `importing` the library. The only difference is that lxml stores information
+    about namespace prefixes and thus they are preserved if XML is saved.

     == Attribute namespaces ==

@@ -371,6 +388,21 @@
     _xml_declaration = re.compile('^<\?xml .*\?>\n')

     def __init__(self, use_lxml=False):
+        """Import library with optionally lxml mode enabled.
+
+        By default this library uses Python's standard
+ [https://docs.python.org/2/library/xml.etree.elementtree.html| ElementTree]
+        module for parsing XML. If `use_lxml` argument is given any true
+        value (e.g. any non-empty string), the library will use
+        [http://lxml.de|lxml] instead. See `introduction` for benefits
+        provided by lxml.
+
+ Using lxml requires that the lxml module is installed on the system. + If lxml mode is enabled but the module is not installed, this library + will emit a warning and revert back to using the standard ElementTree.
+
+        The support for lxml is new in Robot Framework 2.8.5.
+        """
         if use_lxml and lxml_etree:
             self.etree = lxml_etree
             self.modern_etree = True

--

--- You received this message because you are subscribed to the Google Groups "robotframework-commit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to robotframework-commit+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to