Exemplo n.º 1
0
 def _import_visitors(self, visitors):
     importer = Importer('pre-run visitor')
     for visitor, args in visitors:
         try:
             yield importer.import_class_or_module(visitor, args)
         except DataError as err:
             LOGGER.error(unicode(err))
Exemplo n.º 2
0
 def _import_listener(self, listener):
     if not is_string(listener):
         return listener, type_name(listener)
     name, args = split_args_from_name_or_path(listener)
     importer = Importer("listener")
     listener = importer.import_class_or_module(os.path.normpath(name), instantiate_with_args=args)
     return listener, name
 def _import_visitors(self, visitors):
     importer = Importer('model modifier')
     for visitor, args in visitors:
         try:
             yield importer.import_class_or_module(visitor, args)
         except DataError as err:
             self._log_error(unicode(err))
Exemplo n.º 4
0
 def _import_listener(self, listener):
     if not is_string(listener):
         return listener, type_name(listener)
     name, args = split_args_from_name_or_path(listener)
     importer = Importer('listener')
     listener = importer.import_class_or_module(os.path.normpath(name),
                                                instantiate_with_args=args)
     return listener, name
Exemplo n.º 5
0
def TestLibrary(name, args=None, variables=None, create_handlers=True):
    with OutputCapturer(library_import=True):
        importer = Importer("test library")
        libcode = importer.import_class_or_module(name)
    libclass = _get_lib_class(libcode)
    lib = libclass(libcode, name, args or [], variables)
    if create_handlers:
        lib.create_handlers()
    return lib
Exemplo n.º 6
0
def TestLibrary(name, args=None, variables=None, create_handlers=True):
    with OutputCapturer(library_import=True):
        importer = Importer('test library')
        libcode = importer.import_class_or_module(name)
    libclass = _get_lib_class(libcode)
    lib = libclass(libcode, name, args or [], variables)
    if create_handlers:
        lib.create_handlers()
    return lib
Exemplo n.º 7
0
 def _import_listener(self, listener):
     if not is_string(listener):
         # Modules have `__name__`, with others better to use `type_name`.
         name = getattr(listener, '__name__', None) or type_name(listener)
         return listener, name
     name, args = split_args_from_name_or_path(listener)
     importer = Importer('listener')
     listener = importer.import_class_or_module(os.path.normpath(name),
                                                instantiate_with_args=args)
     return listener, name
Exemplo n.º 8
0
 def _yield_visitors(self, visitors):
     importer = Importer('model modifier')
     for visitor in visitors:
         try:
             if not is_string(visitor):
                 yield visitor
             else:
                 name, args = split_args_from_name_or_path(visitor)
                 yield importer.import_class_or_module(name, args)
         except DataError as err:
             self._log_error(err.message)
Exemplo n.º 9
0
 def _yield_visitors(self, visitors):
     importer = Importer('model modifier')
     for visitor in visitors:
         try:
             if not is_string(visitor):
                 yield visitor
             else:
                 name, args = split_args_from_name_or_path(visitor)
                 yield importer.import_class_or_module(name, args)
         except DataError as err:
             self._log_error(err.message)
Exemplo n.º 10
0
def TestLibrary(name, args=None, variables=None, create_handlers=True):
    if name in STDLIBS:
        import_name = "robot.libraries." + name
    else:
        import_name = name
    with OutputCapturer(library_import=True):
        importer = Importer("test library")
        libcode, source = importer.import_class_or_module(import_name, return_source=True)
    libclass = _get_lib_class(libcode)
    lib = libclass(libcode, name, args or [], source, variables)
    if create_handlers:
        lib.create_handlers()
    return lib
Exemplo n.º 11
0
def TestLibrary(name, args=None, variables=None, create_handlers=True):
    if name in STDLIBS or name in DEPRECATED_STDLIBS:
        import_name = 'robot.libraries.' + name
    else:
        import_name = name
    with OutputCapturer(library_import=True):
        importer = Importer('test library')
        libcode = importer.import_class_or_module(import_name)
    libclass = _get_lib_class(libcode)
    lib = libclass(libcode, name, args or [], variables)
    if create_handlers:
        lib.create_handlers()
    return lib
Exemplo n.º 12
0
def TestLibrary(name, args=None, variables=None, create_handlers=True):
    if name in STDLIBS or name in DEPRECATED_STDLIBS:
        import_name = 'robot.libraries.' + name
    else:
        import_name = name
    with OutputCapturer(library_import=True):
        importer = Importer('test library')
        libcode = importer.import_class_or_module(import_name)
    libclass = _get_lib_class(libcode)
    lib = libclass(libcode, name, args or [], variables)
    if create_handlers:
        lib.create_handlers()
    return lib
    def _yield_visitors(self, visitors):
        # Avoid cyclic imports. Yuck.
        from robot.output import LOGGER

        importer = Importer('model modifier', logger=LOGGER)
        for visitor in visitors:
            try:
                if not is_string(visitor):
                    yield visitor
                else:
                    name, args = split_args_from_name_or_path(visitor)
                    yield importer.import_class_or_module(name, args)
            except DataError as err:
                self._log_error(err.message)
Exemplo n.º 14
0
def TestLibrary(name,
                args=None,
                variables=None,
                create_handlers=True,
                logger=LOGGER):
    if name in STDLIBS:
        import_name = 'robot.libraries.' + name
    else:
        import_name = name
    with OutputCapturer(library_import=True):
        importer = Importer('library', logger=LOGGER)
        libcode, source = importer.import_class_or_module(import_name,
                                                          return_source=True)
    libclass = _get_lib_class(libcode)
    lib = libclass(libcode, name, args or [], source, logger, variables)
    if create_handlers:
        lib.create_handlers()
    return lib
Exemplo n.º 15
0
    def _import_languages(self, lang):
        def is_language(member):
            return (inspect.isclass(member) and issubclass(member, Language)
                    and member is not Language)

        if os.path.exists(lang):
            lang = os.path.abspath(lang)
        module = Importer('language file').import_module(lang)
        return [value for _, value in inspect.getmembers(module, is_language)]
Exemplo n.º 16
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:
         args = 'with arguments %s ' % seq2str2(args) if args else ''
         raise DataError("Processing variable file '%s' %sfailed: %s" %
                         (path, args, get_error_message()))
Exemplo n.º 17
0
    def _import_languages(cls, lang):
        def find_subclass(member):
            return (inspect.isclass(member) and issubclass(member, Language)
                    and member is not Language)

        # FIXME: error handling
        if os.path.exists(lang):
            lang = os.path.abspath(lang)
        module = Importer().import_module(lang)
        return [
            value for _, value in inspect.getmembers(module, find_subclass)
        ]
Exemplo n.º 18
0
    def _run_task(self):
        kwfiles = []
        processed_files = []
        for library_name in self.options["path"]:
            kwfile = KeywordFile(library_name)
            try:
                if self.is_pageobject_library(library_name):
                    PageObjects._reset()
                    module = Importer().import_class_or_module_by_path(
                        os.path.abspath(library_name))
                    kwfile.doc = module.__doc__
                    if hasattr(module, "TITLE"):
                        kwfile.title = module.TITLE

                    for pobj_name, pobj in sorted(
                            PageObjects.registry.items()):
                        pobj = PageObjects.registry[pobj_name]
                        libname = "{}.{}".format(pobj.__module__,
                                                 pobj.__name__)
                        libdoc = LibraryDocBuilder().build(libname)
                        libdoc.src = os.path.basename(library_name)
                        libdoc.pobj = libname
                        kwfile.add_keywords(libdoc, pobj_name)

                else:
                    libdoc = DocumentationBuilder(library_name).build(
                        library_name)
                    kwfile.add_keywords(libdoc)

                # if we get here, we were able to process the file correctly
                kwfiles.append(kwfile)
                processed_files.append(library_name)

            except RobotNotRunningError as e:
                # oddly, robot's exception has a traceback embedded in the message, so we'll
                # only print out the first line to hide most of the noise
                self.logger.warn("unexpected error: {}".format(
                    str(e).split("\n")[0]))

        try:
            with open(self.options["output"], "w") as f:
                html = self._render_html(kwfiles)
                f.write(html)
                self.logger.info("created {}".format(f.name))
        except Exception as e:
            raise TaskOptionsError(
                "Unable to create output file '{}' ({})".format(
                    self.options["output"], e.strerror))

        return {"files": processed_files, "html": html}
Exemplo n.º 19
0
def load_classes_from_module_by_name(path, module_name, base_class=None):
    importer = Importer("RemoteMonitorLibrary")
    abs_path = path_join(path, module_name)
    logger.debug(f"[ 'RemoteMonitorLibrary' ] Load Module: {abs_path}")
    reader = importer.import_class_or_module(abs_path)
    return get_class_from_module(reader, base_class)
Exemplo n.º 20
0
 def import_variables(self, path, args=None):
     importer = Importer('variable file').import_class_or_module_by_path
     var_file = importer(path, instantiate_with_args=())
     return self._get_variables(var_file, args)
Exemplo n.º 21
0
 def _import_listener(self, name, args):
     importer = Importer('listener')
     return importer.import_class_or_module(os.path.normpath(name),
                                            instantiate_with_args=args)
Exemplo n.º 22
0
 def _import_listener(self, name, args):
     importer = Importer('listener')
     return importer.import_class_or_module(os.path.normpath(name),
                                            instantiate_with_args=args)