3 new revisions:

Revision: b8bae8573411
Author:   Janne Härkönen <[email protected]>
Date:     Thu Nov  3 06:13:44 2011
Log:      builders: cleanup
http://code.google.com/p/robotframework/source/detail?r=b8bae8573411

Revision: c99de545f44a
Author:   Janne Härkönen <[email protected]>
Date:     Thu Nov  3 06:32:20 2011
Log:      builder: error on unknown XML element
http://code.google.com/p/robotframework/source/detail?r=c99de545f44a

Revision: ea58a7231140
Author:   Janne Härkönen <[email protected]>
Date:     Thu Nov  3 06:32:28 2011
Log:      Automated merge with https://code.google.com/p/robotframework/
http://code.google.com/p/robotframework/source/detail?r=ea58a7231140

==============================================================================
Revision: b8bae8573411
Author:   Janne Härkönen <[email protected]>
Date:     Thu Nov  3 06:13:44 2011
Log:      builders: cleanup
http://code.google.com/p/robotframework/source/detail?r=b8bae8573411

Modified:
 /src/robot/result/builders.py

=======================================
--- /src/robot/result/builders.py       Thu Nov  3 06:05:49 2011
+++ /src/robot/result/builders.py       Thu Nov  3 06:13:44 2011
@@ -23,18 +23,21 @@


 def ResultFromXML(*sources):
-    if len(sources) == 1:
-        source = sources[0]
-        _validate_source(source)
-        # TODO: can this be cleaned? Is raising DataError in public API ok?
-        try:
-            return ExecutionResultBuilder(source).build(ExecutionResult())
-        except:
-            raise DataError("Opening XML file '%s' failed: %s"
-                            % (source, utils.get_error_message()))
- return CombinedExecutionResult(*[ResultFromXML(src) for src in 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 = sources[0]
+    _validate_source(source)
+    # TODO: can this be cleaned? Is raising DataError in public API ok?
+    try:
+        return ExecutionResultBuilder(source).build(ExecutionResult())
+    except:
+        raise DataError("Opening XML file '%s' failed: %s"
+                        % (source, utils.get_error_message()))

 def _validate_source(source):
+    # TODO: add support for xml strings.
     if isinstance(source, basestring) and not os.path.isfile(source):
         raise DataError("Output file '%s' does not exist." % source)


==============================================================================
Revision: c99de545f44a
Author:   Janne Härkönen <[email protected]>
Date:     Thu Nov  3 06:32:20 2011
Log:      builder: error on unknown XML element
http://code.google.com/p/robotframework/source/detail?r=c99de545f44a

Modified:
 /src/robot/result/builders.py
 /utest/result/test_resultbuilder.py

=======================================
--- /src/robot/result/builders.py       Thu Nov  3 06:13:44 2011
+++ /src/robot/result/builders.py       Thu Nov  3 06:32:20 2011
@@ -29,9 +29,11 @@
return CombinedExecutionResult(*[ResultFromXML(src) for src in sources])
     source = sources[0]
     _validate_source(source)
-    # TODO: can this be cleaned? Is raising DataError in public API ok?
     try:
         return ExecutionResultBuilder(source).build(ExecutionResult())
+    # TODO: handle source in errors messages when it's a file object
+    except DataError:
+ raise DataError("File '%s' is not Robot Framework output file." % source)
     except:
         raise DataError("Opening XML file '%s' failed: %s"
                         % (source, utils.get_error_message()))
@@ -89,7 +91,7 @@
         for child_type in self._children():
             if child_type.tag == tag:
                 return child_type()
- return IgnoredElement() # TODO: Should this result in error instead?
+        raise DataError("Unexpected element '%s'" % tag)

     def _children(self):
         return []
@@ -115,8 +117,7 @@
         return result

     def _children(self):
-        # TODO: Should <statistics> be explicitly ignored?
-        return [RootSuiteElement, ErrorsElement]
+        return [RootSuiteElement, StatisticsElement, ErrorsElement]


 class SuiteElement(_CollectionElement):
@@ -293,5 +294,8 @@
         return [MessageElement]


-class IgnoredElement(_Element):
-    pass
+class StatisticsElement(_Element):
+    tag = 'statistics'
+
+    def child_element(self, tag):
+        return self
=======================================
--- /utest/result/test_resultbuilder.py Mon Oct 31 23:00:37 2011
+++ /utest/result/test_resultbuilder.py Thu Nov  3 06:32:20 2011
@@ -3,9 +3,10 @@
 from os.path import join, dirname
 import unittest
 from StringIO import StringIO
-
-from robot.result.builders import _Element, IgnoredElement, ResultFromXML
-from robot.utils.asserts import assert_equals, assert_true
+from robot import DataError
+
+from robot.result.builders import ResultFromXML
+from robot.utils.asserts import assert_equals, assert_true, assert_raises


 with open(join(dirname(__file__), 'golden.xml')) as f:
@@ -146,9 +147,8 @@
         suite = ResultFromXML(StringIO(xml)).suite
         assert_equals(suite.message, 'Setup failed')

-    def test_unknown_elements_are_ignored(self):
-        assert_true(isinstance(_Element().child_element('some_tag'),
-                               IgnoredElement))
+    def test_unknown_elements_cause_an_error(self):
+        assert_raises(DataError, ResultFromXML, StringIO('<some_tag/>'))


 class TestSuiteTeardownFailed(unittest.TestCase):

==============================================================================
Revision: ea58a7231140
Author:   Janne Härkönen <[email protected]>
Date:     Thu Nov  3 06:32:28 2011
Log:      Automated merge with https://code.google.com/p/robotframework/
http://code.google.com/p/robotframework/source/detail?r=ea58a7231140


Reply via email to