Exemplo n.º 1
0
 def import_resource(self, path):
     if self._resources.has_key(path):
         LOGGER.info("Found resource file '%s' from cache" % path)
     else:
         resource = ResourceFile(path)
         self._resources[path] = resource
     return self._resources[path]
Exemplo n.º 2
0
 def main(self, datasources, **options):
     settings = RobotSettings(options)
     LOGGER.register_console_logger(**settings.console_output_config)
     LOGGER.info('Settings:\n%s' % unic(settings))
     builder = TestSuiteBuilder(settings['SuiteNames'],
                                extension=settings.extension,
                                rpa=settings.rpa)
     suite = builder.build(*datasources)
     settings.rpa = builder.rpa
     suite.configure(**settings.suite_config)
     if settings.pre_run_modifiers:
         suite.visit(ModelModifier(settings.pre_run_modifiers,
                                   settings.run_empty_suite, LOGGER))
     with pyloggingconf.robot_handler_enabled(settings.log_level):
         old_max_error_lines = text.MAX_ERROR_LINES
         text.MAX_ERROR_LINES = settings.max_error_lines
         try:
             result = suite.run(settings)
         finally:
             text.MAX_ERROR_LINES = old_max_error_lines
         LOGGER.info("Tests execution ended. Statistics:\n%s"
                     % result.suite.stat_message)
         if settings.log or settings.report or settings.xunit:
             writer = ResultWriter(settings.output if settings.log
                                   else result)
             writer.write_results(settings.get_rebot_settings())
     return result.return_code
Exemplo n.º 3
0
 def import_resource(self, path):
     if path in self._resource_cache:
         LOGGER.info("Found resource file '%s' from cache" % path)
     else:
         resource = ResourceFile(path).populate()
         self._resource_cache[path] = resource
     return self._resource_cache[path]
Exemplo n.º 4
0
 def filter_empty_suites(self):
     for suite in self.suites[:]:
         suite.filter_empty_suites()
         if suite.get_test_count() == 0:
             self.suites.remove(suite)
             LOGGER.info("Running test suite '%s' failed: Test suite "
                         "contains no test cases." % suite.source)
Exemplo n.º 5
0
def _get_multisource_suite(datasources, include_suites):
    suitedatas = []
    for datasource in datasources:
        try:
            suitedatas.append(_parse_suite(datasource, include_suites))
        except DataError, err:
            LOGGER.info(err)
Exemplo n.º 6
0
 def import_resource(self, path):
     if path in self._resource_cache:
         LOGGER.info("Found resource file '%s' from cache" % path)
     else:
         resource = ResourceFileBuilder().build(path)
         self._resource_cache[path] = resource
     return self._resource_cache[path]
Exemplo n.º 7
0
 def _log_imported_library(self, name, args, lib):
     type = lib.__class__.__name__.replace('Library', '').lower()[1:]
     LOGGER.info("Imported library '%s' with arguments %s "
                 "(version %s, %s type, %s scope, %d keywords)"
                 % (name, utils.seq2str2(args), lib.version or '<unknown>',
                    type, lib.scope.lower(), len(lib)))
     if not lib:
         LOGGER.warn("Imported library '%s' contains no keywords" % name)
Exemplo n.º 8
0
 def __init__(self, variables, suite, resource):
     LOGGER.info("Initializing namespace for test suite '%s'" % suite.longname)
     self.variables = variables
     self._imports = resource.imports
     self._kw_store = KeywordStore(resource)
     self._imported_variable_files = ImportCache()
     self._suite_name = suite.longname
     self._running_test = False
Exemplo n.º 9
0
 def populate(self, path, datadir, include_suites=None, warn_on_skipped=False, recurse=True):
     LOGGER.info("Parsing test data directory '%s'" % path)
     include_suites = self._get_include_suites(path, include_suites or [])
     init_file, children = self._get_children(path, include_suites)
     if init_file:
         self._populate_init_file(datadir, init_file)
     if recurse:
         self._populate_children(datadir, children, include_suites, warn_on_skipped)
Exemplo n.º 10
0
 def import_library(self, name, args, alias, variables):
     lib = TestLibrary(name, args, variables, create_handlers=False)
     positional, named = lib.positional_args, lib.named_args
     lib = self._import_library(name, positional, named, lib)
     if alias and name != alias:
         lib = self._copy_library(lib, alias)
         LOGGER.info("Imported library '%s' with name '%s'" % (name, alias))
     return lib
Exemplo n.º 11
0
 def _populate_children(self, datadir, children, include_extensions,
                        include_suites):
     for child in children:
         try:
             datadir.add_child(child, include_suites, include_extensions)
         except NoTestsFound:
             LOGGER.info("Data source '%s' has no tests or tasks." % child)
         except DataError as err:
             LOGGER.error("Parsing '%s' failed: %s" % (child, err.message))
Exemplo n.º 12
0
 def populate(self, path):
     LOGGER.info("Parsing file '%s'." % path)
     source = self._open(path)
     try:
         self._get_reader(path).read(source, self)
     except:
         raise DataError(get_error_message())
     finally:
         source.close()
Exemplo n.º 13
0
 def __call__(self, signum, frame):
     self._signal_count += 1
     LOGGER.info('Received signal: %s.' % signum)
     if self._signal_count > 1:
         sys.__stderr__.write('Execution forcefully stopped.')
         raise SystemExit()
     sys.__stderr__.write('Second signal will force exit.')
     if self._running_keyword and not sys.platform.startswith('java'):
         self._stop_execution_gracefully()
Exemplo n.º 14
0
 def __init__(self, variables, suite, user_keywords, imports):
     LOGGER.info("Initializing namespace for test suite '%s'" % suite.longname)
     self.suite = suite
     self.test = None
     self.uk_handlers = []
     self.variables = variables
     self._imports = imports
     self._kw_store = KeywordStore(user_keywords, suite.source)
     self._imported_variable_files = ImportCache()
Exemplo n.º 15
0
 def _log_imported_library(self, name, args, lib):
     type = lib.__class__.__name__.replace('Library', '').lower()[1:]
     listener = ', with listener' if lib.has_listener else ''
     LOGGER.info("Imported library '%s' with arguments %s "
                 "(version %s, %s type, %s scope, %d keywords%s)"
                 % (name, seq2str2(args), lib.version or '<unknown>',
                    type, lib.scope.lower(), len(lib), listener))
     if not lib and not lib.has_listener:
         LOGGER.warn("Imported library '%s' contains no keywords" % name)
Exemplo n.º 16
0
 def populate(self, path, datadir, include_suites):
     LOGGER.info("Parsing test data directory '%s'" % path)
     include_sub_suites = self._get_include_suites(path, include_suites)
     initfile, children = self._get_children(path, include_sub_suites)
     datadir.initfile = initfile
     if initfile:
         try:
             FromFilePopulator(datadir).populate(initfile)
         except DataError, err:
             LOGGER.error(unicode(err))
Exemplo n.º 17
0
 def _import_resource(self, import_setting, overwrite=False):
     path = self._resolve_name(import_setting)
     self._validate_not_importing_init_file(path)
     if overwrite or path not in self._kw_store.resources:
         resource = IMPORTER.import_resource(path)
         self.variables.set_from_variable_table(resource.variable_table, overwrite)
         self._kw_store.resources[path] = UserLibrary(resource.keyword_table.keywords, resource.source)
         self._handle_imports(resource.setting_table.imports)
     else:
         LOGGER.info("Resource file '%s' already imported by suite '%s'" % (path, self.suite.longname))
Exemplo n.º 18
0
 def _import_library(self, name, positional, named, lib):
     args = positional + ["%s=%s" % arg for arg in named]
     key = (name, positional, named)
     if key in self._library_cache:
         LOGGER.info("Found test library '%s' with arguments %s from cache" % (name, seq2str2(args)))
         return self._library_cache[key]
     lib.create_handlers()
     self._library_cache[key] = lib
     self._log_imported_library(name, args, lib)
     return lib
 def set_from_file(self, path, args=None, overwrite=False):
     LOGGER.info("Importing variable file '%s' with args %s" % (path, args))
     var_file = self._import_variable_file(path)
     try:
         variables = self._get_variables_from_var_file(var_file, args)
         self._set_from_file(variables, overwrite)
     except:
         amsg = "with arguments %s " % utils.seq2str2(args) if args else ""
         raise DataError("Processing variable file '%s' %sfailed: %s" % (path, amsg, utils.get_error_message()))
     return variables
Exemplo n.º 20
0
 def import_variables(self, path, args=None):
     LOGGER.info("Importing variable file '%s' with args %s" % (path, args))
     importer = Importer('variable file').import_class_or_module_by_path
     var_file = importer(path, instantiate_with_args=())
     try:
         return self._get_variables(var_file, args)
     except:
         amsg = 'with arguments %s ' % seq2str2(args) if args else ''
         raise DataError("Processing variable file '%s' %sfailed: %s"
                         % (path, amsg, get_error_message()))
Exemplo n.º 21
0
 def populate(self, path, datadir, include_suites=None,
              include_extensions=None, recurse=True):
     LOGGER.info("Parsing directory '%s'." % path)
     include_suites = self._get_include_suites(path, include_suites)
     init_file, children = self._get_children(path, include_extensions,
                                              include_suites)
     if init_file:
         self._populate_init_file(datadir, init_file)
     if recurse:
         self._populate_children(datadir, children, include_extensions,
                                 include_suites)
Exemplo n.º 22
0
 def _import_library(self, import_setting):
     name = self._resolve_name(import_setting)
     lib = IMPORTER.import_library(name, import_setting.args, import_setting.alias, self.variables)
     if lib.name in self._kw_store.libraries:
         LOGGER.info("Test library '%s' already imported by suite '%s'" % (lib.name, self.suite.longname))
         return
     self._kw_store.libraries[lib.name] = lib
     lib.start_suite()
     if self.test:
         lib.start_test()
     self._import_deprecated_standard_libs(lib.name)
Exemplo n.º 23
0
 def _import_variables(self, import_setting, overwrite=False):
     path = self._resolve_name(import_setting)
     args = self._resolve_args(import_setting)
     if overwrite or (path, args) not in self._imported_variable_files:
         self._imported_variable_files.add((path, args))
         self.variables.set_from_file(path, args, overwrite)
     else:
         msg = "Variable file '%s'" % path
         if args:
             msg += " with arguments %s" % utils.seq2str2(args)
         LOGGER.info("%s already imported by suite '%s'" % (msg, self.suite.longname))
 def set_from_file(self, path, args, overwrite=False):
     LOGGER.info("Importing variable file '%s' with args %s" % (path, args))
     args = args or []
     try:
         module = utils.simple_import(path)
         variables = self._get_variables_from_module(module, args)
         self._set_from_file(variables, overwrite, path)
     except:
         amsg = args and 'with arguments %s ' % utils.seq2str2(args) or ''
         raise DataError("Processing variable file '%s' %sfailed: %s"
                         % (path, amsg, utils.get_error_message()))
     return variables
Exemplo n.º 25
0
 def _import_resource(self, import_setting, overwrite=False):
     path = self._resolve_name(import_setting)
     self._validate_not_importing_init_file(path)
     if overwrite or path not in self._kw_store.resources:
         resource = IMPORTER.import_resource(path)
         self.variables.set_from_variable_table(resource.variables, overwrite)
         user_library = UserLibrary(resource)
         self._kw_store.resources[path] = user_library
         self._handle_imports(resource.imports)
         LOGGER.imported("Resource", user_library.name, importer=import_setting.source, source=path)
     else:
         LOGGER.info("Resource file '%s' already imported by suite '%s'" % (path, self._suite_name))
Exemplo n.º 26
0
 def _close_listener(self, listener):
     method = (getattr(listener, 'close', None) or
               getattr(listener, '_close', None))
     try:
         if method:
             method()
     except:
         message, details = get_error_details()
         name = getattr(listener, '__name__', None) or type_name(listener)
         LOGGER.error("Calling method '%s' of listener '%s' failed: %s"
                      % (method.__name__, name, message))
         LOGGER.info("Details:\n%s" % details)
Exemplo n.º 27
0
 def _import_resource(self, import_setting, variables):
     path = self._resolve_name(import_setting, variables)
     if path not in self._imported_resource_files:
         self._imported_resource_files.append(path)
         resource = IMPORTER.import_resource(path)
         self.variables.set_from_variable_table(resource.variable_table)
         self._userlibs.append(UserLibrary(resource.keyword_table.keywords,
                                           resource.source))
         self._handle_imports(resource.setting_table.imports)
     else:
         LOGGER.info("Resource file '%s' already imported by suite '%s'"
                     % (path, self.suite.longname))
Exemplo n.º 28
0
 def _import_resource(self, import_setting, variables):
     path = self._resolve_name(import_setting, variables)
     if path not in self._imported_resource_files:
         self._imported_resource_files.append(path)
         resource = IMPORTER.import_resource(path)
         self.variables.set_from_variable_table(resource.variable_table)
         self._userlibs.append(
             UserLibrary(resource.keyword_table.keywords, resource.source))
         self._handle_imports(resource.setting_table.imports)
     else:
         LOGGER.info("Resource file '%s' already imported by suite '%s'" %
                     (path, self.suite.longname))
Exemplo n.º 29
0
 def _close_listener(self, listener):
     method = (getattr(listener, 'close', None) or
               getattr(listener, '_close', None))
     try:
         if method:
             method()
     except:
         message, details = get_error_details()
         name = getattr(listener, '__name__', None) or type_name(listener)
         LOGGER.error("Calling method '%s' of listener '%s' failed: %s"
                      % (method.__name__, name, message))
         LOGGER.info("Details:\n%s" % details)
Exemplo n.º 30
0
 def _import_library(self, name, positional, named, lib):
     args = positional + ['%s=%s' % arg for arg in sorted(named.items())]
     key = (name, positional, named)
     if key in self._library_cache:
         LOGGER.info(
             "Found test library '%s' with arguments %s from cache" %
             (name, utils.seq2str2(args)))
         return self._library_cache[key]
     lib.create_handlers()
     self._library_cache[key] = lib
     self._log_imported_library(name, args, lib)
     return lib
Exemplo n.º 31
0
 def _import_variables(self, import_setting, overwrite=False):
     path = self._resolve_name(import_setting)
     args = self._resolve_args(import_setting)
     if overwrite or (path, args) not in self._imported_variable_files:
         self._imported_variable_files.add((path,args))
         self.variables.set_from_file(path, args, overwrite)
     else:
         msg = "Variable file '%s'" % path
         if args:
             msg += " with arguments %s" % utils.seq2str2(args)
         LOGGER.info("%s already imported by suite '%s'"
                     % (msg, self.suite.longname))
Exemplo n.º 32
0
 def set_from_file(self, path, args=None, overwrite=False):
     LOGGER.info("Importing variable file '%s' with args %s" % (path, args))
     args = args or []
     module = self._importer.import_class_or_module_by_path(path)
     try:
         variables = self._get_variables_from_module(module, args)
         self._set_from_file(variables, overwrite, path)
     except:
         amsg = 'with arguments %s ' % utils.seq2str2(args) if args else ''
         raise DataError("Processing variable file '%s' %sfailed: %s"
                         % (path, amsg, utils.get_error_message()))
     return variables
Exemplo n.º 33
0
 def set_from_file(self, path, args, overwrite=False):
     LOGGER.info("Importing varible file '%s' with args %s" % (path, args))
     args = args or []
     try:
         module = utils.simple_import(path)
         variables = self._get_variables_from_module(module, args)
         self._set_from_file(variables, overwrite, path)
     except:
         amsg = args and 'with arguments %s ' % utils.seq2str2(args) or ''
         raise DataError("Processing variable file '%s' %sfailed: %s"
                         % (path, amsg, utils.get_error_message()))
     return variables
Exemplo n.º 34
0
 def _import_resource(self, import_setting, overwrite=False):
     path = self._resolve_name(import_setting)
     self._validate_not_importing_init_file(path)
     if overwrite or path not in self._kw_store.resources:
         resource = IMPORTER.import_resource(path)
         self.variables.set_from_variable_table(resource.variable_table,
                                                overwrite)
         self._kw_store.resources[path] \
             = UserLibrary(resource.keyword_table.keywords, resource.source)
         self._handle_imports(resource.setting_table.imports)
     else:
         LOGGER.info("Resource file '%s' already imported by suite '%s'"
                     % (path, self.suite.longname))
Exemplo n.º 35
0
def build_suite(source, datapath=None, parent_defaults=None,
                process_curdir=True):
    suite = TestSuite(name=format_name(source), source=source)
    defaults = TestDefaults(parent_defaults)
    if datapath:
        ast = get_test_case_file_ast(datapath, process_curdir)
        ErrorLogger(datapath).visit(ast)
        SettingsBuilder(suite, defaults).visit(ast)
        SuiteBuilder(suite, defaults).visit(ast)
        if not suite.tests:
            LOGGER.info("Data source '%s' has no tests or tasks." % datapath)
        suite.rpa = _get_rpa_mode(ast)
    return suite, defaults
 def __init__(self, suite, variables, parent_variables, user_keywords,
              imports):
     LOGGER.info("Initializing namespace for test suite '%s'" % suite.longname)
     self.suite = suite
     self.test = None
     self.uk_handlers = []
     self.variables = _VariableScopes(variables, parent_variables)
     self.library_search_order = []
     self._imports = imports
     self._user_keywords = UserLibrary(user_keywords)
     self._testlibs = {}
     self._imported_resource_files = ImportCache()
     self._imported_variable_files = ImportCache()
Exemplo n.º 37
0
 def _import_library(self, import_setting, variables):
     name = self._get_library_name(import_setting, variables)
     lib = IMPORTER.import_library(name, import_setting.args,
                                   import_setting.alias, variables)
     if lib.name in self._testlibs:
         LOGGER.info("Test library '%s' already imported by suite '%s'"
                     % (lib.name, self.suite.longname))
         return
     self._testlibs[lib.name] = lib
     lib.start_suite()
     if self.test:
         lib.start_test()
     self._import_deprecated_standard_libs(lib.name)
Exemplo n.º 38
0
def build_resource(data, source):
    resource = ResourceFile(source=source)
    if data.data_sections:
        ErrorLogger(source).visit(data)
        if data.has_tests:
            raise DataError("Resource file '%s' cannot contain tests or tasks." %
                            source)
        ResourceBuilder(resource).visit(data)
        LOGGER.info("Imported resource file '%s' (%d keywords)."
                    % (source, len(resource.keywords)))
    else:
        LOGGER.warn("Imported resource file '%s' is empty." % source)
    return resource
 def __init__(self, suite, variables, parent_variables, user_keywords,
              imports):
     LOGGER.info("Initializing namespace for test suite '%s'" %
                 suite.longname)
     self.suite = suite
     self.test = None
     self.uk_handlers = []
     self.variables = _VariableScopes(variables, parent_variables)
     self.library_search_order = []
     self._imports = imports
     self._user_keywords = UserLibrary(user_keywords)
     self._testlibs = {}
     self._imported_resource_files = ImportCache()
     self._imported_variable_files = ImportCache()
Exemplo n.º 40
0
 def _get_children(self, dirpath, incl_suites):
     init_file = None
     children = []
     for name, path in self._list_dir(dirpath):
         if self._is_init_file(name, path):
             if not init_file:
                 init_file = path
             else:
                 LOGGER.error("Ignoring second test suite init file '%s'." % path)
         elif self._is_included(name, path, incl_suites):
             children.append(path)
         else:
             LOGGER.info("Ignoring file or directory '%s'." % name)
     return init_file, children
Exemplo n.º 41
0
def _set_cli_vars(settings):
    for path, args in settings['VariableFiles']:
        try:
            GLOBAL_VARIABLES.set_from_file(path, args)
        except:
            msg, details = utils.get_error_details()
            LOGGER.error(msg)
            LOGGER.info(details)
    for varstr in settings['Variables']:
        try:
            name, value = varstr.split(':', 1)
        except ValueError:
            name, value = varstr, ''
        GLOBAL_VARIABLES['${%s}' % name] = value
Exemplo n.º 42
0
 def _import_library(self, import_setting):
     name = self._resolve_name(import_setting)
     lib = IMPORTER.import_library(name, import_setting.args,
                                   import_setting.alias, self.variables)
     if lib.name in self._kw_store.libraries:
         LOGGER.info("Test library '%s' already imported by suite '%s'" %
                     (lib.name, self.suite.longname))
         return
     self._kw_store.libraries[lib.name] = lib
     lib.start_suite()
     if self.test:
         lib.start_test()
     if name in STDLIB_TO_DEPRECATED_MAP:
         self.import_library(STDLIB_TO_DEPRECATED_MAP[name])
Exemplo n.º 43
0
 def populate(self,
              path,
              datadir,
              include_suites=None,
              warn_on_skipped=False,
              recurse=True):
     LOGGER.info("Parsing test data directory '%s'" % path)
     include_suites = self._get_include_suites(path, include_suites or [])
     init_file, children = self._get_children(path, include_suites)
     if init_file:
         self._populate_init_file(datadir, init_file)
     if recurse:
         self._populate_children(datadir, children, include_suites,
                                 warn_on_skipped)
Exemplo n.º 44
0
 def _list_dir(self, dir_path, incl_extensions, incl_suites):
     # os.listdir returns Unicode entries when path is Unicode
     names = os.listdir(unic(dir_path))
     for name in sorted(names, key=lambda item: item.lower()):
         name = unic(name)  # needed to handle nfc/nfd normalization on OSX
         path = os.path.join(dir_path, name)
         base, ext = os.path.splitext(name)
         ext = ext[1:].lower()
         if self._is_init_file(path, base, ext, incl_extensions):
             yield path, True
         elif self._is_included(path, base, ext, incl_extensions,
                                incl_suites):
             yield path, False
         else:
             LOGGER.info("Ignoring file or directory '%s'." % name)
Exemplo n.º 45
0
 def populate(self,
              path,
              datadir,
              include_suites=None,
              include_extensions=None,
              recurse=True):
     LOGGER.info("Parsing directory '%s'." % path)
     include_suites = self._get_include_suites(path, include_suites)
     init_file, children = self._get_children(path, include_extensions,
                                              include_suites)
     if init_file:
         self._populate_init_file(datadir, init_file)
     if recurse:
         self._populate_children(datadir, children, include_extensions,
                                 include_suites)
Exemplo n.º 46
0
 def main(self, datasources, **options):
     settings = RobotSettings(options)
     LOGGER.register_console_logger(**settings.console_logger_config)
     LOGGER.info('Settings:\n%s' % unicode(settings))
     suite = TestSuiteBuilder(settings['SuiteNames'],
                              settings['WarnOnSkipped'],
                              settings['RunEmptySuite']).build(*datasources)
     suite.configure(**settings.suite_config)
     result = suite.run(settings)
     LOGGER.info("Tests execution ended. Statistics:\n%s" %
                 result.suite.stat_message)
     if settings.log or settings.report or settings.xunit:
         writer = ResultWriter(settings.output if settings.log else result)
         writer.write_results(settings.get_rebot_settings())
     return result.return_code
Exemplo n.º 47
0
 def _import_resource(self, import_setting, overwrite=False):
     path = self._resolve_name(import_setting)
     self._validate_not_importing_init_file(path)
     if overwrite or path not in self._kw_store.resources:
         resource = IMPORTER.import_resource(path)
         self.variables.set_from_variable_table(resource.variables, overwrite)
         user_library = UserLibrary(resource)
         self._kw_store.resources[path] = user_library
         self._handle_imports(resource.imports)
         LOGGER.imported("Resource", user_library.name,
                         importer=import_setting.source,
                         source=path)
     else:
         LOGGER.info("Resource file '%s' already imported by suite '%s'"
                     % (path, self._suite_name))
Exemplo n.º 48
0
 def _import_if_needed(self, path_or_variables, args=None):
     if not is_string(path_or_variables):
         return path_or_variables
     LOGGER.info("Importing variable file '%s' with args %s" %
                 (path_or_variables, args))
     if path_or_variables.lower().endswith('.yaml'):
         importer = YamlImporter()
     else:
         importer = PythonImporter()
     try:
         return importer.import_variables(path_or_variables, args)
     except:
         args = 'with arguments %s ' % seq2str2(args) if args else ''
         raise DataError("Processing variable file '%s' %sfailed: %s" %
                         (path_or_variables, args, get_error_message()))
Exemplo n.º 49
0
 def _set_cli_variables(self, settings):
     for path, args in settings.variable_files:
         try:
             path = find_file(path, file_type='Variable file')
             self.set_from_file(path, args)
         except:
             msg, details = get_error_details()
             LOGGER.error(msg)
             LOGGER.info(details)
     for varstr in settings.variables:
         try:
             name, value = varstr.split(':', 1)
         except ValueError:
             name, value = varstr, ''
         self['${%s}' % name] = value
Exemplo n.º 50
0
 def _import_variables(self, import_setting, overwrite=False):
     path = self._resolve_name(import_setting)
     args = self._resolve_args(import_setting)
     if overwrite or (path, args) not in self._imported_variable_files:
         self._imported_variable_files.add((path, args))
         self.variables.set_from_file(path, args, overwrite)
         LOGGER.imported("Variables", os.path.basename(path),
                         args=list(args),
                         importer=import_setting.source,
                         source=path)
     else:
         msg = "Variable file '%s'" % path
         if args:
             msg += " with arguments %s" % seq2str2(args)
         LOGGER.info("%s already imported by suite '%s'"
                     % (msg, self._suite_name))
Exemplo n.º 51
0
 def _set_cli_variables(self, settings):
     for name, args in settings.variable_files:
         try:
             if name.lower().endswith(self._import_by_path_ends):
                 name = find_file(name, file_type='Variable file')
             self.set_from_file(name, args)
         except:
             msg, details = get_error_details()
             LOGGER.error(msg)
             LOGGER.info(details)
     for varstr in settings.variables:
         try:
             name, value = varstr.split(':', 1)
         except ValueError:
             name, value = varstr, ''
         self['${%s}' % name] = value
 def _build_suite(self, structure):
     parent_defaults = self._stack[-1][-1] if self._stack else None
     source = structure.source
     defaults = TestDefaults(parent_defaults)
     parser = self._get_parser(structure.extension)
     try:
         if structure.is_directory:
             suite = parser.parse_init_file(structure.init_file or source, defaults)
         else:
             suite = parser.parse_suite_file(source, defaults)
             if not suite.tests:
                 LOGGER.info("Data source '%s' has no tests or tasks." % source)
         self._validate_execution_mode(suite)
     except DataError as err:
         raise DataError("Parsing '%s' failed: %s" % (source, err.message))
     return suite, defaults
Exemplo n.º 53
0
 def _import_library(self, name, positional, named, lib):
     key = (name, positional, named)
     if self._libraries.has_key(key):
         LOGGER.info(
             "Found test library '%s' with arguments %s from cache" %
             (name, utils.seq2str2(positional)))
         return self._libraries[key]
     lib.create_handlers()
     self._libraries[key] = lib
     libtype = lib.__class__.__name__.replace('Library', '').lower()[1:]
     LOGGER.info("Imported library '%s' with arguments %s (version %s, "
                 "%s type, %s scope, %d keywords, source %s)" %
                 (name, utils.seq2str2(positional), lib.version, libtype,
                  lib.scope.lower(), len(lib), lib.source))
     if len(lib) == 0:
         LOGGER.warn("Imported library '%s' contains no keywords" % name)
     return lib
Exemplo n.º 54
0
 def _import_variables(self, import_setting, overwrite=False):
     path = self._resolve_name(import_setting)
     args = self._resolve_args(import_setting)
     if overwrite or (path, args) not in self._imported_variable_files:
         self._imported_variable_files.add((path, args))
         self.variables.set_from_file(path, args, overwrite)
         LOGGER.imported("Variables",
                         os.path.basename(path),
                         args=list(args),
                         importer=import_setting.source,
                         source=path)
     else:
         msg = f"Variable file '{path}'"
         if args:
             msg += f" with arguments {seq2str2(args)}"
         LOGGER.info(
             f"{msg} already imported by suite '{self._suite_name}'.")
Exemplo n.º 55
0
 def _list_dir(self, dir_path, incl_suites):
     try:
         names = os.listdir(dir_path)
     except:
         raise DataError("Reading directory '%s' failed: %s"
                         % (dir_path, get_error_message()))
     for name in sorted(names, key=lambda item: item.lower()):
         name = safe_str(name)  # Handles NFC normalization on OSX
         path = os.path.join(dir_path, name)
         base, ext = os.path.splitext(name)
         ext = ext[1:].lower()
         if self._is_init_file(path, base, ext):
             yield path, True
         elif self._is_included(path, base, ext, incl_suites):
             yield path, False
         else:
             LOGGER.info("Ignoring file or directory '%s'." % path)
Exemplo n.º 56
0
def process_output(path, read_level=-1, log_level=None):
    """Process one output file and return TestSuite and ExecutionErrors

    'read_level' can be used to limit how many suite levels are read. This is
    mainly useful when Robot has split outputs and only want to read index.
    """
    if not os.path.isfile(path):
        raise DataError("Output file '%s' does not exist." % path)
    LOGGER.info("Processing output file '%s'." % path)
    try:
        root = utils.DomWrapper(path)
    except:
        err = utils.get_error_message()
        raise DataError("Opening XML file '%s' failed: %s" % (path, err))
    suite = _get_suite_node(root, path)
    errors = _get_errors_node(root)
    return TestSuite(suite, read_level,
                     log_level=log_level), ExecutionErrors(errors)
Exemplo n.º 57
0
 def _import_library(self, import_setting, notify=True):
     name = self._resolve_name(import_setting)
     lib = IMPORTER.import_library(name, import_setting.args,
                                   import_setting.alias, self.variables)
     if lib.name in self._kw_store.libraries:
         LOGGER.info("Test library '%s' already imported by suite '%s'"
                     % (lib.name, self._suite_name))
         return
     if notify:
         LOGGER.imported("Library", lib.name,
                         args=list(import_setting.args),
                         originalname=lib.orig_name,
                         importer=import_setting.source,
                         source=lib.source)
     self._kw_store.libraries[lib.name] = lib
     lib.start_suite()
     if self._running_test:
         lib.start_test()
Exemplo n.º 58
0
 def main(self, datasources, **options):
     settings = RobotSettings(options)
     LOGGER.register_console_logger(**settings.console_output_config)
     LOGGER.info('Settings:\n%s' % unicode(settings))
     suite = TestSuiteBuilder(settings['SuiteNames'],
                              settings['WarnOnSkipped']).build(*datasources)
     suite.configure(**settings.suite_config)
     if settings.pre_run_modifiers:
         suite.visit(ModelModifier(settings.pre_run_modifiers,
                                   settings.run_empty_suite, LOGGER))
     with pyloggingconf.robot_handler_enabled(settings.log_level):
         result = suite.run(settings)
         LOGGER.info("Tests execution ended. Statistics:\n%s"
                     % result.suite.stat_message)
         if settings.log or settings.report or settings.xunit:
             writer = ResultWriter(settings.output if settings.log
                                   else result)
             writer.write_results(settings.get_rebot_settings())
     return result.return_code
Exemplo n.º 59
0
 def _list_dir(self, dir_path, incl_suites):
     # os.listdir returns Unicode entries when path is Unicode
     dir_path = unic(dir_path)
     try:
         names = os.listdir(dir_path)
     except:
         raise DataError("Reading directory '%s' failed: %s" %
                         (dir_path, get_error_message()))
     for name in sorted(names, key=lambda item: item.lower()):
         name = unic(name)  # needed to handle nfc/nfd normalization on OSX
         path = os.path.join(dir_path, name)
         base, ext = os.path.splitext(name)
         ext = ext[1:].lower()
         if self._is_init_file(path, base, ext):
             yield path, True
         elif self._is_included(path, base, ext, incl_suites):
             yield path, False
         else:
             LOGGER.info("Ignoring file or directory '%s'." % path)