4 new revisions:

Revision: 8398c1958fd9
Author:   Pekka Klärck
Date:     Mon Dec 19 07:11:42 2011
Log: test line separators in output files -- currently fails on windows but...
http://code.google.com/p/robotframework/source/detail?r=8398c1958fd9

Revision: 1418821c00e1
Author:   Pekka Klärck
Date:     Mon Dec 19 07:23:59 2011
Log:      random cleanup
http://code.google.com/p/robotframework/source/detail?r=1418821c00e1

Revision: e622ce0a33c1
Author:   Pekka Klärck
Date:     Mon Dec 19 07:26:27 2011
Log: Open files in 'w' mode, not 'wb', to enable automatic '\n' -> '\r\n' t...
http://code.google.com/p/robotframework/source/detail?r=e622ce0a33c1

Revision: 9735450a7206
Author:   Pekka Klärck
Date:     Mon Dec 19 07:44:27 2011
Log: syslog (a.k.a. filelogger): 1) handle invalid log level correctly, 2) ...
http://code.google.com/p/robotframework/source/detail?r=9735450a7206

==============================================================================
Revision: 8398c1958fd9
Author:   Pekka Klärck
Date:     Mon Dec 19 07:11:42 2011
Log: test line separators in output files -- currently fails on windows but ought to pass on linux
http://code.google.com/p/robotframework/source/detail?r=8398c1958fd9

Added:
 /atest/robot/output/outputs_have_correct_line_separators.txt

=======================================
--- /dev/null
+++ /atest/robot/output/outputs_have_correct_line_separators.txt Mon Dec 19 07:11:42 2011
@@ -0,0 +1,28 @@
+*** Settings ***
+Default Tags    regression  pybot  jybot
+Resource        atest_resource.txt
+Library         OutputVerifierLibrary.py
+
+*** Variables ***
+${REBOT INFILE}    ${TEMPDIR}/robot-rebot-infile.xml
+
+*** Test Cases ***
+
+Outputs generated at runtime should have correct line separators
+ Run Tests -l log -r report -x xunit -b debug -L DEBUG misc/pass_and_fail.html
+    Outputs Should Have Correct Line Separators
+    ...    output.xml    log.html    report.html    xunit.xml    debug.txt
+
+Outputs generated with rebot should have correct line separators
+    Copy File    ${OUTFILE}    ${REBOT INFILE}
+    Run Rebot    -l log -r report -x xunit -L DEBUG    ${REBOT INFILE}
+    Outputs Should Have Correct Line Separators
+    ...    output.xml    log.html    report.html    xunit.xml
+    [Teardown]    Remove File    ${REBOT INFILE}
+
+*** Keywords ***
+
+Outputs Should Have Correct Line Separators
+    [Arguments]    @{outputs}
+    :FOR    ${name}    IN    @{outputs}
+    \    Output Should Have Correct Line Separators    ${OUTDIR}${/}${name}

==============================================================================
Revision: 1418821c00e1
Author:   Pekka Klärck
Date:     Mon Dec 19 07:23:59 2011
Log:      random cleanup
http://code.google.com/p/robotframework/source/detail?r=1418821c00e1

Modified:
 /src/robot/output/loggerhelper.py
 /src/robot/utils/jyxmlwriter.py

=======================================
--- /src/robot/output/loggerhelper.py   Wed Dec 14 03:26:44 2011
+++ /src/robot/output/loggerhelper.py   Mon Dec 19 07:23:59 2011
@@ -67,11 +67,11 @@
     def __init__(self, message, level='INFO', html=False, timestamp=None):
         message = self._normalize_message(message)
         level, html = self._get_level_and_html(level, html)
-        timestamp = self._get_timestamp(timestamp)
+        timestamp = timestamp or utils.get_timestamp()
         BaseMessage.__init__(self, message, level, html, timestamp)

     def _normalize_message(self, msg):
-        if not isinstance(msg, basestring):
+        if not isinstance(msg, unicode):
             msg = utils.unic(msg)
         return msg.replace('\r\n', '\n')

@@ -83,12 +83,6 @@
             raise DataError("Invalid log level '%s'" % level)
         return level, html

-    def _get_timestamp(self, timestamp):
-        if timestamp:
-            return timestamp
-        return utils.get_timestamp(daysep='', daytimesep=' ',
-                                   timesep=':', millissep='.')
-

 class IsLogged:

=======================================
--- /src/robot/utils/jyxmlwriter.py     Wed Dec 14 01:41:20 2011
+++ /src/robot/utils/jyxmlwriter.py     Mon Dec 19 07:23:59 2011
@@ -17,7 +17,7 @@
 from javax.xml.transform.stream import StreamResult
 from org.xml.sax.helpers import AttributesImpl

-from abstractxmlwriter import AbstractXmlWriter
+from .abstractxmlwriter import AbstractXmlWriter


 class XmlWriter(AbstractXmlWriter):

==============================================================================
Revision: e622ce0a33c1
Author:   Pekka Klärck
Date:     Mon Dec 19 07:26:27 2011
Log: Open files in 'w' mode, not 'wb', to enable automatic '\n' -> '\r\n' transformation on Windows. Binary mode isn't needed when we encode content to UTF-8 but unfortunately codecs.open forces that mode.
http://code.google.com/p/robotframework/source/detail?r=e622ce0a33c1

Modified:
 /src/robot/output/debugfile.py
 /src/robot/utils/pyxmlwriter.py

=======================================
--- /src/robot/output/debugfile.py      Sun Feb  6 01:24:10 2011
+++ /src/robot/output/debugfile.py      Mon Dec 19 07:26:27 2011
@@ -12,11 +12,10 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.

-
 from robot import utils

-from logger import LOGGER
-from loggerhelper import IsLogged
+from .logger import LOGGER
+from .loggerhelper import IsLogged


 def DebugFile(path):
@@ -24,23 +23,25 @@
         LOGGER.info('No debug file')
         return None
     try:
-        LOGGER.info('Debug file: %s' % path)
-        return _DebugFileWriter(path)
-    except:
+        outfile = open(path, 'w')
+    except EnvironmentError, err:
LOGGER.error("Opening debug file '%s' failed and writing to debug file " - "is disabled. Error: %s" % (path, utils.get_error_message()))
+                     "is disabled. Error: %s" % (path, err.strerror))
         return None
+    else:
+        LOGGER.info('Debug file: %s' % path)
+        return _DebugFileWriter(outfile)


 class _DebugFileWriter:
-
     _separators = {'SUITE': '=', 'TEST': '-', 'KW': '~'}
-
-    def __init__(self, path):
+    _setup_or_teardown = ('setup', 'teardown')
+
+    def __init__(self, outfile):
         self._indent = 0
         self._kw_level = 0
         self._separator_written_last = False
-        self._file = open(path, 'wb')
+        self._outfile = outfile
         self._is_logged = IsLogged('DEBUG')

     def start_suite(self, suite):
@@ -53,7 +54,7 @@
         self._end('SUITE', suite.longname, suite.elapsedtime)
         self._separator('SUITE')
         if self._indent == 0:
-            LOGGER.output_file('Debug', self._file.name)
+            LOGGER.output_file('Debug', self._outfile.name)
             self.close()

     def start_test(self, test):
@@ -81,11 +82,11 @@
             self._write(msg.message)

     def close(self):
-        if not self._file.closed:
-            self._file.close()
+        if not self._outfile.closed:
+            self._outfile.close()

     def _get_kw_type(self, kw):
-        if kw.type in ['setup','teardown']:
+        if kw.type in self._setup_or_teardown:
             return kw.type.upper()
         return 'KW'

@@ -99,11 +100,10 @@
self._write('+%s END %s: %s (%s)' % ('-'*self._indent, type_, name, elapsed))

     def _separator(self, type_):
-        self._write(self._separators[type_] * 78, True)
+        self._write(self._separators[type_] * 78, separator=True)

     def _write(self, text, separator=False):
-        if self._separator_written_last and separator:
-            return
-        self._file.write(utils.unic(text).encode('UTF-8').rstrip() + '\n')
-        self._file.flush()
-        self._separator_written_last = separator
+        if not (separator and self._separator_written_last):
+            self._outfile.write(text.encode('UTF-8').rstrip() + '\n')
+            self._outfile.flush()
+            self._separator_written_last = separator
=======================================
--- /src/robot/utils/pyxmlwriter.py     Fri Dec  2 03:27:16 2011
+++ /src/robot/utils/pyxmlwriter.py     Mon Dec 19 07:26:27 2011
@@ -16,7 +16,7 @@
 from xml.sax.saxutils import XMLGenerator
 from xml.sax.xmlreader import AttributesImpl

-from abstractxmlwriter import AbstractXmlWriter
+from .abstractxmlwriter import AbstractXmlWriter


 class XmlWriter(AbstractXmlWriter):
@@ -29,9 +29,8 @@
         self.closed = False

     def _create_output(self, output):
-        if isinstance(output, basestring):
-            return open(output, 'wb')
-        return output
+        return open(output, 'w') \
+            if isinstance(output, basestring) else output

     def _start(self, name, attrs):
         self._writer.startElement(name, AttributesImpl(attrs))

==============================================================================
Revision: 9735450a7206
Author:   Pekka Klärck
Date:     Mon Dec 19 07:44:27 2011
Log: syslog (a.k.a. filelogger): 1) handle invalid log level correctly, 2) cleaner implementation for using correct line seps on windoes (simply use 'w' mode instead of 'wb')
http://code.google.com/p/robotframework/source/detail?r=9735450a7206

Modified:
 /atest/robot/cli/runner/syslog.txt
 /atest/robot/output/outputs_have_correct_line_separators.txt
 /src/robot/output/filelogger.py
 /src/robot/output/logger.py
 /utest/output/test_filelogger.py

=======================================
--- /atest/robot/cli/runner/syslog.txt  Fri Apr 15 06:02:50 2011
+++ /atest/robot/cli/runner/syslog.txt  Mon Dec 19 07:44:27 2011
@@ -29,7 +29,7 @@
 Invalid syslog file
     Set Environment Variable  ROBOT_SYSLOG_FILE  ${CLI OUTDIR}
     ${output} =  Run Some Tests
- Should Contain ${output} Opening syslog file '${CLI OUTDIR}' failed: IOError: + Should Start With ${output} [ ERROR ] Opening syslog file '${CLI OUTDIR}' failed:

 Setting syslog Level
Set Environment Variable ROBOT_SYSLOG_FILE ${CLI OUTDIR}${/}syslog.txt
@@ -48,5 +48,5 @@
 Invalid syslog level
     Set Environment Variable  ROBOT_SYSLOG_LEVEL  invalid
     ${output} =  Run Some Tests
- Should Contain ${output} Opening syslog file '${CLI OUTDIR}${/}syslog.txt' failed: Invalid log level 'invalid' + Should Start With ${output} [ ERROR ] Opening syslog file '${CLI OUTDIR}${/}syslog.txt' failed: Invalid log level 'invalid'
     [Teardown]  Delete Environment Variable  ROBOT_SYSLOG_LEVEL
=======================================
--- /atest/robot/output/outputs_have_correct_line_separators.txt Mon Dec 19 07:11:42 2011 +++ /atest/robot/output/outputs_have_correct_line_separators.txt Mon Dec 19 07:44:27 2011
@@ -24,5 +24,6 @@

 Outputs Should Have Correct Line Separators
     [Arguments]    @{outputs}
-    :FOR    ${name}    IN    @{outputs}
-    \    Output Should Have Correct Line Separators    ${OUTDIR}${/}${name}
+    :FOR    ${name}    IN    @{outputs}  ${SYSLOG FILE}
+    \    ${path} =    Join Path    ${OUTDIR}    ${name}
+    \    Output Should Have Correct Line Separators    ${path}
=======================================
--- /src/robot/output/filelogger.py     Mon Dec 19 04:55:53 2011
+++ /src/robot/output/filelogger.py     Mon Dec 19 07:44:27 2011
@@ -12,8 +12,7 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.

-import os
-import codecs
+from robot.errors import DataError

 from .loggerhelper import AbstractLogger

@@ -25,13 +24,16 @@
         self._writer = self._get_writer(path)  # unit test hook

     def _get_writer(self, path):
-        return codecs.open(path, 'wb', encoding='UTF-8')
+        try:
+            return open(path, 'w')
+        except EnvironmentError, err:
+            raise DataError(err.strerror)

     def message(self, msg):
         if self._is_logged(msg.level) and not self._writer.closed:
             entry = '%s | %s | %s\n' % (msg.timestamp, msg.level.ljust(5),
                                         msg.message)
-            self._writer.write(entry.replace('\n', os.linesep))
+            self._writer.write(entry.encode('UTF-8'))

     def start_suite(self, suite):
         self.info("Started test suite '%s'" % suite.name)
=======================================
--- /src/robot/output/logger.py Mon Dec 19 04:55:53 2011
+++ /src/robot/output/logger.py Mon Dec 19 07:44:27 2011
@@ -14,7 +14,7 @@

 import os

-from robot import utils
+from robot.errors import DataError

 from .filelogger import FileLogger
 from .loggerhelper import AbstractLogger, AbstractLoggerProxy
@@ -83,8 +83,8 @@
             return
         try:
             logger = FileLogger(path, level)
-        except EnvironmentError, err:
- self.error("Opening syslog file '%s' failed: %s" % (path, err.strerror))
+        except DataError, err:
+ self.error("Opening syslog file '%s' failed: %s" % (path, unicode(err)))
         else:
             self.register_logger(logger)

=======================================
--- /utest/output/test_filelogger.py    Fri Apr 15 07:25:49 2011
+++ /utest/output/test_filelogger.py    Mon Dec 19 07:44:27 2011
@@ -1,5 +1,4 @@
 import unittest
-import os
 from StringIO import StringIO

 from robot import utils
@@ -42,7 +41,6 @@
         self._verify_message('20060613 08:37:42.123 | DEBUG | msg\n')

     def _verify_message(self, expected):
-        expected = expected.replace('\n', os.linesep)
         assert_equals(self.logger._writer.getvalue(), expected)

 if __name__ == "__main__":

Reply via email to