def get_canonic_paths(self, include_specification_types): result = set() for include_specification_type in include_specification_types: if include_specification_type == IncludeSpecificationTypes.QUOTED: result.update(self.__canonic_quoted_include_paths) if include_specification_type == IncludeSpecificationTypes.ANGLE: result.update(self.__canonic_angle_include_paths) return PathCanonicalizer.default_canonic_path_list(result)
def __init__(self, quoted_include_paths, angle_include_paths, path_module=os.path, canonic_quoted_include_paths=None, canonic_angle_include_paths=None): """ Angle include paths take precedence over quoted include paths. Therefore, it is not possible to use quoted includes for a directory tree, and angle includes for a subtree of that. You can implement a decorator, which checks for such cases first. @param quoted_include_paths: The base paths to use for quoted include specifications. @param angle_include_paths: The base paths to use for angle include specifications. @param path_module: An object behaving like os.path, defaults to posixpath @param canonic_quoted_include_paths: The list of canonic base paths to use for quoted includes. If None, the default is to use the most paths closest to the root among the quoted_included_paths. In many cases, this may not be what is desired, because this typically includes paths too close to the root, e.g. the top-level path of the local repository. @param canonic_angle_include_paths: Same as canonic_quoted_include_paths for angle includes. """ if not canonic_quoted_include_paths: self.__canonic_quoted_include_paths = PathCanonicalizer.default_canonic_path_list( quoted_include_paths, path_module=path_module) else: self.__canonic_quoted_include_paths = canonic_quoted_include_paths if not canonic_angle_include_paths: self.__canonic_angle_include_paths = PathCanonicalizer.default_canonic_path_list( angle_include_paths, path_module=path_module) else: self.__canonic_angle_include_paths = canonic_angle_include_paths self.__quoted_include_paths_canonicalizer = PathCanonicalizer( input_path_list=quoted_include_paths, canonic_path_list=self.__canonic_quoted_include_paths, path_module=path_module) self.__angle_include_paths_canonicalizer = PathCanonicalizer( input_path_list=angle_include_paths, canonic_path_list=self.__canonic_angle_include_paths, path_module=path_module)
def testSimple(self): canonicalizer = PathCanonicalizer(input_path_list=['/test', '/test/x'], canonic_path_list=['/test'], path_module=MockOsPath( existing_files=['/test/x/y'], decoratee=posixpath)) canonical_resource = canonicalizer.canonical_resource_for_path("y") self.assertEqual("/test/x/y", canonical_resource.name()) self.assertEqual("/test", canonical_resource.get_resolution_root()) canonical_resource = canonicalizer.canonical_resource_for_path("x/y") self.assertEqual("/test/x/y", canonical_resource.name()) self.assertEqual("/test", canonical_resource.get_resolution_root()) canonical_resource = canonicalizer.canonical_resource_for_path( "/test/x/y") self.assertEqual("/test/x/y", canonical_resource.name()) self.assertEqual("/test", canonical_resource.get_resolution_root()) self.assertRaises( ResourceUnresolvable, lambda: canonicalizer.canonical_resource_for_path("test/x/y")) self.assertRaises( ResourceUnresolvable, lambda: canonicalizer.canonical_resource_for_path("z"))
def testUncoveredFail(self): self.assertRaises( ValueError, lambda: PathCanonicalizer(input_path_list=['/test', '/test/x'], canonic_path_list=['/other'], path_module=posixpath))
def testCanonicList3(self): self.assertEqual(['/test', '/test2'], PathCanonicalizer.default_canonic_path_list( ['/test/', '/test2/'], path_module=posixpath))
def testCanonicList0NT(self): self.assertEqual(['D:\\Test', 'E:\\Test'], PathCanonicalizer.default_canonic_path_list( ['D:\\Test', 'E:\\Test'], path_module=ntpath))