2 new revisions:

Revision: 08a3ee2bf460
Author:   Pekka Klärck
Date:     Tue Aug 28 05:55:11 2012
Log:      TestCheckerLibrary.py: little cleanup. lot more would be nice...
http://code.google.com/p/robotframework/source/detail?r=08a3ee2bf460

Revision: 356183ef0b08
Author:   Pekka Klärck
Date:     Tue Aug 28 06:49:28 2012
Log: atests: Removed custom XML libs and took new XML library into use....
http://code.google.com/p/robotframework/source/detail?r=356183ef0b08

==============================================================================
Revision: 08a3ee2bf460
Author:   Pekka Klärck
Date:     Tue Aug 28 05:55:11 2012
Log:      TestCheckerLibrary.py: little cleanup. lot more would be nice...
http://code.google.com/p/robotframework/source/detail?r=08a3ee2bf460

Modified:
 /atest/resources/TestCheckerLibrary.py

=======================================
--- /atest/resources/TestCheckerLibrary.py      Mon Jun 18 04:44:21 2012
+++ /atest/resources/TestCheckerLibrary.py      Tue Aug 28 05:55:11 2012
@@ -41,15 +41,13 @@
         tests = self.get_tests_from_suite(suite, name)
         if len(tests) == 1:
             return tests[0]
-        elif len(tests) == 0:
-            err = "No test '%s' found from suite '%s'"
-        else:
-            err = "More than one test '%s' found from suite '%s'"
+        err = "No test '%s' found from suite '%s'" if not tests \
+            else "More than one test '%s' found from suite '%s'"
         raise RuntimeError(err % (name, suite.name))

     def get_tests_from_suite(self, suite, name=None):
-        tests = [ test for test in suite.tests
-                  if name is None or utils.eq(test.name, name) ]
+        tests = [test for test in suite.tests
+                 if name is None or utils.eq(test.name, name)]
         for subsuite in suite.suites:
             tests.extend(self.get_tests_from_suite(subsuite, name))
         return tests
@@ -58,14 +56,12 @@
         suites = self.get_suites_from_suite(suite, name)
         if len(suites) == 1:
             return suites[0]
-        elif len(suites) == 0:
-            err = "No suite '%s' found from suite '%s'"
-        else:
-            err = "More than one suite '%s' found from suite '%s'"
+        err = "No suite '%s' found from suite '%s'" if not suites \
+            else "More than one suite '%s' found from suite '%s'"
         raise RuntimeError(err % (name, suite.name))

     def get_suites_from_suite(self, suite, name):
-        suites = utils.eq(suite.name, name) and [ suite ] or []
+        suites = [suite] if utils.eq(suite.name, name) else []
         for subsuite in suite.suites:
             suites.extend(self.get_suites_from_suite(subsuite, name))
         return suites
@@ -85,7 +81,6 @@
             test.exp_status = status
         if message is not None:
             test.exp_message = message
-
         if test.exp_status != test.status:
             if test.exp_status == 'PASS':
                 msg = "Test was expected to PASS but it FAILED. "
@@ -94,7 +89,6 @@
                 msg = "Test was expected to FAIL but it PASSED. "
                 msg += "Expected message:\n" + test.exp_message
             raise AssertionError(msg)
-
         if test.exp_message == test.message:
             return
         if test.exp_message.startswith('REGEXP:'):
@@ -107,18 +101,16 @@
                 raise RuntimeError("Empty 'STARTS:' is not allowed")
             if test.message.startswith(start):
                 return
-
         raise AssertionError("Wrong message\n\n"
                              "Expected:\n%s\n\nActual:\n%s\n"
                              % (test.exp_message, test.message))

-
     def check_suite_contains_tests(self, suite, *expected_names):
- actual_tests = [ test for test in self.get_tests_from_suite(suite) ]
+        actual_tests = [test for test in self.get_tests_from_suite(suite)]
         tests_msg  = """
 Expected tests : %s
 Actual tests   : %s"""  % (str(list(expected_names)), str(actual_tests))
- expected_names = [ utils.normalize(name) for name in expected_names ]
+        expected_names = [utils.normalize(name) for name in expected_names]
         if len(actual_tests) != len(expected_names):
             raise AssertionError("Wrong number of tests." + tests_msg)
         for test in actual_tests:
@@ -129,8 +121,7 @@
             else:
raise AssertionError("Test '%s' was not expected to be run.%s"
                                      % (test.name, tests_msg))
-        if len(expected_names) != 0:
-            raise Exception("Bug in test library")
+        assert not expected_names

     def should_contain_tests(self, suite, *test_names):
         self.check_suite_contains_tests(suite, *test_names)
@@ -153,7 +144,7 @@
         for act, exp in zip(test.tags, tag_names):
             utils.eq(act, exp)

-    def  should_contain_keywords(self, item, *kw_names):
+    def should_contain_keywords(self, item, *kw_names):
         actual_names =  [kw.name for kw in item.keywords]
utils.asserts.assert_equals(len(actual_names), len(kw_names), 'Wrong number of keywords')
         for act, exp in zip(actual_names, kw_names):

==============================================================================
Revision: 356183ef0b08
Author:   Pekka Klärck
Date:     Tue Aug 28 06:49:28 2012
Log:      atests: Removed custom XML libs and took new XML library into use.

Update issue 1196
Now acceptance tests use the new library instead of custom solutions. Taking the new lib into use was pretty trivial.
http://code.google.com/p/robotframework/source/detail?r=356183ef0b08

Deleted:
 /atest/robot/libdoc/XmlLibrary.py
Modified:
 /atest/resources/TestCheckerLibrary.py
 /atest/resources/atest_resource.txt
 /atest/robot/libdoc/libdoc_resource.txt
 /atest/robot/output/statistics.txt
 /atest/robot/output/statistics_with_rebot.txt
 /atest/robot/output/test_criticality.txt
 /atest/robot/output/xunit.txt
 /atest/robot/rebot/combine.txt
 /atest/robot/rebot/xunit.txt
 /atest/robot/tags/critical_tags_with_rebot.txt

=======================================
--- /atest/robot/libdoc/XmlLibrary.py   Tue Mar  6 00:46:30 2012
+++ /dev/null
@@ -1,59 +0,0 @@
-#  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.
-
-from __future__ import with_statement
-
-from robot.utils import ET, ETSource
-from robot.libraries.BuiltIn import BuiltIn
-
-
-def should_be_equal(text, expected):
-    BuiltIn().should_be_equal(text, expected)
-
-def should_match(text, pattern):
-    BuiltIn().should_match(text, pattern)
-
-
-class XmlLibrary(object):
-
-    def parse_xml(self, source):
-        with ETSource(source) as source:
-            return ET.parse(source).getroot()
-
-    def get_element(self, node, path=None):
-        return node.find(path) if path else node
-
-    def get_elements(self, node, path):
-        return node.findall(path)
-
-    def get_element_text(self, node, path):
-        return self.get_element(node, path).text or ''
-
-    def get_elements_texts(self, node, path):
-        return [elem.text or '' for elem in self.get_elements(node, path)]
-
-    def element_text_should_be(self, node, expected, path=None):
-        should_be_equal(self.get_element_text(node, path), expected)
-
-    def element_text_should_match(self, node, pattern, path=None):
-        should_match(self.get_element_text(node, path), pattern)
-
-    def get_attribute(self, node, name, path=None):
-        return self.get_element(node, path).get(name)
-
-    def attribute_should_match(self, node, name, pattern, path=None):
-        should_match(self.get_attribute(node, name, path), pattern)
-
-    def attribute_should_be(self, node, name, expected, path=None):
-        should_be_equal(self.get_attribute(node, name, path), expected)
=======================================
--- /atest/resources/TestCheckerLibrary.py      Tue Aug 28 05:55:11 2012
+++ /atest/resources/TestCheckerLibrary.py      Tue Aug 28 06:49:28 2012
@@ -150,16 +150,6 @@
         for act, exp in zip(actual_names, kw_names):
             utils.eq(act, exp)

-    def get_node(self, file_path, node_path=None):
-        dom =  utils.ET.parse(file_path)
-        # This search path is broken on certain python versions
-        if node_path == '/':
-            return dom.getroot()
-        return dom.find(node_path) if node_path else dom
-
-    def get_nodes(self, file_path, node_path):
-        return utils.ET.parse(file_path).findall(node_path)
-

 def process_suite(suite):
     for subsuite in suite.suites:
=======================================
--- /atest/resources/atest_resource.txt Tue Aug 14 03:43:54 2012
+++ /atest/resources/atest_resource.txt Tue Aug 28 06:49:28 2012
@@ -5,6 +5,7 @@
 Library         String
 Library         TestCheckerLibrary
 Library         TestHelper
+Library         XML
 Variables       atest_variables.py

 *** Variables ***
@@ -273,7 +274,7 @@
 Get Stat Nodes
     [Arguments]  ${type}  ${output}=
     ${output} =  Set Variable If  "${output}"  ${output}  ${OUTFILE}
-    ${nodes} =  Get Nodes  ${output}  statistics/${type}/stat
+    ${nodes} =  Get Elements  ${output}  statistics/${type}/stat
     [Return]  ${nodes}

 Get Tag Stat Nodes
=======================================
--- /atest/robot/libdoc/libdoc_resource.txt     Thu May 31 02:09:09 2012
+++ /atest/robot/libdoc/libdoc_resource.txt     Tue Aug 28 06:49:28 2012
@@ -1,7 +1,6 @@
 *** Settings ***
 Resource          atest_resource.txt
 Library           LibDocLib.py    ${INTERPRETER}
-Library           XmlLibrary.py
 Library           OperatingSystem

 *** Variables ***
@@ -33,7 +32,7 @@

 Name Should Be
     [Arguments]    ${name}
-    Attribute Should Be    ${LIBDOC}    name    ${name}
+    Element Attribute Should Be    ${LIBDOC}    name    ${name}

 Doc Should Start With
     [Arguments]    @{doc}
@@ -55,7 +54,7 @@

 Type Should Be
     [Arguments]    ${type}
-    Attribute Should Be    ${LIBDOC}    type    ${type}
+    Element Attribute Should Be    ${LIBDOC}    type    ${type}

 Scope Should Be
     [Arguments]    ${scope}
@@ -66,7 +65,7 @@
     Element Text Should Be    ${LIBDOC}    ${namedargs}    namedargs

 Generated Should Be Defined
-    Attribute Should Match    ${LIBDOC}    generated    *
+    Element Attribute Should Match    ${LIBDOC}    generated    *

 Should Have No Init
     ${inits} =    Get Elements    ${LIBDOC}    init
@@ -84,7 +83,7 @@
 Keyword Name Should Be
     [Arguments]    ${index}   ${name}
     ${elements}=   Get Elements    ${LIBDOC}    kw
-    Attribute Should Be    ${elements[${index}]}    name    ${name}
+    Element Attribute Should Be    ${elements[${index}]}    name    ${name}

 Keyword Arguments Should Be
     [Arguments]    ${index}    @{expected}
=======================================
--- /atest/robot/output/statistics.txt  Wed Jun 27 15:34:50 2012
+++ /atest/robot/output/statistics.txt  Tue Aug 28 06:49:28 2012
@@ -12,13 +12,13 @@
     Should Match Regexp  ${output}  ${exp}

 Total statistics should be Correct
-    ${stats} =  Get Node  ${OUTFILE}  statistics/total
+    ${stats} =  Get Element  ${OUTFILE}  statistics/total
     ${crit}  ${total} =  Call Method  ${stats}  findall  stat
     Node Information Should Be Correct  ${crit}  Critical Tests  5  1
     Node Information Should Be Correct  ${total}  All Tests  9  1

 Tag statistics should be Correct
-    ${stats} =  Get Node  ${OUTFILE}  statistics/tag
+    ${stats} =  Get Element  ${OUTFILE}  statistics/tag
Tag Node Information Should Be Correct ${stats.getchildren()[0]} t1 5 1 info=critical links=my title:http://url.to:::title:url Tag Node Information Should Be Correct ${stats.getchildren()[2]} d1 AND d2 1 0 info=combined Tag Node Information Should Be Correct ${stats.getchildren()[3]} f1 NOT t1 4 0 info=combined
@@ -28,11 +28,11 @@
Tag Node Information Should Be Correct ${stats.getchildren()[7]} sub3 2 0

 Combined Tag Statistics Name Can Be Given
-    ${stats} =  Get Node  ${OUTFILE}  statistics/tag
+    ${stats} =  Get Element  ${OUTFILE}  statistics/tag
Tag Node Information Should Be Correct ${stats.getchildren()[1]} combined tag with new name 1 0 combined

 Suite statistics should be Correct
-    ${stats} =  Get Node  ${OUTFILE}  statistics/suite
+    ${stats} =  Get Element  ${OUTFILE}  statistics/suite
Suite Node Information Should Be Correct ${stats.getchildren()[0]} Suites 9 1 Suite Node Information Should Be Correct ${stats.getchildren()[1]} Suites.Fourth 0 1 Suite Node Information Should Be Correct ${stats.getchildren()[2]} Suites.Subsuites 2 0
=======================================
--- /atest/robot/output/statistics_with_rebot.txt       Wed Jun 27 15:34:50 2012
+++ /atest/robot/output/statistics_with_rebot.txt       Tue Aug 28 06:49:28 2012
@@ -12,13 +12,13 @@
     Matches Regexp  ${output}  ${exp}

 Total statistics should be Correct
-    ${stats} =  Get Node  ${OUTFILE}  statistics/total
+    ${stats} =  Get Element  ${OUTFILE}  statistics/total
     ${crit}  ${total} =  Call Method  ${stats}  findall  stat
     Node Information Should Be Correct  ${crit}  Critical Tests  5  1
     Node Information Should Be Correct  ${total}  All Tests  9  1

 Tag statistics should be Correct
-    ${stats} =  Get Node  ${OUTFILE}  statistics/tag
+    ${stats} =  Get Element  ${OUTFILE}  statistics/tag
Tag Node Information Should Be Correct ${stats.getchildren()[0]} t1 5 1 critical Tag Node Information Should Be Correct ${stats.getchildren()[1]} d1 AND d2 1 0 combined Tag Node Information Should Be Correct ${stats.getchildren()[2]} d1 1 0
@@ -27,7 +27,7 @@
Tag Node Information Should Be Correct ${stats.getchildren()[5]} sub3 2 0

 Suite statistics should be Correct
-    ${stats} =  Get Node  ${OUTFILE}  statistics/suite
+    ${stats} =  Get Element  ${OUTFILE}  statistics/suite
Node Information Should Be Correct ${stats.getchildren()[0]} Suites 9 1 Node Information Should Be Correct ${stats.getchildren()[1]} Suites.Fourth 0 1 Node Information Should Be Correct ${stats.getchildren()[2]} Suites.Subsuites 2 0
=======================================
--- /atest/robot/output/test_criticality.txt    Mon Jun 18 00:57:01 2012
+++ /atest/robot/output/test_criticality.txt    Tue Aug 28 06:49:28 2012
@@ -11,7 +11,7 @@
 *** Keywords ***
 Run some tests and parse XML
     Run Tests   --noncritical fail  misc${/}pass_and_fail.txt
-    ${SUITE}=  Get Node  ${OUTFILE}  suite
+    ${SUITE}=  Get Element  ${OUTFILE}  suite
     Set Suite Variable  ${SUITE}

 Check Test Criticality in Output
=======================================
--- /atest/robot/output/xunit.txt       Mon Jun 25 07:41:07 2012
+++ /atest/robot/output/xunit.txt       Tue Aug 28 06:49:28 2012
@@ -17,7 +17,7 @@
     File Should Exist  ${OUTDIR}/log.html

 File Structure Is Correct
-    ${root} =  Get XUnit Node  /
+    ${root} =  Get XUnit Node  .
     Should Be Equal  ${root.tag}  testsuite
     ${tests} =  Get XUnit Nodes  testcase
     Length Should Be  ${tests}  8
@@ -53,10 +53,10 @@
 *** Keywords ***
 Get XUnit Node
     [Arguments]  ${path}
-    ${node} =  Get Node  ${OUTDIR}/xunit.xml  ${path}
+    ${node} =  Get Element  ${OUTDIR}/xunit.xml  ${path}
     [Return]  ${node}

 Get XUnit Nodes
     [Arguments]  ${path}
-    ${nodes} =  Get Nodes  ${OUTDIR}/xunit.xml  ${path}
+    ${nodes} =  Get Elements  ${OUTDIR}/xunit.xml  ${path}
     [Return]  ${nodes}
=======================================
--- /atest/robot/rebot/combine.txt      Mon Jun 18 00:57:01 2012
+++ /atest/robot/rebot/combine.txt      Tue Aug 28 06:49:28 2012
@@ -133,11 +133,11 @@
     Should Be Equal  ${SUITE4.suites[1].suites[1].elapsedtime}  ${MILLIS2}

Elapsed Time Should Be Written To Output When Start And End Time Are Not Known
-    ${combined} =  Get Node  ${COMB OUT 1}  suite/status
+    ${combined} =  Get Element  ${COMB OUT 1}  suite/status
     Should Be Equal  ${combined.attrib['starttime']}  N/A
     Should Be Equal  ${combined.attrib['endtime']}  N/A
     Should Be True   ${combined.attrib['elapsedtime']} >= 0
-    ${originals} =  Get Nodes  ${COMB OUT 1}  suite/suite/status
+    ${originals} =  Get Elements  ${COMB OUT 1}  suite/suite/status
     Should Not Be Equal  ${originals[0].attrib['starttime']}  N/A
     Should Not Be Equal  ${originals[0].attrib['endtime']}  N/A
     Should Not Be True   ${originals[0].attrib.has_key('elapsedtime')}
=======================================
--- /atest/robot/rebot/xunit.txt        Mon Jun 25 07:41:07 2012
+++ /atest/robot/rebot/xunit.txt        Tue Aug 28 06:49:28 2012
@@ -26,12 +26,12 @@
     Check Stdout Contains  XUnit
     File Should Exist  ${OUTDIR}/xunit.xml
     File Should Exist  ${OUTDIR}/log.html
-    ${root} =  Get Node  ${OUTDIR}/xunit.xml  /
+    ${root} =  Parse XML  ${OUTDIR}/xunit.xml
     Should Be Equal  ${root.tag}  testsuite
-    ${tests} =  Get Nodes  ${OUTDIR}/xunit.xml  testcase
+    ${tests} =  Get Elements  ${root}  testcase
     Length Should Be  ${tests}  18
Should Be Equal ${tests[7].attrib['name']} Ünïcödë Tëst änd Këywörd Nämës
-    ${failures} =  Get Nodes  ${OUTDIR}/xunit.xml  testcase/failure
+    ${failures} =  Get Elements  ${root}  testcase/failure
     Length Should Be  ${failures}  5
     Should Be Equal  ${failures[0].attrib['message']}  ${MESSAGES}

=======================================
--- /atest/robot/tags/critical_tags_with_rebot.txt      Mon Jun 18 00:57:01 2012
+++ /atest/robot/tags/critical_tags_with_rebot.txt      Tue Aug 28 06:49:28 2012
@@ -47,7 +47,7 @@
 Test Criticality
     [Arguments]  ${options}  ${crit 1}  ${crit 2}
Run Rebot ${options} --escape star:STAR --escape quest:QUEST --report rebot-report.html ${INPUT FILE}
-    ${tests} =  Get Nodes  ${OUT FILE}  suite/test
+    ${tests} =  Get Elements  ${OUT FILE}  suite/test
     Test Status And Criticality Should Be  ${tests[0]}  PASS  ${crit 1}
     Test Status And Criticality Should Be  ${tests[1]}  FAIL  ${crit 2}

Reply via email to