Mock call to os.path.isdir in roll_deps_test.

Bug: b/365524353
Change-Id: I9494a022b18b6c9c240f86a77ec0430cb27149b2
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/362085
Commit-Queue: Björn Terelius <terelius@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#42986}
This commit is contained in:
Björn Terelius 2024-09-09 15:57:17 +02:00 committed by WebRTC LUCI CQ
parent 76aa330c24
commit 0f61f60e46
2 changed files with 18 additions and 4 deletions

View File

@ -189,6 +189,12 @@ def _RunCommand(command,
return std_output, err_output return std_output, err_output
def _IsExistingDir(path):
"""Returns True if `path` exists and is a dir.
"""
return os.path.isdir(path)
def _GetBranches(): def _GetBranches():
"""Returns a tuple of active,branches. """Returns a tuple of active,branches.
@ -620,7 +626,7 @@ def UpdateDepsFile(deps_filename, rev_update, changed_deps, new_cr_content):
if isinstance(dep, ChangedVersionEntry): if isinstance(dep, ChangedVersionEntry):
continue continue
local_dep_dir = os.path.join(GCLIENT_ROOT_DIR, dep.path) local_dep_dir = os.path.join(GCLIENT_ROOT_DIR, dep.path)
if not os.path.isdir(local_dep_dir): if not _IsExistingDir(local_dep_dir):
raise RollError( raise RollError(
'Cannot find local directory %s. Either run\n' 'Cannot find local directory %s. Either run\n'
'gclient sync --deps=all\n' 'gclient sync --deps=all\n'

View File

@ -85,6 +85,13 @@ class NullCmd:
return None, None return None, None
class MockIsExistingDir:
"""Pretends that all paths are valid directories."""
def __call__(self, *args, **kwargs):
return True
class TestRollChromiumRevision(unittest.TestCase): class TestRollChromiumRevision(unittest.TestCase):
def setUp(self): def setUp(self):
@ -134,9 +141,10 @@ class TestRollChromiumRevision(unittest.TestCase):
changed_deps = CalculateChangedDeps(webrtc_deps, new_cr_deps) changed_deps = CalculateChangedDeps(webrtc_deps, new_cr_deps)
with mock.patch('roll_deps._RunCommand', NullCmd()): with mock.patch('roll_deps._RunCommand', NullCmd()):
UpdateDepsFile(self._webrtc_depsfile_android, with mock.patch('roll_deps._IsExistingDir', MockIsExistingDir()):
NO_CHROMIUM_REVISION_UPDATE, changed_deps, UpdateDepsFile(self._webrtc_depsfile_android,
new_cr_contents) NO_CHROMIUM_REVISION_UPDATE, changed_deps,
new_cr_contents)
with open(self._webrtc_depsfile_android, 'rb') as deps_file: with open(self._webrtc_depsfile_android, 'rb') as deps_file:
updated_contents = deps_file.read().decode('utf-8') updated_contents = deps_file.read().decode('utf-8')