3 new revisions:
Revision: 8714ad55049a
Author: Pekka Klärck
Date: Thu Dec 1 12:28:32 2011
Log: Simplified XML reading by keeping intermediate results in
ElementStack
http://code.google.com/p/robotframework/source/detail?r=8714ad55049a
Revision: 1d64eb8e57cf
Author: Pekka Klärck
Date: Thu Dec 1 12:38:59 2011
Log: Moved ResultFromXML and ExecutionResultBuilder to executionresult
modu...
http://code.google.com/p/robotframework/source/detail?r=1d64eb8e57cf
Revision: f0914cacea61
Author: Pekka Klärck
Date: Thu Dec 1 12:40:32 2011
Log: Renamed ResultFromXML -> ResultFromXml to follow our naming
convention...
http://code.google.com/p/robotframework/source/detail?r=f0914cacea61
==============================================================================
Revision: 8714ad55049a
Author: Pekka Klärck
Date: Thu Dec 1 12:28:32 2011
Log: Simplified XML reading by keeping intermediate results in
ElementStack
http://code.google.com/p/robotframework/source/detail?r=8714ad55049a
Modified:
/src/robot/result/builders.py
=======================================
--- /src/robot/result/builders.py Thu Dec 1 11:23:43 2011
+++ /src/robot/result/builders.py Thu Dec 1 12:28:32 2011
@@ -41,32 +41,35 @@
if isinstance(source, XmlSource) else XmlSource(source)
def build(self, result):
- elements = ElementStack(RootElement())
+ elements = ElementStack(result, RootElement())
with self._source as source:
for action, elem in ET.iterparse(source,
events=('start', 'end')):
- result = getattr(elements, action)(elem, result)
+ getattr(elements, action)(elem)
SuiteTeardownFailureHandler(result.generator).visit_suite(result.suite)
return result
class ElementStack(object):
- def __init__(self, root_element):
+ def __init__(self, result, root_element):
+ self._results = [result]
self._elements = [root_element]
@property
- def _current(self):
+ def _result(self):
+ return self._results[-1]
+
+ @property
+ def _element(self):
return self._elements[-1]
- def start(self, elem, result):
- self._elements.append(self._current.child_element(elem.tag))
- return self._current.start(elem, result)
-
- def end(self, elem, result):
- result = self._current.end(elem, result)
+ def start(self, elem):
+ self._elements.append(self._element.child_element(elem.tag))
+ self._results.append(self._element.start(elem, self._result))
+
+ def end(self, elem):
+ self._elements.pop().end(elem, self._results.pop())
elem.clear()
- self._elements.pop()
- return result
class _Element(object):
@@ -76,7 +79,7 @@
return result
def end(self, elem, result):
- return result
+ pass
def child_element(self, tag):
# TODO: replace _children() list with dict
@@ -89,12 +92,6 @@
return []
-class _CollectionElement(_Element):
-
- def end(self, elem, result):
- return result.parent
-
-
class RootElement(_Element):
def _children(self):
@@ -112,7 +109,7 @@
return [RootSuiteElement, StatisticsElement, ErrorsElement]
-class SuiteElement(_CollectionElement):
+class SuiteElement(_Element):
tag = 'suite'
def start(self, elem, result):
@@ -127,16 +124,12 @@
class RootSuiteElement(SuiteElement):
def start(self, elem, result):
- self._result = result
- self._result.suite.name = elem.get('name')
- self._result.suite.source = elem.get('source')
- return self._result.suite
-
- def end(self, elem, result):
- return self._result
-
-
-class TestCaseElement(_CollectionElement):
+ result.suite.name = elem.get('name')
+ result.suite.source = elem.get('source')
+ return result.suite
+
+
+class TestCaseElement(_Element):
tag = 'test'
def start(self, elem, result):
@@ -147,7 +140,7 @@
return [KeywordElement, TagsElement, DocElement, TestStatusElement]
-class KeywordElement(_CollectionElement):
+class KeywordElement(_Element):
tag = 'kw'
def start(self, elem, result):
@@ -168,7 +161,6 @@
linkable = elem.get('linkable', 'no') == 'yes'
result.messages.create(elem.text or '', elem.get('level'),
html, elem.get('timestamp'), linkable)
- return result
class _StatusElement(_Element):
@@ -190,7 +182,6 @@
def end(self, elem, result):
self._set_status(elem, result)
self._set_times(elem, result)
- return result
class SuiteStatusElement(_StatusElement):
@@ -198,7 +189,6 @@
def end(self, elem, result):
self._set_message(elem, result)
self._set_times(elem, result)
- return result
class TestStatusElement(_StatusElement):
@@ -207,7 +197,6 @@
self._set_status(elem, result)
self._set_message(elem, result)
self._set_times(elem, result)
- return result
class DocElement(_Element):
@@ -215,7 +204,6 @@
def end(self, elem, result):
result.doc = elem.text or ''
- return result
class MetadataElement(_Element):
@@ -233,7 +221,6 @@
def end(self, elem, result):
result.metadata[elem.get('name')] = elem.text or ''
- return result
class TagsElement(_Element):
@@ -248,7 +235,6 @@
def end(self, elem, result):
result.tags.add(elem.text or '')
- return result
class ArgumentsElement(_Element):
@@ -263,18 +249,13 @@
def end(self, elem, result):
result.args.append(elem.text or '')
- return result
class ErrorsElement(_Element):
tag = 'errors'
def start(self, elem, result):
- self._result = result
- return self._result.errors
-
- def end(self, elem, result):
- return self._result
+ return result.errors
def _children(self):
return [MessageElement]
==============================================================================
Revision: 1d64eb8e57cf
Author: Pekka Klärck
Date: Thu Dec 1 12:38:59 2011
Log: Moved ResultFromXML and ExecutionResultBuilder to executionresult
module. Much better home for them.
http://code.google.com/p/robotframework/source/detail?r=1d64eb8e57cf
Modified:
/atest/resources/TestCheckerLibrary.py
/src/robot/output/__init__.py
/src/robot/reporting/resultwriter.py
/src/robot/result/__init__.py
/src/robot/result/builders.py
/src/robot/result/executionresult.py
/utest/result/test_resultbuilder.py
/utest/result/test_resultserializer.py
/utest/result/test_visitor.py
=======================================
--- /atest/resources/TestCheckerLibrary.py Thu Dec 1 11:23:43 2011
+++ /atest/resources/TestCheckerLibrary.py Thu Dec 1 12:38:59 2011
@@ -2,7 +2,7 @@
import re
from robot import utils
-from robot.result.builders import ExecutionResultBuilder, ExecutionResult
+from robot.result.executionresult import ExecutionResultBuilder,
ExecutionResult
from robot.result import TestSuite, TestCase, Keyword
from robot.libraries.BuiltIn import BuiltIn
=======================================
--- /src/robot/output/__init__.py Mon Nov 28 01:08:54 2011
+++ /src/robot/output/__init__.py Thu Dec 1 12:38:59 2011
@@ -19,8 +19,6 @@
from loggerhelper import LEVELS, Message
from readers import process_output, process_outputs
-from robot.reporting.resultwriter import ResultFromXML
-
# Hooks to output. Set by Output.
# Use only if no other way available (e.g. from BuiltIn library)
=======================================
--- /src/robot/reporting/resultwriter.py Thu Dec 1 06:23:25 2011
+++ /src/robot/reporting/resultwriter.py Thu Dec 1 12:38:59 2011
@@ -14,7 +14,7 @@
from robot.errors import DATA_ERROR
-from robot.result.builders import ResultFromXML
+from robot.result import ResultFromXML
from robot.result.combiningvisitor import CombiningVisitor,
KeywordRemovingVisitor
from robot.result.datamodel import JSModelCreator
=======================================
--- /src/robot/result/__init__.py Mon Nov 28 06:07:42 2011
+++ /src/robot/result/__init__.py Thu Dec 1 12:38:59 2011
@@ -16,4 +16,5 @@
from testcase import TestCase
from keyword import Keyword
from message import Message
-
+from executionresult import ResultFromXML
+
=======================================
--- /src/robot/result/builders.py Thu Dec 1 12:28:32 2011
+++ /src/robot/result/builders.py Thu Dec 1 12:38:59 2011
@@ -15,38 +15,6 @@
from __future__ import with_statement
from robot.errors import DataError
-from robot.utils import ET, XmlSource
-
-from .executionresult import ExecutionResult, CombinedExecutionResult
-from .suiteteardownfailed import SuiteTeardownFailureHandler
-
-
-def ResultFromXML(*sources):
- if not sources:
- raise DataError('One or more data source needed.')
- if len(sources) > 1:
- return CombinedExecutionResult(*[ResultFromXML(src) for src in
sources])
- source = XmlSource(sources[0])
- try:
- return ExecutionResultBuilder(source).build(ExecutionResult())
- except DataError, err:
- raise DataError("Reading XML source '%s' failed: %s"
- % (unicode(source), unicode(err)))
-
-
-class ExecutionResultBuilder(object):
-
- def __init__(self, source):
- self._source = source \
- if isinstance(source, XmlSource) else XmlSource(source)
-
- def build(self, result):
- elements = ElementStack(result, RootElement())
- with self._source as source:
- for action, elem in ET.iterparse(source,
events=('start', 'end')):
- getattr(elements, action)(elem)
-
SuiteTeardownFailureHandler(result.generator).visit_suite(result.suite)
- return result
class ElementStack(object):
=======================================
--- /src/robot/result/executionresult.py Thu Dec 1 11:23:43 2011
+++ /src/robot/result/executionresult.py Thu Dec 1 12:38:59 2011
@@ -12,11 +12,43 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+from robot.errors import DataError
from robot.model.statistics import Statistics
-
+from robot.utils import ET, XmlSource
+
+from .builders import ElementStack, RootElement
+from .executionerrors import ExecutionErrors
from .configurer import SuiteConfigurer
+from .suiteteardownfailed import SuiteTeardownFailureHandler
from .testsuite import TestSuite
-from .executionerrors import ExecutionErrors
+
+
+def ResultFromXML(*sources):
+ if not sources:
+ raise DataError('One or more data source needed.')
+ if len(sources) > 1:
+ return CombinedExecutionResult(*[ResultFromXML(src) for src in
sources])
+ source = XmlSource(sources[0])
+ try:
+ return ExecutionResultBuilder(source).build(ExecutionResult())
+ except DataError, err:
+ raise DataError("Reading XML source '%s' failed: %s"
+ % (unicode(source), unicode(err)))
+
+
+class ExecutionResultBuilder(object):
+
+ def __init__(self, source):
+ self._source = source \
+ if isinstance(source, XmlSource) else XmlSource(source)
+
+ def build(self, result):
+ elements = ElementStack(result, RootElement())
+ with self._source as source:
+ for action, elem in ET.iterparse(source,
events=('start', 'end')):
+ getattr(elements, action)(elem)
+
SuiteTeardownFailureHandler(result.generator).visit_suite(result.suite)
+ return result
class ExecutionResult(object):
=======================================
--- /utest/result/test_resultbuilder.py Thu Dec 1 04:11:16 2011
+++ /utest/result/test_resultbuilder.py Thu Dec 1 12:38:59 2011
@@ -5,7 +5,7 @@
from StringIO import StringIO
from robot import DataError
-from robot.result.builders import ResultFromXML
+from robot.result import ResultFromXML
from robot.utils.asserts import assert_equals, assert_true, assert_raises
def _read_file(name):
=======================================
--- /utest/result/test_resultserializer.py Tue Nov 29 23:05:03 2011
+++ /utest/result/test_resultserializer.py Thu Dec 1 12:38:59 2011
@@ -4,7 +4,7 @@
from xml.etree.ElementTree import XML
from xml.etree.ElementTree import tostring
-from robot.result.builders import ResultFromXML
+from robot.result import ResultFromXML
from robot.result.serializer import RebotXMLWriter
from robot.utils.pyxmlwriter import XmlWriter
from robot.utils.asserts import assert_equals
=======================================
--- /utest/result/test_visitor.py Sat Nov 5 02:54:53 2011
+++ /utest/result/test_visitor.py Thu Dec 1 12:38:59 2011
@@ -1,7 +1,7 @@
import unittest
from os.path import dirname, join
-from robot.result.builders import ResultFromXML
+from robot.result import ResultFromXML
from robot.result.visitor import SuiteVisitor
==============================================================================
Revision: f0914cacea61
Author: Pekka Klärck
Date: Thu Dec 1 12:40:32 2011
Log: Renamed ResultFromXML -> ResultFromXml to follow our naming
conventions.
http://code.google.com/p/robotframework/source/detail?r=f0914cacea61
Modified:
/src/robot/output/__init__.py
/src/robot/reporting/resultwriter.py
/src/robot/result/__init__.py
/src/robot/result/executionresult.py
/utest/result/test_resultbuilder.py
/utest/result/test_resultserializer.py
/utest/result/test_visitor.py
/utest/webcontent/spec/data/create_jsdata_for_specs.py
=======================================
--- /src/robot/output/__init__.py Thu Dec 1 12:38:59 2011
+++ /src/robot/output/__init__.py Thu Dec 1 12:40:32 2011
@@ -41,7 +41,7 @@
if path is None:
path = outpath
suite.set_status()
- testoutput = ResultFromXML(suite, errors)
+ testoutput = ResultFromXml(suite, errors)
testoutput.serialize_output(path)
suite.write_to_file = write_to_file
=======================================
--- /src/robot/reporting/resultwriter.py Thu Dec 1 12:38:59 2011
+++ /src/robot/reporting/resultwriter.py Thu Dec 1 12:40:32 2011
@@ -14,7 +14,7 @@
from robot.errors import DATA_ERROR
-from robot.result import ResultFromXML
+from robot.result import ResultFromXml
from robot.result.combiningvisitor import CombiningVisitor,
KeywordRemovingVisitor
from robot.result.datamodel import JSModelCreator
@@ -69,7 +69,7 @@
@property
def model(self):
if self._model is None:
- self._model = ResultFromXML(*self._data_sources)
+ self._model = ResultFromXml(*self._data_sources)
self._model.configure(self._settings.status_rc,
self._settings.suite_config,
self._settings.statistics_config)
=======================================
--- /src/robot/result/__init__.py Thu Dec 1 12:38:59 2011
+++ /src/robot/result/__init__.py Thu Dec 1 12:40:32 2011
@@ -16,5 +16,5 @@
from testcase import TestCase
from keyword import Keyword
from message import Message
-from executionresult import ResultFromXML
-
+from executionresult import ResultFromXml
+
=======================================
--- /src/robot/result/executionresult.py Thu Dec 1 12:38:59 2011
+++ /src/robot/result/executionresult.py Thu Dec 1 12:40:32 2011
@@ -23,11 +23,11 @@
from .testsuite import TestSuite
-def ResultFromXML(*sources):
+def ResultFromXml(*sources):
if not sources:
raise DataError('One or more data source needed.')
if len(sources) > 1:
- return CombinedExecutionResult(*[ResultFromXML(src) for src in
sources])
+ return CombinedExecutionResult(*[ResultFromXml(src) for src in
sources])
source = XmlSource(sources[0])
try:
return ExecutionResultBuilder(source).build(ExecutionResult())
=======================================
--- /utest/result/test_resultbuilder.py Thu Dec 1 12:38:59 2011
+++ /utest/result/test_resultbuilder.py Thu Dec 1 12:40:32 2011
@@ -5,7 +5,7 @@
from StringIO import StringIO
from robot import DataError
-from robot.result import ResultFromXML
+from robot.result import ResultFromXml
from robot.utils.asserts import assert_equals, assert_true, assert_raises
def _read_file(name):
@@ -20,7 +20,7 @@
class TestBuildingSuiteExecutionResult(unittest.TestCase):
def setUp(self):
- result = ResultFromXML(StringIO(GOLDEN_XML))
+ result = ResultFromXml(StringIO(GOLDEN_XML))
self._suite = result.suite
self._test = self._suite.tests[0]
self._keyword = self._test.keywords[0]
@@ -91,7 +91,7 @@
class TestCombiningSuites(unittest.TestCase):
def setUp(self):
- self.result = ResultFromXML(StringIO(GOLDEN_XML),
StringIO(GOLDEN_XML))
+ self.result = ResultFromXml(StringIO(GOLDEN_XML),
StringIO(GOLDEN_XML))
def test_name(self):
assert_equals(self.result.suite.name, 'Normal & Normal')
@@ -110,7 +110,7 @@
</suite>
</robot>
"""
- suite = ResultFromXML(StringIO(xml)).suite
+ suite = ResultFromXml(StringIO(xml)).suite
assert_equals(suite.name, 'foo')
assert_equals(suite.suites[0].name, 'bar')
assert_equals(suite.longname, 'foo')
@@ -128,7 +128,7 @@
</suite>
</robot>
"""
- test = ResultFromXML(StringIO(xml)).suite.tests[0]
+ test = ResultFromXml(StringIO(xml)).suite.tests[0]
assert_equals(test.message, 'Failure message')
assert_equals(test.status, 'FAIL')
assert_equals(test.longname, 'foo.test')
@@ -141,28 +141,28 @@
</suite>
</robot>
"""
- suite = ResultFromXML(StringIO(xml)).suite
+ suite = ResultFromXml(StringIO(xml)).suite
assert_equals(suite.message, 'Setup failed')
def test_unknown_elements_cause_an_error(self):
- assert_raises(DataError, ResultFromXML, StringIO('<some_tag/>'))
+ assert_raises(DataError, ResultFromXml, StringIO('<some_tag/>'))
class TestSuiteTeardownFailed(unittest.TestCase):
def test_passed_test(self):
- tc = ResultFromXML(StringIO(SUITE_TEARDOWN_FAILED)).suite.tests[0]
+ tc = ResultFromXml(StringIO(SUITE_TEARDOWN_FAILED)).suite.tests[0]
assert_equals(tc.status, 'FAIL')
assert_equals(tc.message, 'Teardown of the parent suite failed.')
def test_failed_test(self):
- tc = ResultFromXML(StringIO(SUITE_TEARDOWN_FAILED)).suite.tests[1]
+ tc = ResultFromXml(StringIO(SUITE_TEARDOWN_FAILED)).suite.tests[1]
assert_equals(tc.status, 'FAIL')
assert_equals(tc.message, 'Message\n\nAlso teardown of the parent
suite failed.')
def test_already_processed(self):
inp =
SUITE_TEARDOWN_FAILED.replace('generator="Robot', 'generator="Rebot')
- tc1, tc2 = ResultFromXML(StringIO(inp)).suite.tests
+ tc1, tc2 = ResultFromXml(StringIO(inp)).suite.tests
assert_equals(tc1.status, 'PASS')
assert_equals(tc1.message, '')
assert_equals(tc2.status, 'FAIL')
@@ -182,7 +182,7 @@
</suite>
</robot>
""".strip()
- result = ResultFromXML(xml)
+ result = ResultFromXml(xml)
if __name__ == '__main__':
unittest.main()
=======================================
--- /utest/result/test_resultserializer.py Thu Dec 1 12:38:59 2011
+++ /utest/result/test_resultserializer.py Thu Dec 1 12:40:32 2011
@@ -4,7 +4,7 @@
from xml.etree.ElementTree import XML
from xml.etree.ElementTree import tostring
-from robot.result import ResultFromXML
+from robot.result import ResultFromXml
from robot.result.serializer import RebotXMLWriter
from robot.utils.pyxmlwriter import XmlWriter
from robot.utils.asserts import assert_equals
@@ -73,7 +73,7 @@
def test_single_result_serialization(self):
output = StringIO()
-
ResultFromXML(StringIO(GOLDEN_XML)).visit(self._create_writer(output))
+
ResultFromXml(StringIO(GOLDEN_XML)).visit(self._create_writer(output))
self._assert_xml_content(self._xml_lines(output.getvalue()),
self._xml_lines(GOLDEN_XML))
@@ -87,7 +87,7 @@
def test_combining_results(self):
output = StringIO()
- result = ResultFromXML(StringIO(GOLDEN_XML), StringIO(GOLDEN_XML))
+ result = ResultFromXml(StringIO(GOLDEN_XML), StringIO(GOLDEN_XML))
result.visit(self._create_writer(output))
self._assert_xml_content(self._xml_lines(output.getvalue()),
self._xml_lines(GOLDEN_XML_TWICE))
=======================================
--- /utest/result/test_visitor.py Thu Dec 1 12:38:59 2011
+++ /utest/result/test_visitor.py Thu Dec 1 12:40:32 2011
@@ -1,11 +1,11 @@
import unittest
from os.path import dirname, join
-from robot.result import ResultFromXML
+from robot.result import ResultFromXml
from robot.result.visitor import SuiteVisitor
-RESULT = ResultFromXML(join(dirname(__file__), 'golden.xml'))
+RESULT = ResultFromXml(join(dirname(__file__), 'golden.xml'))
class TestVisitingSuite(unittest.TestCase):
=======================================
--- /utest/webcontent/spec/data/create_jsdata_for_specs.py Thu Dec 1
04:42:12 2011
+++ /utest/webcontent/spec/data/create_jsdata_for_specs.py Thu Dec 1
12:40:32 2011
@@ -27,7 +27,7 @@
def create_jsdata(outxml, target, split_log):
- result = robot.result.builders.ResultFromXML(outxml)
+ result = robot.result.builders.ResultFromXml(outxml)
visitor = JSModelCreator(split_log=split_log)
result.visit(visitor)
model = DataModelWriter(visitor.datamodel,
visitor._context.split_results)