def test_cache(self): f = NamedTemporaryFile(delete=False) f.close() self.assertEquals( 0, self._testee.apply_metric_to_resource(FileResource(f.name))) self.assertFalse(self._testee.modified(FileResource(f.name))) time.sleep(self.get_mtime_minwait()) with open(f.name, "wt") as f2: f2.write("\n") f2.close() self.assertTrue(self._testee.modified(FileResource(f.name))) os.unlink(f.name)
def test_succeed_and_fail(self): f = NamedTemporaryFile(delete=False) f.close() self.assertEquals( 0, self._testee.apply_metric_to_resource(FileResource(f.name))) os.unlink(f.name) self.assertRaises(ResourceAccessError, self._testee.apply_metric_to_resource, FileResource(f.name)) time.sleep(self.get_mtime_minwait()) with open(f.name, "wt") as f2: f2.write("\n") f2.close() self.assertEquals( 1, self._testee.apply_metric_to_resource(FileResource(f.name))) os.unlink(f.name)
def test_fail(self): f = NamedTemporaryFile(delete=False) f.close() os.unlink(f.name) self.assertRaises(ResourceAccessError, self._testee.apply_metric_to_resource, FileResource(f.name))
def create_file_repair_processor(self, local_source_base_dir, mode, required_includes, closure, invalidate, target=None, target_dir=None, required_include_files_calculator_class=None, include_list_generator_factory=None): local_source_resource_resolver = FixedBaseDirPathResolver(FileResource(local_source_base_dir), normalize=True) is_implementation_file_func = self.__cpp_file_configuration.is_implementation_file generation_strategy = self.__create_generation_strategy("none" if mode==FileTransformationModes.ListIncludes else target, target_dir) if mode in (FileTransformationModes.NormalizeOnly, FileTransformationModes.ListIncludes): ipcf = self.__create_include_path_canonicalizer_factory(local_source_base_dir) if mode == FileTransformationModes.NormalizeOnly: individual_file_repair_processor = self.__create_normalizing_file_repair_processor(local_source_resource_resolver, is_implementation_file_func, ipcf, generation_strategy, invalidate) elif mode == FileTransformationModes.ListIncludes: individual_file_repair_processor = self.__create_list_include_processor(local_source_resource_resolver, is_implementation_file_func, ipcf, generation_strategy, invalidate) elif mode == FileTransformationModes.Repair: # TODO repairing should be able to perform the same normalization as for NormalizeOnly individual_file_repair_processor = self.__create_repairing_file_repair_processor(required_includes, local_source_resource_resolver, is_implementation_file_func, generation_strategy, required_include_files_calculator_class, include_list_generator_factory=include_list_generator_factory) else: raise ValueError("Invalid file repair mode") if closure: file_repair_processor = ClosureFileRepairProcessor( decoratee=individual_file_repair_processor) else: file_repair_processor = individual_file_repair_processor return file_repair_processor
def __init__(self, path_rel_to_root_unix, module_name=None, local_repository_root=None, resource=None, path_module=os.path): self.__module_name = module_name self.__local_repository_root = local_repository_root self.__path_rel_to_root_unix = path_rel_to_root_unix if resource: self.__resource = resource elif self.__local_repository_root: self.__resource = FileResource(path_module.join(self.__local_repository_root, self.__path_rel_to_root_unix))
def parse_files_ex(self, filenames): #TODO extract into interface #TODO merge impl. with parse_files for name in filenames: self._current_resource = FileResource(name) for entry in self.parse_lines(open(name, 'r')): yield (self._current_resource, entry) self._current_resource = None
def resolve_include_specification(self, included_file, try_first): """ @rtype: tuple(IncludeSpecificationType, Resource) """ try: (include_specification_type, canonical_resource ) = self.__include_path_canonicalizer.canonicalize( included_file, try_first) self.__count_resolvable[include_specification_type] += 1 return (include_specification_type, canonical_resource) except ResourceUnresolvable: self.__logger.warning( "Include file %s in file %s cannot be resolved exactly" % (included_file, self.__repair_path)) self.__logger.debug("Cause", exc_info=1) self.__count_unresolvable += 1 fuzzy_result = self.__fuzzy_resolver_func(included_file) if fuzzy_result: self.__count_fuzzy += 1 return fuzzy_result else: return (IncludeSpecificationTypes.ANGLE, FileResource( path=PathTools.unix_normpath(included_file)))
def parse_files(self, filenames): for name in filenames: self._current_resource = FileResource(name) for entry in self.parse_lines(open(name, 'r')): yield entry self._current_resource = None