Revision: 76477958ad1d
Author:   Pekka Klärck
Date:     Sat Jun 30 16:02:25 2012
Log: ETSource: Don't use DataError because it has special meaning when running tests and XML library nowadays uses ETSource.

Wrapping parsing errors to DataError was accidentally removed already
in previous commit. This commit removes raising DataError when source
file doesn't exist. Also code using ETSource was updated and related
tests fixed.
http://code.google.com/p/robotframework/source/detail?r=76477958ad1d

Modified:
 /atest/robot/cli/rebot/invalid_usage.txt
 /src/robot/result/resultbuilder.py
 /src/robot/utils/etreewrapper.py
 /utest/api/test_run_and_rebot.py
 /utest/utils/test_etreesource.py

=======================================
--- /atest/robot/cli/rebot/invalid_usage.txt    Tue Dec 13 15:10:56 2011
+++ /atest/robot/cli/rebot/invalid_usage.txt    Sat Jun 30 16:02:25 2012
@@ -13,7 +13,7 @@
     Rebot should fail  ${EMPTY}  Expected at least 1 argument, got 0.

 Non-Existing Input
- Rebot should fail nönéx.xml Reading XML source 'nönéx\\.xml' failed: Source file 'nönéx\\.xml' does not exist.* + Rebot should fail nönéx.xml Reading XML source 'nönéx\\.xml' failed: .*

 Non-XML Input
     Create File  ${MYOUTDIR}/invalid.txt  Hello, world
=======================================
--- /src/robot/result/resultbuilder.py  Mon Mar 12 14:04:55 2012
+++ /src/robot/result/resultbuilder.py  Sat Jun 30 16:02:25 2012
@@ -15,7 +15,7 @@
 from __future__ import with_statement

 from robot.errors import DataError
-from robot.utils import ET, ETSource
+from robot.utils import ET, ETSource, get_error_message

 from .suiteteardownfailed import SuiteTeardownFailureHandler
 from .xmlelementhandlers import XmlElementHandler
@@ -37,9 +37,11 @@
     source = ETSource(sources[0])
     try:
         return ExecutionResultBuilder(source).build(Result(sources[0]))
-    except DataError, err:
-        raise DataError("Reading XML source '%s' failed: %s"
-                        % (unicode(source), unicode(err)))
+    except IOError, err:
+        error = err.strerror
+    except:
+        error = get_error_message()
+ raise DataError("Reading XML source '%s' failed: %s" % (unicode(source), error))


 class ExecutionResultBuilder(object):
=======================================
--- /src/robot/utils/etreewrapper.py    Sat Jun 30 13:13:45 2012
+++ /src/robot/utils/etreewrapper.py    Sat Jun 30 16:02:25 2012
@@ -16,8 +16,6 @@
 import sys
 from StringIO import StringIO

-from robot.errors import DataError
-

 _IRONPYTHON = sys.platform == 'cli'
 _ERROR = 'No valid ElementTree XML parser module found'
@@ -55,16 +53,12 @@
         self._opened = None

     def __enter__(self):
-        if self._source_file_does_not_exist():
- raise DataError("Source file '%s' does not exist." % self._source)
         self._opened = self._open_source_if_necessary()
         return self._opened or self._source

     def __exit__(self, exc_type, exc_value, exc_trace):
         if self._opened:
             self._opened.close()
-        if exc_type is None or exc_type is DataError:
-            return False

     def __str__(self):
         if self._source_is_file_name():
@@ -73,9 +67,6 @@
             return self._source.name
         return '<in-memory file>'

-    def _source_file_does_not_exist(self):
- return self._source_is_file_name() and not os.path.isfile(self._source)
-
     def _source_is_file_name(self):
         return isinstance(self._source, basestring) \
                 and not self._source.lstrip().startswith('<')
=======================================
--- /utest/api/test_run_and_rebot.py    Mon Jun 18 00:57:01 2012
+++ /utest/api/test_run_and_rebot.py    Sat Jun 30 16:02:25 2012
@@ -140,7 +140,7 @@
         assert_equals(rebot(self.nonex), 252)
         assert_equals(rebot(self.data, outputdir=TEMP), 1)
         self._assert_outputs(stdout=[(LOG, 1)],
- stderr=[('[ ERROR ]', 1), (self.nonex, 2), ('--help', 1)]) + stderr=[('[ ERROR ]', 1), (self.nonex, 1), ('--help', 1)])

     def test_custom_stdout(self):
         stdout = StringIO()
=======================================
--- /utest/utils/test_etreesource.py    Wed Jun 27 06:01:03 2012
+++ /utest/utils/test_etreesource.py    Sat Jun 30 16:02:25 2012
@@ -53,7 +53,7 @@
         def use(src):
             with src:
                 pass
-        assert_raises(DataError, use, ETSource('nonex.xml'))
+        assert_raises(IOError, use, ETSource('nonex.xml'))

     def test_non_ascii_string_repr(self):
         self._verify_string_representation(ETSource(u'\xe4'), u'\xe4')

Reply via email to