Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1486)

Unified Diff: recipe_modules/path/api.py

Issue 2918463002: [recipe_modules/file] add real file module to engine. (Closed)
Patch Set: rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: recipe_modules/path/api.py
diff --git a/recipe_modules/path/api.py b/recipe_modules/path/api.py
index c62586608f0de687fe50655e2007f463eff44864..7fbc21f882bc1338a72aceed758b6bcba1b21775 100644
--- a/recipe_modules/path/api.py
+++ b/recipe_modules/path/api.py
@@ -35,6 +35,8 @@ def string_filter(func):
class path_set(object):
""" implements a set which contains all the parents folders of added folders.
"""
+ # TODO(iannucci): Expand this to be a full fakey filesystem, including file
+ # contents and file types. Coordinate with the `file` module.
def __init__(self, path_mod, initial_paths):
self._path_mod = path_mod
self._initial_paths = set(initial_paths)
@@ -54,6 +56,21 @@ class path_set(object):
self._paths.add(path)
path = self._path_mod.dirname(path)
+ def copy(self, source, dest):
+ source, dest = str(source), str(dest)
+ self._initialize()
+ to_add = set()
+ for p in self._paths:
+ if p.startswith(source):
+ to_add.add(p.replace(source, dest))
+ self._paths |= to_add
+
+ def remove(self, path, filt):
+ path = str(path)
+ self._initialize()
+ kill_set = set(p for p in self._paths if p.startswith(path) and filt(p))
+ self._paths -= kill_set
+
def contains(self, path):
self._initialize()
return self.contains(path)
@@ -91,6 +108,18 @@ class fake_path(object):
"""
self._mock_path_exists.add(path)
+ def mock_copy_paths(self, source, dest):
+ """
+ Duplicates a path and all of its children to another path.
+ """
+ self._mock_path_exists.copy(source, dest)
+
+ def mock_remove_paths(self, path, filt):
+ """
+ Removes a path and all of its children from the set of existing paths.
+ """
+ self._mock_path_exists.remove(path, filt)
+
def exists(self, path): # pylint: disable=E0202
"""Return True if path refers to an existing path."""
return self._mock_path_exists.contains(path)
@@ -240,6 +269,22 @@ class PathApi(recipe_api.RecipeApi):
if self._test_data.enabled:
self._path_mod.mock_add_paths(path)
+ def mock_copy_paths(self, source, dest):
+ """For testing purposes, copy |source| to |dest|."""
+ if self._test_data.enabled:
+ self._path_mod.mock_copy_paths(source, dest)
+
+ def mock_remove_paths(self, path, filt=lambda p: True):
+ """For testing purposes, assert that |path| doesn't exist.
+
+ Args:
+ path (str|Path) - The path to remove.
+ filt (func[str] bool) - Called for every candidate path. Return
+ True to remove this path.
+ """
+ if self._test_data.enabled:
+ self._path_mod.mock_remove_paths(path, filt)
+
def assert_absolute(self, path):
assert self.abspath(path) == str(path), '%s is not absolute' % path

Powered by Google App Engine
This is Rietveld 408576698