Esempio n. 1
0
    def preprocess_coverage_data(coverage):
        '''
        Preprocess the given coverage data.

        Preprocessing includes structuring the coverage data by directory
        for better performance as well as computing coverage summaries per directory.

        @type coverage: dict
        @param coverage: Coverage Data

        @rtype dict
        @return Preprocessed Coverage Data
        '''

        ret = {"children": {}}

        if "source_files" in coverage:
            # Coveralls format
            source_files = coverage["source_files"]

            # Process every source file and store the coverage data in our tree structure
            for source_file in source_files:

                # Split the filename into path parts and file part
                name = source_file["name"]
                name_parts = name.split(os.sep)
                path_parts = name_parts[:-1]
                file_part = name_parts[-1]

                # Start at the top of the tree for the path walking
                ptr = ret["children"]

                # Walk the tree down, one path part at a time and create parts
                # on the fly if they don't exist yet in our tree.
                for path_part in path_parts:
                    if path_part not in ptr:
                        ptr[path_part] = {"children": {}}

                    ptr = ptr[path_part]["children"]

                ptr[file_part] = {
                    "coverage":
                    [-1 if x is None else x for x in source_file["coverage"]]
                }

        else:
            raise RuntimeError("Unknown coverage format")

        # Now we need to calculate the coverage summaries (lines total and covered)
        # for each subtree in the tree. We can do this easily by using a recursive
        # definition.
        CoverageHelper.calculate_summary_fields(ret)

        return ret
Esempio n. 2
0
    def preprocess_coverage_data(coverage):
        '''
        Preprocess the given coverage data.

        Preprocessing includes structuring the coverage data by directory
        for better performance as well as computing coverage summaries per directory.

        @type coverage: dict
        @param coverage: Coverage Data

        @rtype dict
        @return Preprocessed Coverage Data
        '''

        ret = {"children": {}}

        if "source_files" in coverage:
            # Coveralls format
            source_files = coverage["source_files"]

            # Process every source file and store the coverage data in our tree structure
            for source_file in source_files:

                # Split the filename into path parts and file part
                name = source_file["name"]
                name_parts = name.split(os.sep)
                path_parts = name_parts[:-1]
                file_part = name_parts[-1]

                # Start at the top of the tree for the path walking
                ptr = ret["children"]

                # Walk the tree down, one path part at a time and create parts
                # on the fly if they don't exist yet in our tree.
                for path_part in path_parts:
                    if path_part not in ptr:
                        ptr[path_part] = {"children": {}}

                    ptr = ptr[path_part]["children"]

                ptr[file_part] = {
                    "coverage": [-1 if x is None else x for x in source_file["coverage"]]
                }

        else:
            raise RuntimeError("Unknown coverage format")

        # Now we need to calculate the coverage summaries (lines total and covered)
        # for each subtree in the tree. We can do this easily by using a recursive
        # definition.
        CoverageHelper.calculate_summary_fields(ret)

        return ret
Esempio n. 3
0
 def apply(self, collection):
     CoverageHelper.apply_include_exclude_directives(
         collection, self.directives.splitlines())
     CoverageHelper.calculate_summary_fields(collection)
Esempio n. 4
0
 def apply(self, collection):
     CoverageHelper.apply_include_exclude_directives(collection, self.directives.splitlines())
     CoverageHelper.calculate_summary_fields(collection)