3 new revisions:
Revision: 74032bad8b05
Author: Pekka Klärck
Date: Mon Jan 30 12:45:43 2012
Log: cleanup
http://code.google.com/p/robotframework/source/detail?r=74032bad8b05
Revision: a72f14d4b55e
Author: Pekka Klärck
Date: Mon Jan 30 12:52:40 2012
Log: fixed import
http://code.google.com/p/robotframework/source/detail?r=a72f14d4b55e
Revision: d19843f60615
Author: Pekka Klärck
Date: Mon Jan 30 13:05:37 2012
Log: Changed the generic Application so that it must be subclassed and
_mai...
http://code.google.com/p/robotframework/source/detail?r=d19843f60615
==============================================================================
Revision: 74032bad8b05
Author: Pekka Klärck
Date: Mon Jan 30 12:45:43 2012
Log: cleanup
http://code.google.com/p/robotframework/source/detail?r=74032bad8b05
Modified:
/src/robot/utils/argumentparser.py
=======================================
--- /src/robot/utils/argumentparser.py Mon Jan 30 08:28:51 2012
+++ /src/robot/utils/argumentparser.py Mon Jan 30 12:45:43 2012
@@ -300,7 +300,7 @@
if not args:
self._arg_limits = (0, 0)
else:
- maxargs = args[-1].endswith('s') and sys.maxint or
len(args)
+ maxargs = sys.maxint if args[-1].endswith('s') else
len(args)
self._arg_limits = (len(args), maxargs)
def _parse_opt_line(self, line):
@@ -311,7 +311,7 @@
if long_opt in self._names:
self._raise_option_multiple_times_in_usage('--' + long_opt)
self._names.append(long_opt)
- short_opts = [ opt[1] for opt in res.group(1).split() ]
+ short_opts = [opt[1] for opt in res.group(1).split()]
for sopt in short_opts:
if self._short_to_long.has_key(sopt):
self._raise_option_multiple_times_in_usage('-' + sopt)
@@ -322,7 +322,7 @@
# options with arguments
if res.group(4):
long_opt += '='
- short_opts = [ sopt + ':' for sopt in short_opts ]
+ short_opts = [sopt+':' for sopt in short_opts]
else:
self._toggle_opts.append(long_opt)
self._long_opts.append(long_opt)
==============================================================================
Revision: a72f14d4b55e
Author: Pekka Klärck
Date: Mon Jan 30 12:52:40 2012
Log: fixed import
http://code.google.com/p/robotframework/source/detail?r=a72f14d4b55e
Modified:
/atest/robot/tidy/TidyLib.py
=======================================
--- /atest/robot/tidy/TidyLib.py Wed Jan 25 01:46:49 2012
+++ /atest/robot/tidy/TidyLib.py Mon Jan 30 12:52:40 2012
@@ -5,7 +5,7 @@
from subprocess import call, STDOUT
import tempfile
-from robot import DataError
+from robot.errors import DataError
from robot.utils.asserts import assert_equals
from robot.tidy import TidyCommandLine
import robot.tidy
==============================================================================
Revision: d19843f60615
Author: Pekka Klärck
Date: Mon Jan 30 13:05:37 2012
Log: Changed the generic Application so that it must be subclassed and
_main implemented. It now has generic entry points 'cli' and 'api', but
those could possibly be renamed e.g. to 'cli_execute' and 'execute'. That
can be done as part of review and when integrating this with Tidy.
http://code.google.com/p/robotframework/source/detail?r=d19843f60615
Modified:
/src/robot/rebot.py
/src/robot/run.py
/src/robot/utils/application.py
=======================================
--- /src/robot/rebot.py Mon Jan 30 11:49:14 2012
+++ /src/robot/rebot.py Mon Jan 30 13:05:37 2012
@@ -260,19 +260,35 @@
from robot.utils import Application
-def rebot_cli(cli_args):
- app = Application(USAGE)
- opts, args = app.parse_arguments(cli_args)
- rc = app.execute(_rebot, opts, args)
- app.exit(rc)
-
+class Rebot(Application):
+
+ def _main(self, *datasources, **options):
+ settings = RebotSettings(options)
+ 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:
+ raise DataError('No outputs created.')
+ return rc
+
+
+
+def rebot_cli(arguments):
+ """Command line execution entry point for running rebot.
+
+ For programmatic usage the `rebot` method is typically better. It has
+ better API for that usage and does not use sys.exit like this method.
+ """
+ Rebot(USAGE).cli(arguments)
def rebot(*datasources, **options):
"""Creates reports/logs from given Robot output files with given
options.
Given input files are paths to Robot output files similarly as when
running
- rebot from command line. Options are given as keywords arguments and
+ rebot from the command line. Options are given as keywords arguments
and
their names are same as long command line options without hyphens.
To capture stdout and/or stderr streams, pass open file objects in as
@@ -289,20 +305,7 @@
rebot path/to/output.xml
rebot --report r.html --log NONE o1.xml o2.xml > stdout.txt
"""
- app = Application('xxx', exit=False)
- rc = app.execute(_rebot, options, datasources)
- return app.exit(rc)
-
-def _rebot(*datasources, **options):
- settings = RebotSettings(options)
- 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:
- raise DataError('No outputs created.')
- return rc
+ return Rebot(USAGE).api(*datasources, **options)
if __name__ == '__main__':
=======================================
--- /src/robot/run.py Mon Jan 30 11:49:14 2012
+++ /src/robot/run.py Mon Jan 30 13:05:37 2012
@@ -319,20 +319,44 @@
from robot.variables import init_global_variables
-
-def run_cli(cli_args):
- app = Application(USAGE)
- opts, args = app.parse_arguments(cli_args)
- rc = app.execute(_run, opts, args)
- app.exit(rc)
+class RobotFramework(Application):
+
+ def _main(self, *datasources, **options):
+ STOP_SIGNAL_MONITOR.start()
+ settings = RobotSettings(options)
+ pyloggingconf.initialize(settings['LogLevel'])
+ 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)
+ suite.run(output)
+ LOGGER.info("Tests execution ended. Statistics:\n%s"
+ % suite.get_stat_message())
+ output.close(suite)
+ if settings.is_rebot_needed():
+ output, settings = settings.get_rebot_datasource_and_settings()
+ ResultWriter(output).write_results(settings)
+ return suite.return_code
+
+
+def run_cli(arguments):
+ """Command line execution entry point for running tests.
+
+ For programmatic usage the `run` method is typically better. It has
+ better API for that usage and does not use sys.exit like this method.
+ """
+ RobotFramework(USAGE).cli(arguments)
def run(*datasources, **options):
- """Executes given Robot data sources with given options.
+ """Executes given Robot Framework data sources with given options.
Data sources are paths to files and directories, similarly as when
running
- pybot/jybot from command line. Options are given as keywords arguments
and
- their names are same as long command line options without hyphens.
+ pybot/jybot from the command line. Options are given as keywords
arguments
+ and their names are same as long command line options without hyphens.
To capture stdout and/or stderr streams, pass open file objects in as
keyword arguments `stdout` and `stderr`, respectively.
@@ -348,29 +372,7 @@
pybot path/to/tests.html
pybot --report r.html --log NONE t1.txt t2.txt > stdout.txt
"""
- app = Application('xxx', exit=False)
- rc = app.execute(_run, options, datasources)
- return app.exit(rc)
-
-def _run(*datasources, **options):
- STOP_SIGNAL_MONITOR.start()
- settings = RobotSettings(options)
- pyloggingconf.initialize(settings['LogLevel'])
- 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)
- suite.run(output)
- LOGGER.info("Tests execution ended. Statistics:\n%s"
- % suite.get_stat_message())
- output.close(suite)
- if settings.is_rebot_needed():
- output, settings = settings.get_rebot_datasource_and_settings()
- ResultWriter(output).write_results(settings)
- return suite.return_code
+ return RobotFramework(USAGE).api(*datasources, **options)
if __name__ == '__main__':
=======================================
--- /src/robot/utils/application.py Mon Jan 30 11:51:13 2012
+++ /src/robot/utils/application.py Mon Jan 30 13:05:37 2012
@@ -24,30 +24,44 @@
class Application(object):
- def __init__(self, usage, name=None, version=None, arg_limits=None,
exit=True,
+ def __init__(self, usage, name=None, version=None, arg_limits=None,
logger=None):
self._ap = ArgumentParser(usage, name, version, arg_limits)
self._exit = exit
if not logger:
from robot.output import LOGGER as logger # Hack
self._logger = logger
+
+ def cli(self, cli_arguments):
+ self._init_logging()
+ options, arguments = self._parse_arguments(cli_arguments)
+ rc = self._execute(arguments, options)
+ self._exit(rc)
+
+ def _init_logging(self):
self._logger.register_file_logger()
self._logger.info('%s %s' % (self._ap.name, self._ap.version))
- def parse_arguments(self, cli_args, check_args=True):
+ def _parse_arguments(self, cli_args):
try:
- options, arguments = self._ap.parse_args(cli_args, check_args)
+ options, arguments = self._ap.parse_args(cli_args)
except Information, msg:
- return self._report_info(unicode(msg))
+ self._report_info(unicode(msg))
except DataError, err:
- return self._report_error(unicode(err), help=True)
+ self._report_error(unicode(err), help=True, exit=True)
else:
self._logger.info('Arguments: %s' % ','.join(arguments))
return options, arguments
- def execute(self, method, options, arguments):
+ def api(self, *arguments, **options):
+ self._init_logging()
+ rc = self._execute(arguments, options)
+ self._logger.close()
+ return rc
+
+ def _execute(self, arguments, options):
try:
- rc = method(*arguments, **options)
+ rc = self._main(*arguments, **options)
except DataError, err:
return self._report_error(unicode(err), help=True)
except (KeyboardInterrupt, SystemExit):
@@ -60,20 +74,24 @@
else:
return rc
+ def _main(self, *arguments, **options):
+ raise NotImplementedError
+
def _report_info(self, msg):
print encode_output(unicode(msg))
- return self.exit(INFO_PRINTED)
-
- def _report_error(self, message, details=None, help=False,
rc=DATA_ERROR):
+ self._exit(INFO_PRINTED)
+
+ def _report_error(self, message, details=None, help=False,
rc=DATA_ERROR,
+ exit=False):
if help:
message += '\n\nTry --help for usage information.'
if details:
message += '\n' + details
self._logger.error(message)
- return self.exit(rc)
-
- def exit(self, rc):
+ if exit:
+ self._exit(rc)
+ return rc
+
+ def _exit(self, rc):
self._logger.close()
- if self._exit:
- sys.exit(rc)
- return rc
+ sys.exit(rc)