2 new revisions:

Revision: 5ed2e5773e7a
Author:   Pekka Klärck
Date:     Sun Jan 29 10:03:05 2012
Log:      updated rebot's outdated --MonitorColors documentation
http://code.google.com/p/robotframework/source/detail?r=5ed2e5773e7a

Revision: acdac2978028
Author:   Pekka Klärck
Date:     Sun Jan 29 10:35:23 2012
Log:      robot.run and robot.rebot: support capturing stdout and stderr...
http://code.google.com/p/robotframework/source/detail?r=acdac2978028

==============================================================================
Revision: 5ed2e5773e7a
Author:   Pekka Klärck
Date:     Sun Jan 29 10:03:05 2012
Log:      updated rebot's outdated --MonitorColors documentation
http://code.google.com/p/robotframework/source/detail?r=5ed2e5773e7a

Modified:
 /src/robot/rebot.py

=======================================
--- /src/robot/rebot.py Fri Jan 13 03:40:38 2012
+++ /src/robot/rebot.py Sun Jan 29 10:03:05 2012
@@ -178,11 +178,11 @@
                           of combined test suites together.
--nostatusrc Sets the return code to zero regardless of failures
                           in test cases. Error codes are returned normally.
- -C --monitorcolors on|off|force Using ANSI colors in console. Normally colors - work in unixes but not in Windows. Default is 'on'.
-                          'on'    - use colors in unixes but not in Windows
-                          'off'   - never use colors
-                          'force' - always use colors (also in Windows)
+ -C --monitorcolors auto|on|off  Use colors on console output or not.
+ auto: use colors when output not redirected (default)
+                          on: always use colors
+                          off: never use colors
+ Note that colors do not work with Jython on Windows. -E --escape what:with * Escape characters which are problematic in console.
                           'what' is the name of the character to escape and
                           'with' is the string to escape it with. Note that

==============================================================================
Revision: acdac2978028
Author:   Pekka Klärck
Date:     Sun Jan 29 10:35:23 2012
Log:      robot.run and robot.rebot: support capturing stdout and stderr

Update issue 59
Status: Started
This feature is now implemented and tested. Both run and rebot documentation
has also been updated but the relevant User Guide section still requires some
love.
http://code.google.com/p/robotframework/source/detail?r=acdac2978028

Modified:
 /src/robot/__init__.py
 /src/robot/conf/settings.py
 /src/robot/output/logger.py
 /utest/api/test_run_and_rebot.py

=======================================
--- /src/robot/__init__.py      Sun Jan 29 04:20:55 2012
+++ /src/robot/__init__.py      Sun Jan 29 10:35:23 2012
@@ -90,15 +90,19 @@
pybot/jybot from command line. Options are given as keywords arguments and
     their names are same as long command line options without hyphens.

-    Returns a return code similarly as when running on the command line.
+    To capture stdout and/or stderr streams, pass open file objects in as
+    keyword arguments `stdout` and `stderr`, respectively.
+
+ A return code is returned similarly as when running on the command line.

     Examples:
-    run('/path/to/tests.html')
-    run('/path/to/tests.html', '/path/to/tests2.html', log='mylog.html')
+    run('path/to/tests.html')
+    with open('stdout.txt', 'w') as stdout:
+        run('t1.txt', 't2.txt', report='r.html', log='NONE', stdout=stdout)

     Equivalent command line usage:
-    pybot /path/to/tests.html
-    pybot --log mylog.html /path/to/tests.html /path/to/tests2.html
+    pybot path/to/tests.html
+    pybot --report r.html --log NONE t1.txt t2.txt > stdout.txt
     """
     return _execute(_run, datasources, options)

@@ -106,8 +110,10 @@
     STOP_SIGNAL_MONITOR.start()
     settings = RobotSettings(options)
     pyloggingconf.initialize(settings['LogLevel'])
-    LOGGER.register_console_logger(settings['MonitorWidth'],
-                                   settings['MonitorColors'])
+    LOGGER.register_console_logger(width=settings['MonitorWidth'],
+                                   colors=settings['MonitorColors'],
+                                   stdout=settings['StdOut'],
+                                   stderr=settings['StdErr'])
     init_global_variables(settings)
     suite = TestSuite(datasources, settings)
     output = Output(settings)
@@ -128,21 +134,27 @@
     rebot from command line. Options are given as keywords arguments and
     their names are same as long command line options without hyphens.

-    Returns a return code similarly as when running on the command line.
+    To capture stdout and/or stderr streams, pass open file objects in as
+    keyword arguments `stdout` and `stderr`, respectively.
+
+ A return code is returned similarly as when running on the command line.

     Examples:
-    rebot('/path/to/output.xml')
- rebot('/path/out1.xml', '/path/out2.xml', report='myrep.html', log='NONE')
+    rebot('path/to/output.xml')
+    with open('stdout.txt', 'w') as stdout:
+ rebot('o1.xml', 'o2.xml', report='r.html', log='NONE', stdout=stdout)

     Equivalent command line usage:
-    rebot /path/to/output.xml
-    rebot --report myrep.html --log NONE /path/out1.xml /path/out2.xml
+    rebot path/to/output.xml
+    rebot --report r.html --log NONE o1.xml o2.xml > stdout.txt
     """
     return _execute(_rebot, datasources, options)

 def _rebot(datasources, options):
     settings = RebotSettings(options)
-    LOGGER.register_console_logger(colors=settings['MonitorColors'])
+    LOGGER.register_console_logger(colors=settings['MonitorColors'],
+                                   stdout=settings['StdOut'],
+                                   stderr=settings['StdErr'])
     LOGGER.disable_message_cache()
     rc = ResultWriter(*datasources).write_results(settings)
     if rc < 0:
=======================================
--- /src/robot/conf/settings.py Mon Jan  2 14:56:46 2012
+++ /src/robot/conf/settings.py Sun Jan 29 10:35:23 2012
@@ -52,7 +52,9 @@
                  'NoStatusRC'       : ('nostatusrc', False),
                  'RunEmptySuite'    : ('runemptysuite', False),
                  'MonitorWidth'     : ('monitorwidth', 78),
-                 'MonitorColors'    : ('monitorcolors', 'AUTO')}
+                 'MonitorColors'    : ('monitorcolors', 'AUTO'),
+                 'StdOut'           : ('stdout', None),
+                 'StdErr'           : ('stderr', None)}
     _output_opts = ['Output', 'Log', 'Report', 'DebugFile', 'XUnitFile']

     def __init__(self, options={}, log=True):
=======================================
--- /src/robot/output/logger.py Mon Dec 19 07:44:27 2011
+++ /src/robot/output/logger.py Sun Jan 29 10:35:23 2012
@@ -67,12 +67,14 @@
         for log in loggers:
             self._loggers.unregister_logger(log)

-    def register_console_logger(self, width=78, colors='AUTO'):
+    def register_console_logger(self, width=78, colors='AUTO', stdout=None,
+                                stderr=None):
         self.disable_automatic_console_logger()
-        self._register_console_logger(width, colors)
-
-    def _register_console_logger(self, width=78, colors='AUTO'):
-        monitor = CommandLineMonitor(width, colors)
+        self._register_console_logger(width, colors, stdout, stderr)
+
+ def _register_console_logger(self, width=78, colors='AUTO', stdout=None,
+                                 stderr=None):
+        monitor = CommandLineMonitor(width, colors, stdout, stderr)
         self._loggers.register_regular_logger(monitor)

     def register_file_logger(self, path=None, level='INFO'):
=======================================
--- /utest/api/test_run_and_rebot.py    Sun Jan 29 04:20:55 2012
+++ /utest/api/test_run_and_rebot.py    Sun Jan 29 10:35:23 2012
@@ -79,6 +79,21 @@
         self._assert_outputs(stdout=[('Pass And Fail', 2), (LOG, 1)],
stderr=[('[ ERROR ]', 1), (self.nonex, 1), ('--help', 1)])

+    def test_custom_stdout(self):
+        stdout = StringIO()
+        assert_equals(run(self.data, output='NONE', stdout=stdout), 1)
+        self._assert_output(stdout, [('Pass And Fail', 2), ('Output:', 1),
+                                     ('Log:', 0), ('Report:', 0)])
+        self._assert_outputs()
+
+    def test_custom_stderr(self):
+        stderr = StringIO()
+        assert_equals(run(self.nonex, stderr=stderr), 252)
+        assert_equals(run(self.data, output='NONE', stderr=stderr), 1)
+ self._assert_output(stderr, [('[ ERROR ]', 1), (self.nonex, 1), ('--help', 1)])
+        self._assert_outputs([('Pass And Fail', 2), ('Output:', 1),
+                              ('Log:', 0), ('Report:', 0)])
+

 class TestRebot(Base):
     data = join(ROOT, 'atest', 'testdata', 'rebot', 'created_normal.xml')
@@ -100,6 +115,22 @@
         self._assert_outputs(stdout=[(LOG, 1)],
stderr=[('[ ERROR ]', 1), (self.nonex, 2), ('--help', 1)])

+    def test_custom_stdout(self):
+        stdout = StringIO()
+        assert_equals(rebot(self.data, report='None', stdout=stdout), 1)
+        self._assert_output(stdout, [('Log:', 1), ('Report:', 0)])
+        self._assert_outputs()
+
+    def test_custom_stdout_and_stderr(self):
+        output = StringIO()
+ assert_equals(rebot(self.data, log='NONE', report='NONE', stdout=output,
+                            stderr=output), 252)
+        assert_equals(rebot(self.data, report='NONE', stdout=output,
+                            stderr=output), 1)
+        self._assert_output(output, [('[ ERROR ] No outputs created', 1),
+ ('--help', 1), ('Log:', 1), ('Report:', 0)])
+        self._assert_outputs()
+

 if __name__ == '__main__':
     unittest.main()

Reply via email to