def _run_or_rebot_from_cli(method, cliargs, usage, **argparser_config):
    LOGGER.register_file_logger()
    try:
        options, datasources = _parse_arguments(cliargs, usage,
                                                **argparser_config)
    except Information, msg:
        print utils.encode_output(unicode(msg))
        return INFO_PRINTED
Esempio n. 2
0
def _run_or_rebot_from_cli(method, cliargs, usage, **argparser_config):
    LOGGER.register_file_logger()
    ap = utils.ArgumentParser(usage, get_full_version())
    try:
        options, datasources = \
            ap.parse_args(cliargs, argfile='argumentfile', unescape='escape',
                          help='help', version='version', check_args=True,
                          **argparser_config)
    except Information, msg:
        _exit(INFO_PRINTED, utils.unic(msg))
Esempio n. 3
0
def _run_or_rebot_from_cli(method, cliargs, usage, **argparser_config):
    LOGGER.register_file_logger()
    ap = utils.ArgumentParser(usage, get_full_version())
    try:
        options, datasources = \
            ap.parse_args(cliargs, argfile='argumentfile', unescape='escape',
                          help='help', version='version', check_args=True,
                          **argparser_config)
    except Information, msg:
        _exit(INFO_PRINTED, utils.unic(msg))
Esempio n. 4
0
def _exit(rc, message=None, details=None):
    """Exits with given rc or rc from given output. Reports possible error.

    Exit code is the number of failed critical tests or error number.
      0       - Tests executed and all critical tests passed
      1-250   - Tests executed but returned number of critical tests failed
                (250 means 250 or more failures)
      251     - Help or version info was printed
      252     - Invalid test data or command line arguments
      253     - Execution stopped by user
      255     - Internal and unexpected error occurred in the framework itself
    """
    if rc == INFO_PRINTED:
        print utils.encode_output(message)
    else:
        if rc == DATA_ERROR:
            message += '\n\nTry --help for usage information.'
        LOGGER.error(message)
        if details:
            LOGGER.info(details)
    sys.exit(rc)
Esempio n. 5
0
def _exit(rc, message=None, details=None):
    """Exits with given rc or rc from given output. Reports possible error.

    Exit code is the number of failed critical tests or error number.
      0       - Tests executed and all critical tests passed
      1-250   - Tests executed but returned number of critical tests failed
                (250 means 250 or more failures)
      251     - Help or version info was printed
      252     - Invalid test data or command line arguments
      253     - Execution stopped by user
      255     - Internal and unexpected error occurred in the framework itself
    """
    if rc == INFO_PRINTED:
        print message
    else:
        if rc == DATA_ERROR:
            message += '\n\nTry --help for usage information.'
        LOGGER.error(message)
        if details:
            LOGGER.info(details)
    sys.exit(rc)
def run(*datasources, **options):
    """Executes given Robot 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.

    Examples:
    run('/path/to/tests.html')
    run('/path/to/tests.html', '/path/to/tests2.html', log='mylog.html')

    Equivalent command line usage:
    pybot /path/to/tests.html
    pybot --log mylog.html /path/to/tests.html /path/to/tests2.html
    """
    STOP_SIGNAL_MONITOR.start()
    settings = RobotSettings(options)
    LOGGER.register_console_logger(settings['MonitorWidth'],
                                   settings['MonitorColors'])
    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(settings).write_robot_results(output)
    LOGGER.close()
    return suite
def run_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
    their names are same as long command line options without hyphens.

    Examples:
    run_rebot('/path/to/output.xml')
    run_rebot('/path/out1.xml', '/path/out2.xml', report='myrep.html', log='NONE')

    Equivalent command line usage:
    rebot /path/to/output.xml
    rebot --report myrep.html --log NONE /path/out1.xml /path/out2.xml
    """
    settings = RebotSettings(options)
    LOGGER.register_console_logger(colors=settings['MonitorColors'])
    LOGGER.disable_message_cache()
    suite = ResultWriter(settings).write_rebot_results(*datasources)
    LOGGER.close()
    return suite
Esempio n. 8
0
def run_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
    their names are same as long command line options without hyphens.

    Examples:
    run_rebot('/path/to/output.xml')
    run_rebot('/path/out1.xml', '/path/out2.xml', report='myrep.html', log='NONE')

    Equivalent command line usage:
    rebot /path/to/output.xml
    rebot --report myrep.html --log NONE /path/out1.xml /path/out2.xml
    """
    settings = RebotSettings(options)
    LOGGER.register_console_logger(colors=settings['MonitorColors'])
    LOGGER.disable_message_cache()
    testoutput = RebotTestOutput(datasources, settings)
    testoutput.serialize(settings, generator='Rebot')
    LOGGER.close()
    return testoutput.suite
Esempio n. 9
0
def run(*datasources, **options):
    """Executes given Robot 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.

    Examples:
    run('/path/to/tests.html')
    run('/path/to/tests.html', '/path/to/tests2.html', log='mylog.html')

    Equivalent command line usage:
    pybot /path/to/tests.html
    pybot --log mylog.html /path/to/tests.html /path/to/tests2.html
    """
    STOP_SIGNAL_MONITOR.start()
    settings = RobotSettings(options)
    LOGGER.register_console_logger(settings['MonitorWidth'],
                                   settings['MonitorColors'])
    output = Output(settings)
    init_global_variables(settings)
    suite = TestSuite(datasources, settings)
    suite.run(output)
    LOGGER.info("Tests execution ended. Statistics:\n%s" %
                suite.get_stat_message())
    testoutput = RobotTestOutput(suite, settings)
    output.close(suite)
    if settings.is_rebot_needed():
        datasources, settings = settings.get_rebot_datasources_and_settings()
        if settings['SplitOutputs'] > 0:
            testoutput = SplitIndexTestOutput(suite, datasources[0], settings)
        else:
            testoutput = RebotTestOutput(datasources, settings)
        testoutput.serialize(settings)
    LOGGER.close()
    return suite
Esempio n. 10
0
def rebot_from_cli(args, usage):
    LOGGER.info(get_full_version('Rebot'))
    _run_or_rebot_from_cli(run_rebot, args, usage)
Esempio n. 11
0
def run_from_cli(args, usage):
    LOGGER.info(get_full_version('Robot Framework'))
    _run_or_rebot_from_cli(run, args, usage, pythonpath='pythonpath')
Esempio n. 12
0

def _run_or_rebot_from_cli(method, cliargs, usage, **argparser_config):
    LOGGER.register_file_logger()
    ap = utils.ArgumentParser(usage, get_full_version())
    try:
        options, datasources = \
            ap.parse_args(cliargs, argfile='argumentfile', unescape='escape',
                          help='help', version='version', check_args=True,
                          **argparser_config)
    except Information, msg:
        _exit(INFO_PRINTED, utils.unic(msg))
    except DataError, err:
        _exit(DATA_ERROR, utils.unic(err))

    LOGGER.info('Data sources: %s' % utils.seq2str(datasources))
    try:
        suite = method(*datasources, **options)
    except DataError, err:
        _exit(DATA_ERROR, unicode(err))
    except (KeyboardInterrupt, SystemExit):
        _exit(STOPPED_BY_USER, 'Execution stopped by user.')
    except:
        error, details = utils.get_error_details()
        _exit(FRAMEWORK_ERROR, 'Unexpected error: %s' % error, details)
    else:
        _exit(_failed_critical_test_count(suite))


def _failed_critical_test_count(suite):
    rc = suite.critical_stats.failed
def rebot_from_cli(args, usage):
    LOGGER.info(get_full_version('Rebot'))
    return _run_or_rebot_from_cli(run_rebot, args, usage)
def run_from_cli(args, usage):
    LOGGER.info(get_full_version('Robot Framework'))
    return _run_or_rebot_from_cli(run, args, usage, pythonpath='pythonpath')
def _report_error(message, details=None, help=False):
    if help:
        message += '\n\nTry --help for usage information.'
    if details:
        message += '\n' + details
    LOGGER.error(message)
def rebot_from_cli(args, usage):
    LOGGER.info(get_full_version('Rebot'))
    return _run_or_rebot_from_cli(run_rebot, args, usage)

def _run_or_rebot_from_cli(method, cliargs, usage, **argparser_config):
    LOGGER.register_file_logger()
    try:
        options, datasources = _parse_arguments(cliargs, usage,
                                                **argparser_config)
    except Information, msg:
        print utils.encode_output(unicode(msg))
        return INFO_PRINTED
    except DataError, err:
        _report_error(unicode(err), help=True)
        return DATA_ERROR
    LOGGER.info('Data sources: %s' % utils.seq2str(datasources))
    return _execute(method, datasources, options)

def _parse_arguments(cliargs, usage, **argparser_config):
    ap = utils.ArgumentParser(usage, get_full_version())
    return ap.parse_args(cliargs, argfile='argumentfile', unescape='escape',
                         help='help', version='version', check_args=True,
                         **argparser_config)

def _execute(method, datasources, options):
    try:
        suite = method(*datasources, **options)
    except DataError, err:
        _report_error(unicode(err), help=True)
        return DATA_ERROR
    except (KeyboardInterrupt, SystemExit):