Example #1
0
    def _load_resource(self, path, report_status):
        r = ResourceFile(path)

        if os.stat(path)[6]!=0 and report_status:
            return r.populate()
        FromFilePopulator(r).populate(r.source)
        return r
    def add_resource_file(self, filename):
        """add all keywords in a resource file"""
        resource = ResourceFile(source=filename)
        resource.populate()

        if len(resource.keywords) > 0:
            collection_id = self.add_collection(resource.name, "resource", resource.setting_table.doc.value)
            for kw in resource.keywords:
                args = [arg.strip("${}") for arg in kw.args.value]
                self._add_keyword(collection_id, kw.name, kw.doc.value, args)
Example #3
0
    def add_resource_file(self, filename):
        '''add all keywords in a resource file'''
        resource = ResourceFile(source=filename)
        resource.populate()

        if len(resource.keywords) > 0:
            collection_id = self.add_collection(
                resource.name, "resource", resource.setting_table.doc.value)
            for kw in resource.keywords:
                args = [arg.strip("${}") for arg in kw.args.value]
                self._add_keyword(collection_id, kw.name, kw.doc.value, args)
Example #4
0
 def scan_res(self, file):
     # return None if file is not a test suite file.
     try:
         rs = ResourceFile(source=file)
         rs.populate()
         kws = []
         for kw in rs.keywords:
             print "-- keywords: %s" % (kw.name)
             kws.append(kw.name)
         return dict(name=rs.name, kws=kws)
     except Exception as e:
         print "not a resource: %s, %s" % (file, e)
         return None
Example #5
0
 def scan_res(self, file):
     # return None if file is not a test suite file.
     try:
         rs = ResourceFile(source=file)
         rs.populate()
         kws = []
         for kw in rs.keywords:
             print "-- keywords: %s" % (kw.name)
             kws.append(kw.name)
         return dict(name=rs.name, kws=kws)
     except Exception as e:
         print "not a resource: %s, %s" % (file, e)
         return None
Example #6
0
    def _process_dependency(self, dependency):
        """
        Processes a test suite dependency (could be a Resource or Library). This is read off the disk and added to the
        dependencies dict. This will then get transferred over to the remote side with the test suite. A dependency's
        location will be different on the remote host. This function also updates the reference to the dependency so
        that it resolves correctly on the remote side

        :param dependency: dependency to process
        :type dependency: robot.model.imports.Import
        """
        # RobotFramework will be installed on the remote machine so we don't need to bundle these
        if dependency.name not in STDLIBS:
            # Locate the dependency file
            dep_filepath = find_file(dependency.name, dependency.directory, dependency.type)
            dep_filename = os.path.basename(dep_filepath)
            logger.debug('Resolved dependency to: `{}`'.format(dependency.name))

            # Change the path to the reference so that it will resolve on the remote side. The directory containing all
            # of the dependencies will be added to the PYTHONPATH, so just the filename is sufficient
            dependency.name = dep_filename

            if dep_filename not in self._dependencies:
                if dependency.type == 'Resource':
                    # Import the Resource in order to parse its dependencies
                    res = ResourceFile(dep_filepath).populate()

                    # A Resource may have a dependency on other Resource and Library files, also collect these
                    for imp in res.imports:
                        logger.debug('Processing dependency: `{}` for: `{}`'.format(imp.name, dependency.name))
                        self._process_dependency(imp)

                    # Get the resource file data with the new reference paths
                    string_io = StringIO()
                    res.save(output=string_io)
                    logger.debug('Patched Resource file: `{}`'.format(dependency.name))
                    self._dependencies[dep_filename] = string_io.getvalue()
                elif dependency.type == 'Library':
                    # A Library is just a python file, so read this straight from disk
                    logger.debug('Reading Python library from disk: `{}`'.format(dep_filepath))
                    self._dependencies[dep_filename] = read_file_from_disk(dep_filepath)
            else:
                logger.debug('Dependency is already in the cache, skipping')
 def _create_data(self, resource_name, resource_import):
     res_path = os.path.abspath(resource_name)
     tcf = TestCaseFile(source=os.path.abspath('test.txt'))
     tcf.setting_table.add_resource(resource_import)
     tcf.variable_table.add('${dirname}', os.path.abspath('.').replace('\\', '\\\\'))
     tcf.variable_table.add('${path}', os.path.abspath(resource_name).replace('\\', '\\\\'))
     library_manager = LibraryManager(':memory:')
     library_manager.create_database()
     self.chef = ChiefController(Namespace(FakeSettings()), FakeSettings(), library_manager)
     self.chef._controller = TestCaseFileController(tcf, self.chef)
     res = ResourceFile(source=res_path)
     self.res_controller = \
         self.chef._resource_file_controller_factory.create(res)
     self.chef._namespace._resource_factory.cache[os.path.normcase(res_path)] = res
Example #8
0
 def test_reload_with_resource(self):
     controller_parent = lambda: 0
     controller_parent.children = []
     controller_parent.add_child = controller_parent.children.append
     ctrl = ResourceFileController(
         ResourceFile(source=self._resource_path).populate(),
         parent=controller_parent)
     assert_equals(len(ctrl.keywords), 1)
     open(self._resource_path,
          'a').write('Ninjaed Keyword  Log  I am taking over!\n')
     ctrl.reload()
     assert_equals(len(ctrl.keywords), 2)
     assert_equals(ctrl.keywords[-1].name, 'Ninjaed Keyword')
     assert_equals(ctrl.parent, controller_parent)
Example #9
0
    root = os.getcwd()
    py_path = os.path.join(root, sys.argv[1])
    if not os.path.exists(py_path) or not sys.argv[1].endswith(".py"):
        exit(1)
    p = pyparse(py_path)
    p.do()

    robot_files, py_files, filtered_files = [], [], []
    for subdir, dirs, files in os.walk(root):
        for f in files:
            path = subdir + os.sep + f
            if path.endswith('.robot'):
                robot_files.append(path)
            elif path.endswith('.txt'):
                try:
                    r = ResourceFile(path).populate()
                    robot_files.append(path)
                except:
                    filtered_files.append(path)
            elif path.endswith('.py'):
                py_files.append(path)
            else:
                filtered_files.append(path)

    for robot_file in robot_files:
        with open(robot_file, 'r', encoding='utf-8') as rf:
            for line in rf:
                if not line.startswith('#'):
                    for i in range(len(p.all_func_info)):
                        end_call_name, end_alias, in_line_call_name, in_line_alias = p.all_func_info[
                            i].robot_wrap()
 def _load_resource(self, path, report_status):
     r = ResourceFile(path)
     if os.stat(path)[6] != 0 and report_status:
         return r.populate()
     FromFilePopulator(r).populate(r.source)
     return r
 def new_resource(self, directory, name):
     path = os.path.join(directory, name) if directory else name
     path = self._normalize(path)
     resource = ResourceFile(source=path)
     self.cache[path] = resource
     return resource
 def _set_resources(self, *paths):
     for p in paths:
         resource = ResourceFileController(ResourceFile(os.path.normpath(p)))
         self.chief.resources.append(resource)
         self.chief.insert_into_suite_structure(resource)
Example #13
0
 def __init__(self, path):
     self.datafile = ResourceFile(path).populate()
     self.doc = LibraryDocumentation(path)