Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
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.º 6
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.º 7
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.º 8
0
 def populate(self, path, resource=False):
     LOGGER.info("Parsing file '%s'." % path)
     source = self._open(path)
     try:
         self._get_reader(path, resource).read(source, self)
     except:
         raise DataError(get_error_message())
     finally:
         source.close()
Exemplo n.º 9
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.\n')
         raise SystemExit()
     sys.__stderr__.write('Second signal will force exit.\n')
     if self._running_keyword and not sys.platform.startswith('java'):
         self._stop_execution_gracefully()
Exemplo n.º 10
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.º 11
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:
         alias = variables.replace_scalar(alias)
         lib = self._copy_library(lib, alias)
         LOGGER.info("Imported library '%s' with name '%s'" % (name, alias))
     return lib
Exemplo n.º 12
0
 def populate(self, path, resource=False):
     LOGGER.info("Parsing file '%s'." % path)
     source = self._open(path)
     try:
         self._get_reader(path, resource).read(source, self)
     except:
         raise DataError(get_error_message())
     finally:
         source.close()
Exemplo n.º 13
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:
         alias = variables.replace_scalar(alias)
         lib = self._copy_library(lib, alias)
         LOGGER.info("Imported library '%s' with name '%s'" % (name, alias))
     return lib
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)
     self._imported_variable_files = ImportCache()
Exemplo n.º 15
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.º 16
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.º 17
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.\n')
         raise SystemExit()
     sys.__stderr__.write('Second signal will force exit.\n')
     if self._running_keyword and not sys.platform.startswith('java'):
         self._stop_execution_gracefully()
Exemplo n.º 18
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)
     self._imported_variable_files = ImportCache()
Exemplo n.º 19
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.º 20
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, 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.º 21
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, 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.º 22
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.º 23
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.º 24
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.º 25
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.º 26
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.º 27
0
Arquivo: scopes.py Projeto: Garjy/RIDE
 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.º 28
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.º 29
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.º 30
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.º 31
0
 def _list_dir(self, dir_path, incl_extensions, incl_suites):
     # os.listdir returns Unicode entries when path is Unicode
     dir_path = unic(dir_path)
     names = os.listdir(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'." % path)
Exemplo n.º 32
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.º 33
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.º 34
0
 def _list_dir(self, dir_path, incl_extensions, incl_suites):
     # os.listdir returns Unicode entries when path is Unicode
     dir_path = unic(dir_path)
     names = os.listdir(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'." % path)
Exemplo n.º 35
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.º 36
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.longname))
Exemplo n.º 37
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.keywords, resource.source)
         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.longname))
Exemplo n.º 38
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.º 39
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.º 40
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.º 41
0
 def _log_failed_parsing(self, message, warn):
     if warn:
         LOGGER.warn(message)
     else:
         LOGGER.info(message)
Exemplo n.º 42
0
 def _log_failed_parsing(self, message, warn):
     if warn:
         LOGGER.warn(message)
     else:
         LOGGER.info(message)
Exemplo n.º 43
0
 def _report_status(self):
     if self.setting_table or self.variable_table or self.keyword_table:
         LOGGER.info("Imported resource file '%s' (%d keywords)." %
                     (self.source, len(self.keyword_table.keywords)))
     else:
         LOGGER.warn("Imported resource file '%s' is empty." % self.source)
Exemplo n.º 44
0
 def _report_status(self):
     if self.setting_table or self.variable_table or self.keyword_table:
         LOGGER.info("Imported resource file '%s' (%d keywords)."
                     % (self.source, len(self.keyword_table.keywords)))
     else:
         LOGGER.warn("Imported resource file '%s' is empty." % self.source)