4 new revisions:

Revision: 183a915be497
Author:   Pekka Klärck
Date:     Tue Dec 13 13:52:33 2011
Log: XmlWriter: IOError also from Jython version when given file is invalid...
http://code.google.com/p/robotframework/source/detail?r=183a915be497

Revision: 59d062002c70
Author:   Pekka Klärck
Date:     Tue Dec 13 14:09:27 2011
Log:      Fixed, with tests, handling invalid xunit files.
http://code.google.com/p/robotframework/source/detail?r=59d062002c70

Revision: 1f2fd0280cd2
Author:   Pekka Klärck
Date:     Tue Dec 13 14:31:37 2011
Log:      Fixed, with tests, handling invalid output file with rebot.
http://code.google.com/p/robotframework/source/detail?r=1f2fd0280cd2

Revision: 3b56be2aff44
Author:   Pekka Klärck
Date:     Tue Dec 13 14:32:42 2011
Log:      Automated merge with https://code.google.com/p/robotframework/
http://code.google.com/p/robotframework/source/detail?r=3b56be2aff44

==============================================================================
Revision: 183a915be497
Author:   Pekka Klärck
Date:     Tue Dec 13 13:52:33 2011
Log: XmlWriter: IOError also from Jython version when given file is invalid.
http://code.google.com/p/robotframework/source/detail?r=183a915be497

Modified:
 /src/robot/utils/jyxmlwriter.py
 /utest/utils/test_xmlwriter.py

=======================================
--- /src/robot/utils/jyxmlwriter.py     Fri Dec  2 03:27:16 2011
+++ /src/robot/utils/jyxmlwriter.py     Tue Dec 13 13:52:33 2011
@@ -12,7 +12,7 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.

-from java.io import FileOutputStream
+from java.io import FileOutputStream, FileNotFoundException
 from javax.xml.transform.sax import SAXTransformerFactory
 from javax.xml.transform.stream import StreamResult
 from org.xml.sax.helpers import AttributesImpl
@@ -32,9 +32,12 @@
         self.closed = False

     def _create_output(self, output):
-        if isinstance(output, basestring):
+        if not isinstance(output, basestring):
+            return output
+        try:
             return FileOutputStream(output)
-        return output
+        except FileNotFoundException, err:
+            raise IOError(None, err.getMessage(), output)

     def _start(self, name, attrs):
self._writer.startElement('', '', name, self._get_attrs_impl(attrs))
=======================================
--- /utest/utils/test_xmlwriter.py      Tue Nov 29 06:29:05 2011
+++ /utest/utils/test_xmlwriter.py      Tue Dec 13 13:52:33 2011
@@ -18,12 +18,11 @@
         os.remove(PATH)

     def test_write_element_in_pieces(self):
-        self.writer.start('name', {'attr': 'value'}, True)
+        self.writer.start('name', {'attr': 'value'})
         self.writer.content('Some content here!!')
-        self.writer.end('name', True)
+        self.writer.end('name')
         self.writer.close()
-        self._verify_node(None, 'name', '\nSome content here!!',
-                          {'attr': 'value'})
+ self._verify_node(None, 'name', '\nSome content here!!', {'attr': 'value'})

     def test_calling_content_multiple_times(self):
         self.writer.start(u'robot-log', newline=False)
@@ -61,12 +60,10 @@
     def test_newline_insertion(self):
         self.writer.start('root')
         self.writer.start('suite', {'type': 'directory_suite'})
-        self.writer.element('test', attributes={'name': 'my_test'},
-                                  newline=False)
+ self.writer.element('test', attributes={'name': 'my_test'}, newline=False)
         self.writer.element('test', attributes={'name': 'my_2nd_test'})
         self.writer.end('suite', False)
-        self.writer.start('suite', {'name': 'another suite'},
-                                  newline=False)
+ self.writer.start('suite', {'name': 'another suite'}, newline=False)
         self.writer.content('Suite 2 content')
         self.writer.end('suite')
         self.writer.end('root')
@@ -102,7 +99,6 @@
         self._verify_node(root.find('f'), 'f',
                          u'Hyv\u00E4\u00E4 \u00FC\u00F6t\u00E4')

-
     def test_content_with_entities(self):
         self.writer.element(u'robot-log', 'Me, Myself & I > you')
         self.writer.close()
@@ -115,6 +111,9 @@
         assert_equals(self.writer._escape(u'\x1b[31m'), '[31m')
         assert_equals(self.writer._escape(u'\x00'), '')

+    def test_ioerror_when_file_is_invalid(self):
+        assert_raises(IOError, utils.XmlWriter, os.path.dirname(__file__))
+
     def _verify_node(self, node, name, text=None, attrs={}):
         if node is None:
             node = utils.ET.parse(PATH).getroot()

==============================================================================
Revision: 59d062002c70
Author:   Pekka Klärck
Date:     Tue Dec 13 14:09:27 2011
Log:      Fixed, with tests, handling invalid xunit files.
http://code.google.com/p/robotframework/source/detail?r=59d062002c70

Modified:
 /atest/robot/output/xunit.txt
 /atest/robot/rebot/xunit.txt
 /src/robot/reporting/builders.py

=======================================
--- /atest/robot/output/xunit.txt       Wed Jun 15 00:11:08 2011
+++ /atest/robot/output/xunit.txt       Tue Dec 13 14:09:27 2011
@@ -6,18 +6,29 @@

 *** Variables ***
 ${TESTDATA}  misc/pass_and_fail.html
+${INVALID}   ${TEMPDIR}${/}ïnvälïd-ẍünïẗ.xml

 *** Test Cases ***
-No Xunit Option Given
+No XUnit Option Given
     Run Tests  ${EMPTY}  ${TESTDATA}
     Check Stdout Does Not Contain  XUnit

-Xunit Option Given
-    Run Tests  -x xunit.xml  ${TESTDATA}
+XUnit Option Given
+    Run Tests  -x xunit.xml -l log.html ${TESTDATA}
     Check Stdout Contains  XUnit
     Stderr should be empty
-    Should Exist  ${OUTDIR}/xunit.xml
+    File Should Exist  ${OUTDIR}/xunit.xml
+    File Should Exist  ${OUTDIR}/log.html
     ${dom} =  Get Dom
     Check Root Element Is Test Suite  ${dom}
     Check Element Count  ${dom}  testcase  2
     Check Element Count  ${dom}  failure  1
+
+Invalid XUnit File
+    Create Directory  ${INVALID}
+    Run Tests  --XUnitFile ${INVALID} -l log.html  ${TESTDATA}
+    File Should Not Exist  ${INVALID}
+    File Should Exist  ${OUTDIR}/log.html
+    Check Stderr Matches Regexp
+ ... \\[ ERROR \\] Opening XUnit result file '${INVALID}' failed: .*directory.*
+
=======================================
--- /atest/robot/rebot/xunit.txt        Tue Dec  7 04:00:09 2010
+++ /atest/robot/rebot/xunit.txt        Tue Dec 13 14:09:27 2011
@@ -11,27 +11,39 @@
 ${TESTDATA_SUITES}  misc${/}suites
 ${MYOUTDIR}         ${TEMPDIR}${/}robot-test-xunit
 ${INPUT FILE}       ${TEMPDIR}${/}robot-test-xunit-file.xml
+${INVALID}          ${TEMPDIR}${/}ïnvälïd-ẍünïẗ.xml
+

 *** Test Cases ***
-No Xunit Option Given
+No XUnit Option Given
     Run Rebot  ${EMPTY}  ${INPUT FILE}
     Stderr Should Be Empty
     Check Stdout Does Not Contain  XUnit

-Xunit Option Given
-    Run Rebot  --xunitfile xunit.xml  ${INPUT FILE}
+XUnit Option Given
+    Run Rebot  --xunitfile xunit.xml --log log.html  ${INPUT FILE}
     Stderr Should Be Empty
     Check Stdout Contains  XUnit
-    Should Exist  ${OUTDIR}${/}xunit.xml
+    File Should Exist  ${OUTDIR}${/}xunit.xml
+    File Should Exist  ${OUTDIR}${/}log.html
     ${dom} =  Get Dom
     Check Root Element Is Test Suite  ${dom}
     Check Element Count  ${dom}  testcase  15
     Check Element Count  ${dom}  failure   1

+Invalid XUnit File
+    Create Directory  ${INVALID}
+    Run Rebot  -x ${INVALID} -l log.html  ${INPUT FILE}
+    File Should Not Exist  ${INVALID}
+    File Should Exist  ${OUTDIR}/log.html
+    Check Stderr Matches Regexp
+ ... \\[ ERROR \\] Opening XUnit result file '${INVALID}' failed: .*directory.*
+
 *** Keywords ***
 Create Input File
Create Output With Robot ${INPUT FILE} ${EMPTY} ${TESTDATA_TEST} ${TESTDATA_SUITES}
     Create Directory          ${MYOUTDIR}
+
 Remove Temps
     Remove Directory    ${MYOUTDIR}  recursive
     Remove File         ${INPUT FILE}
=======================================
--- /src/robot/reporting/builders.py    Tue Dec 13 06:57:42 2011
+++ /src/robot/reporting/builders.py    Tue Dec 13 14:09:27 2011
@@ -44,15 +44,15 @@
         self._model = model

     def build(self, path):
- writer = XUnitWriter(path) # TODO: handle (with atests) error in opening output file
         try:
+            writer = XUnitWriter(path)
+        except EnvironmentError, err:
+            LOGGER.error("Opening XUnit result file '%s' failed: %s"
+                         % (path, err.strerror))
+        else:
             self._model.visit(writer)
-        except:
-            raise DataError("Writing XUnit result file '%s' failed: %s" %
-                            (path, utils.get_error_message()))
-        finally:
             writer.close()
-        LOGGER.output_file('XUnit', path)
+            LOGGER.output_file('XUnit', path)


 class _HTMLFileBuilder(object):

==============================================================================
Revision: 1f2fd0280cd2
Author:   Pekka Klärck
Date:     Tue Dec 13 14:31:37 2011
Log:      Fixed, with tests, handling invalid output file with rebot.
http://code.google.com/p/robotframework/source/detail?r=1f2fd0280cd2

Modified:
 /atest/robot/cli/rebot/output_files.txt
 /src/robot/reporting/builders.py

=======================================
--- /atest/robot/cli/rebot/output_files.txt     Mon Jun 20 22:57:34 2011
+++ /atest/robot/cli/rebot/output_files.txt     Tue Dec 13 14:31:37 2011
@@ -4,6 +4,7 @@
 Test Template   Correct outputs should be created
 Resource        rebot_cli_resource.txt

+
 *** Test Cases ***
 Default outputs
     ${EMPTY}  log.html  report.html
@@ -24,7 +25,7 @@
--output xoutput --report xreport --log xlog xlog.html xoutput.xml xreport.html

 Outputs Into Different Directories
-    [Template]
+    [Template]  NONE
     Set Runners
Run ${REBOT} --outputdir ::invalid:: -o ${MYOUTDIR}${/}o${/}o.xml -r ${MYOUTDIR}${/}r${/}r.html -l ${MYOUTDIR}${/}l${/}l.html ${MYINPUT}
     Directory Should Contain  ${MYOUTDIR}${/}o  o.xml
@@ -32,6 +33,19 @@
     Directory Should Contain  ${MYOUTDIR}${/}l  l.html
     Directory Should Contain  ${MYOUTDIR}  l  o  r

+Non-writable Output File
+    [Template]  NONE
+    Set Runners
+    Create Directory  ${MYOUTDIR}/diréctöry.xml
+ ${output} = Run ${REBOT} -d ${MYOUTDIR} -o diréctöry.xml -r r.html -l l.html ${MYINPUT}
+    Directory Should Contain  ${MYOUTDIR}  diréctöry.xml  l.html  r.html
+    ${error}=  Catenate  SEPARATOR=\n
+ ... \\[ ERROR \\] Opening output file '.*diréctöry.xml' for writing failed: .*
+    ...  Log: .*
+    ...  Report: .*
+    Should Match Regexp  ${output}  ^${error}$
+
+
 *** Keywords ***
 Correct outputs should be created
     [Arguments]  ${arguments}  @{expected}
=======================================
--- /src/robot/reporting/builders.py    Tue Dec 13 14:09:27 2011
+++ /src/robot/reporting/builders.py    Tue Dec 13 14:31:37 2011
@@ -33,9 +33,13 @@
         self._model = model

     def build(self, path):
-        writer = RebotXMLWriter(path)
-        self._model.visit(writer)
-        LOGGER.output_file('Output', path)
+        try:
+            writer = RebotXMLWriter(path)
+        except DataError, err:
+            LOGGER.error(unicode(err))
+        else:
+            self._model.visit(writer)
+            LOGGER.output_file('Output', path)


 class XUnitBuilder(object):

==============================================================================
Revision: 3b56be2aff44
Author:   Pekka Klärck
Date:     Tue Dec 13 14:32:42 2011
Log:      Automated merge with https://code.google.com/p/robotframework/
http://code.google.com/p/robotframework/source/detail?r=3b56be2aff44


Reply via email to