def test_DictFilterKeysMatchingRegex(self): test_dict = { "foo.h": ["bar.h"], "foo.cc": ["foo.h", "bar.h"], "bar.h": ["baz.h", "qux.h"], "bad/bad.h": ["baz.h", "foo.h"] } test_regexes = [r"foo\..*", r"bad/.*"] expected_output = {"bar.h": ["baz.h", "qux.h"]} output = common_utils.DictFilterKeysMatchingRegex( test_dict, test_regexes) self.assertEqual(expected_output, output)
def GenerateGroupSizesForFilters(self, key_partition_function, filters=None): if filters is None: filters = [] including_file_dict = common_utils.DictFilterKeysMatchingRegex( self.including_file_dict, filters) feature_groups = common_utils.DictPartitionKeys( including_file_dict, key_partition_function) feature_dict = {} for feature, including_files in feature_groups.items(): feature_dict[feature] = len(including_files) feature_dict = common_utils.DictWithTotal(feature_dict) return feature_dict
def __init__(self, database_filename, including_files_filters, included_files_to_limit_to=None): self.inclusions_db = inclusions_database.ReadInclusionsDbFromDisk( database_filename) if included_files_to_limit_to: inclusions_database.LimitToSpecifiedIncludedFiles( self.inclusions_db, included_files_to_limit_to) # TODO: Maybe this function should move to this class? including_file_dict = inclusions_database.FilterOutIncludedFilesAsKeys( self.inclusions_db) including_file_dict = common_utils.DictFilterKeysMatchingRegex( including_file_dict, including_files_filters) self.including_file_dict = including_file_dict
def GenerateGroupNumInclusionsForFilters(self, key_partition_function, filters=None): if filters is None: filters = [] including_file_dict = common_utils.DictFilterKeysMatchingRegex( self.including_file_dict, filters) feature_groups = common_utils.DictPartitionKeys( including_file_dict, key_partition_function) feature_dict = {} including_file_dict = common_utils.DictListValuesToSums( including_file_dict) for feature, including_files in feature_groups.items(): feature_dict[feature] = 0 for including_file in including_files: feature_dict[feature] += including_file_dict[including_file] feature_dict = common_utils.DictWithTotal(feature_dict) return feature_dict
def FilterOutIncludedFilesAsKeys(inclusions_db): output_dict = common_utils.DictFilterKeysMatchingRegex( inclusions_db["including_to_included"], IncludedFilesRegexes(inclusions_db)) return output_dict