aboutsummaryrefslogtreecommitdiff
path: root/infra
diff options
context:
space:
mode:
authorjonathanmetzman <31354670+jonathanmetzman@users.noreply.github.com>2021-08-12 11:25:57 -0700
committerGitHub <noreply@github.com>2021-08-12 11:25:57 -0700
commit01247be731f3a324f66e7ea7683aa57506a4309e (patch)
tree4e37335f75bfa4a2bad489e46d34ff9603e47ef5 /infra
parent5ca8c0e2513a5ed9dbc50375a8b1ad6a55b52555 (diff)
downloadoss-fuzz-01247be731f3a324f66e7ea7683aa57506a4309e.tar.gz
[infra][tests][NFC] Change mocked function prefix from "mocked_" to "mock_" (#6198)
Also rename mock_ functions to have impl suffix so we can use mock_ in place of mocked_
Diffstat (limited to 'infra')
-rw-r--r--infra/base-images/base-builder/bisect_clang_test.py18
-rw-r--r--infra/base-images/base-runner/test_all_test.py4
-rw-r--r--infra/build/functions/request_build_test.py4
-rw-r--r--infra/build/functions/request_coverage_build_test.py6
-rw-r--r--infra/build/functions/update_build_status_test.py51
-rw-r--r--infra/cifuzz/affected_fuzz_targets_test.py4
-rw-r--r--infra/cifuzz/build_fuzzers_test.py8
-rw-r--r--infra/cifuzz/clusterfuzz_deployment_test.py40
-rw-r--r--infra/cifuzz/config_utils_test.py22
-rw-r--r--infra/cifuzz/continuous_integration_test.py8
-rw-r--r--infra/cifuzz/docker_test.py4
-rw-r--r--infra/cifuzz/filestore/github_actions/github_actions_test.py78
-rw-r--r--infra/cifuzz/fuzz_target_test.py25
-rw-r--r--infra/cifuzz/generate_coverage_report_test.py4
-rw-r--r--infra/cifuzz/get_coverage_test.py20
-rw-r--r--infra/cifuzz/http_utils_test.py22
-rw-r--r--infra/cifuzz/run_fuzzers_test.py57
-rw-r--r--infra/cifuzz/stack_parser_test.py8
-rw-r--r--infra/helper_test.py20
-rw-r--r--infra/utils_test.py8
20 files changed, 204 insertions, 207 deletions
diff --git a/infra/base-images/base-builder/bisect_clang_test.py b/infra/base-images/base-builder/bisect_clang_test.py
index edf13e759..a11bf8640 100644
--- a/infra/base-images/base-builder/bisect_clang_test.py
+++ b/infra/base-images/base-builder/bisect_clang_test.py
@@ -127,7 +127,7 @@ def create_mock_popen(
return MockPopen
-def mock_prepare_build(llvm_project_path): # pylint: disable=unused-argument
+def mock_prepare_build_impl(llvm_project_path): # pylint: disable=unused-argument
"""Mocked prepare_build function."""
return '/work/llvm-build'
@@ -138,7 +138,7 @@ class BuildClangTest(BisectClangTestMixin, unittest.TestCase):
def test_build_clang_test(self):
"""Tests that build_clang works as intended."""
with mock.patch('subprocess.Popen', create_mock_popen()) as mock_popen:
- with mock.patch('bisect_clang.prepare_build', mock_prepare_build):
+ with mock.patch('bisect_clang.prepare_build', mock_prepare_build_impl):
llvm_src_dir = '/src/llvm-project'
bisect_clang.build_clang(llvm_src_dir)
self.assertEqual([['ninja', '-C', '/work/llvm-build', 'install']],
@@ -170,13 +170,13 @@ class GitRepoTest(BisectClangTestMixin, unittest.TestCase):
"""Tests test_start_commit works as intended when the test returns an
unexpected value."""
- def mock_execute(command, *args, **kwargs): # pylint: disable=unused-argument
+ def mock_execute_impl(command, *args, **kwargs): # pylint: disable=unused-argument
if command == self.test_command:
return returncode, '', ''
return 0, '', ''
- with mock.patch('bisect_clang.execute', mock_execute):
- with mock.patch('bisect_clang.prepare_build', mock_prepare_build):
+ with mock.patch('bisect_clang.execute', mock_execute_impl):
+ with mock.patch('bisect_clang.prepare_build', mock_prepare_build_impl):
with self.assertRaises(bisect_clang.BisectError):
self.git.test_start_commit(commit, label, self.test_command)
@@ -202,13 +202,13 @@ class GitRepoTest(BisectClangTestMixin, unittest.TestCase):
expected value."""
command_args = []
- def mock_execute(command, *args, **kwargs): # pylint: disable=unused-argument
+ def mock_execute_impl(command, *args, **kwargs): # pylint: disable=unused-argument
command_args.append(command)
if command == self.test_command:
return returncode, '', ''
return 0, '', ''
- with mock.patch('bisect_clang.execute', mock_execute):
+ with mock.patch('bisect_clang.execute', mock_execute_impl):
self.git.test_start_commit(commit, label, self.test_command)
self.assertEqual([
get_git_command('checkout', commit), self.test_command,
@@ -247,13 +247,13 @@ class GitRepoTest(BisectClangTestMixin, unittest.TestCase):
"""Test test_commit works as intended."""
command_args = []
- def mock_execute(command, *args, **kwargs): # pylint: disable=unused-argument
+ def mock_execute_impl(command, *args, **kwargs): # pylint: disable=unused-argument
command_args.append(command)
if command == self.test_command:
return returncode, output, ''
return 0, output, ''
- with mock.patch('bisect_clang.execute', mock_execute):
+ with mock.patch('bisect_clang.execute', mock_execute_impl):
result = self.git.test_commit(self.test_command)
self.assertEqual([self.test_command,
get_git_command('bisect', label)], command_args)
diff --git a/infra/base-images/base-runner/test_all_test.py b/infra/base-images/base-runner/test_all_test.py
index 0cd067afc..b3077ec1e 100644
--- a/infra/base-images/base-runner/test_all_test.py
+++ b/infra/base-images/base-runner/test_all_test.py
@@ -25,13 +25,13 @@ class TestTestAll(unittest.TestCase):
@mock.patch('test_all.find_fuzz_targets', return_value=[])
@mock.patch('builtins.print')
- def test_test_all_no_fuzz_targets(self, mocked_print, _):
+ def test_test_all_no_fuzz_targets(self, mock_print, _):
"""Tests that test_all returns False when there are no fuzz targets."""
outdir = '/out'
allowed_broken_targets_percentage = 0
self.assertFalse(
test_all.test_all(outdir, allowed_broken_targets_percentage))
- mocked_print.assert_called_with('ERROR: No fuzz targets found.')
+ mock_print.assert_called_with('ERROR: No fuzz targets found.')
if __name__ == '__main__':
diff --git a/infra/build/functions/request_build_test.py b/infra/build/functions/request_build_test.py
index 50e8eec2b..146dad48e 100644
--- a/infra/build/functions/request_build_test.py
+++ b/infra/build/functions/request_build_test.py
@@ -52,9 +52,9 @@ class TestRequestBuilds(unittest.TestCase):
@mock.patch('build_lib.get_signed_url', return_value='test_url')
@mock.patch('datetime.datetime')
- def test_get_build_steps(self, mocked_url, mocked_time):
+ def test_get_build_steps(self, mock_url, mock_time):
"""Test for get_build_steps."""
- del mocked_url, mocked_time
+ del mock_url, mock_time
datetime.datetime = test_utils.SpoofedDatetime
project_yaml_contents = ('language: c++\n'
'sanitizers:\n'
diff --git a/infra/build/functions/request_coverage_build_test.py b/infra/build/functions/request_coverage_build_test.py
index 78d1d0f1f..2e81e6ae7 100644
--- a/infra/build/functions/request_coverage_build_test.py
+++ b/infra/build/functions/request_coverage_build_test.py
@@ -53,10 +53,10 @@ class TestRequestCoverageBuilds(unittest.TestCase):
'url': 'test_download'
}])
@mock.patch('datetime.datetime')
- def test_get_coverage_build_steps(self, mocked_url, mocked_corpora_steps,
- mocked_time):
+ def test_get_coverage_build_steps(self, mock_url, mock_corpora_steps,
+ mock_time):
"""Test for get_build_steps."""
- del mocked_url, mocked_corpora_steps, mocked_time
+ del mock_url, mock_corpora_steps, mock_time
datetime.datetime = test_utils.SpoofedDatetime
project_yaml_contents = ('language: c++\n'
'sanitizers:\n'
diff --git a/infra/build/functions/update_build_status_test.py b/infra/build/functions/update_build_status_test.py
index 6784fac2d..24a32f676 100644
--- a/infra/build/functions/update_build_status_test.py
+++ b/infra/build/functions/update_build_status_test.py
@@ -56,14 +56,14 @@ class MockGetBuild:
class TestGetBuildHistory(unittest.TestCase):
"""Unit tests for get_build_history."""
- def test_get_build_history(self, mocked_upload_log, mocked_cloud_build,
- mocked_google_auth):
+ def test_get_build_history(self, mock_upload_log, mock_cloud_build,
+ mock_google_auth):
"""Test for get_build_steps."""
- del mocked_cloud_build, mocked_google_auth
- mocked_upload_log.return_value = True
+ del mock_cloud_build, mock_google_auth
+ mock_upload_log.return_value = True
builds = [{'build_id': '1', 'finishTime': 'test_time', 'status': 'SUCCESS'}]
- mocked_get_build = MockGetBuild(builds)
- update_build_status.get_build = mocked_get_build.get_build
+ mock_get_build = MockGetBuild(builds)
+ update_build_status.get_build = mock_get_build.get_build
expected_projects = {
'history': [{
@@ -79,27 +79,26 @@ class TestGetBuildHistory(unittest.TestCase):
self.assertDictEqual(update_build_status.get_build_history(['1']),
expected_projects)
- def test_get_build_history_missing_log(self, mocked_upload_log,
- mocked_cloud_build,
- mocked_google_auth):
+ def test_get_build_history_missing_log(self, mock_upload_log,
+ mock_cloud_build, mock_google_auth):
"""Test for missing build log file."""
- del mocked_cloud_build, mocked_google_auth
+ del mock_cloud_build, mock_google_auth
builds = [{'build_id': '1', 'finishTime': 'test_time', 'status': 'SUCCESS'}]
- mocked_get_build = MockGetBuild(builds)
- update_build_status.get_build = mocked_get_build.get_build
- mocked_upload_log.return_value = False
+ mock_get_build = MockGetBuild(builds)
+ update_build_status.get_build = mock_get_build.get_build
+ mock_upload_log.return_value = False
self.assertRaises(update_build_status.MissingBuildLogError,
update_build_status.get_build_history, ['1'])
- def test_get_build_history_no_last_success(self, mocked_upload_log,
- mocked_cloud_build,
- mocked_google_auth):
+ def test_get_build_history_no_last_success(self, mock_upload_log,
+ mock_cloud_build,
+ mock_google_auth):
"""Test when there is no last successful build."""
- del mocked_cloud_build, mocked_google_auth
+ del mock_cloud_build, mock_google_auth
builds = [{'build_id': '1', 'finishTime': 'test_time', 'status': 'FAILURE'}]
- mocked_get_build = MockGetBuild(builds)
- update_build_status.get_build = mocked_get_build.get_build
- mocked_upload_log.return_value = True
+ mock_get_build = MockGetBuild(builds)
+ update_build_status.get_build = mock_get_build.get_build
+ mock_upload_log.return_value = True
expected_projects = {
'history': [{
@@ -229,12 +228,12 @@ class TestUpdateBuildStatus(unittest.TestCase):
@mock.patch('google.auth.default', return_value=['temp', 'temp'])
@mock.patch('update_build_status.build', return_value='cloudbuild')
@mock.patch('update_build_status.upload_log')
- def test_update_build_status(self, mocked_upload_log, mocked_cloud_build,
- mocked_google_auth):
+ def test_update_build_status(self, mock_upload_log, mock_cloud_build,
+ mock_google_auth):
"""Testing update build status as a whole."""
- del self, mocked_cloud_build, mocked_google_auth
+ del self, mock_cloud_build, mock_google_auth
update_build_status.upload_status = MagicMock()
- mocked_upload_log.return_value = True
+ mock_upload_log.return_value = True
status_filename = 'status.json'
with ndb.Client().context():
BuildsHistory(id='test-project-1-fuzzing',
@@ -264,8 +263,8 @@ class TestUpdateBuildStatus(unittest.TestCase):
'build_id': '3',
'status': 'WORKING'
}]
- mocked_get_build = MockGetBuild(builds)
- update_build_status.get_build = mocked_get_build.get_build
+ mock_get_build = MockGetBuild(builds)
+ update_build_status.get_build = mock_get_build.get_build
expected_data = {
'projects': [{
diff --git a/infra/cifuzz/affected_fuzz_targets_test.py b/infra/cifuzz/affected_fuzz_targets_test.py
index 121e0d881..823654d11 100644
--- a/infra/cifuzz/affected_fuzz_targets_test.py
+++ b/infra/cifuzz/affected_fuzz_targets_test.py
@@ -72,10 +72,10 @@ class RemoveUnaffectedFuzzTargets(unittest.TestCase):
# being set, which doesn't work properly in fakefs.
with tempfile.TemporaryDirectory() as tmp_dir, mock.patch(
'get_coverage.OSSFuzzCoverage.get_files_covered_by_target'
- ) as mocked_get_files:
+ ) as mock_get_files:
with mock.patch('get_coverage._get_oss_fuzz_fuzzer_stats_dir_url',
return_value=1):
- mocked_get_files.side_effect = side_effect
+ mock_get_files.side_effect = side_effect
shutil.copy(self.TEST_FUZZER_1, tmp_dir)
shutil.copy(self.TEST_FUZZER_2, tmp_dir)
diff --git a/infra/cifuzz/build_fuzzers_test.py b/infra/cifuzz/build_fuzzers_test.py
index e2d65002b..52e17aa89 100644
--- a/infra/cifuzz/build_fuzzers_test.py
+++ b/infra/cifuzz/build_fuzzers_test.py
@@ -64,7 +64,7 @@ class BuildFuzzersTest(unittest.TestCase):
@mock.patch('repo_manager._clone', return_value=None)
@mock.patch('continuous_integration.checkout_specified_commit')
@mock.patch('helper.docker_run', return_value=False) # We want to quit early.
- def test_cifuzz_env_var(self, mocked_docker_run, _, __, ___):
+ def test_cifuzz_env_var(self, mock_docker_run, _, __, ___):
"""Tests that the CIFUZZ env var is set."""
with tempfile.TemporaryDirectory() as tmp_dir:
@@ -75,7 +75,7 @@ class BuildFuzzersTest(unittest.TestCase):
workspace=tmp_dir,
pr_ref='refs/pull/1757/merge'))
- docker_run_command = mocked_docker_run.call_args_list[0][0][0]
+ docker_run_command = mock_docker_run.call_args_list[0][0][0]
def command_has_env_var_arg(command, env_var_arg):
for idx, element in enumerate(command):
@@ -296,14 +296,14 @@ class CheckFuzzerBuildTest(unittest.TestCase):
self.assertFalse(build_fuzzers.check_fuzzer_build(self.config))
@mock.patch('utils.execute', return_value=(None, None, 0))
- def test_allow_broken_fuzz_targets_percentage(self, mocked_execute):
+ def test_allow_broken_fuzz_targets_percentage(self, mock_execute):
"""Tests that ALLOWED_BROKEN_TARGETS_PERCENTAGE is set when running
docker if passed to check_fuzzer_build."""
percentage = '0'
self.config.allowed_broken_targets_percentage = percentage
build_fuzzers.check_fuzzer_build(self.config)
self.assertEqual(
- mocked_execute.call_args[1]['env']['ALLOWED_BROKEN_TARGETS_PERCENTAGE'],
+ mock_execute.call_args[1]['env']['ALLOWED_BROKEN_TARGETS_PERCENTAGE'],
percentage)
diff --git a/infra/cifuzz/clusterfuzz_deployment_test.py b/infra/cifuzz/clusterfuzz_deployment_test.py
index 3d3f0fe2c..29a864d5b 100644
--- a/infra/cifuzz/clusterfuzz_deployment_test.py
+++ b/infra/cifuzz/clusterfuzz_deployment_test.py
@@ -68,13 +68,13 @@ class OSSFuzzTest(fake_filesystem_unittest.TestCase):
EXAMPLE_FUZZER)
@mock.patch('http_utils.download_and_unpack_zip', return_value=True)
- def test_download_corpus(self, mocked_download_and_unpack_zip):
+ def test_download_corpus(self, mock_download_and_unpack_zip):
"""Tests that we can download a corpus for a valid project."""
self.deployment.download_corpus(EXAMPLE_FUZZER, self.corpus_dir)
expected_url = ('https://storage.googleapis.com/example-backup.'
'clusterfuzz-external.appspot.com/corpus/libFuzzer/'
'example_crash_fuzzer/public.zip')
- call_args, _ = mocked_download_and_unpack_zip.call_args
+ call_args, _ = mock_download_and_unpack_zip.call_args
self.assertEqual(call_args, (expected_url, self.corpus_dir))
self.assertTrue(os.path.exists(self.corpus_dir))
@@ -100,21 +100,21 @@ class OSSFuzzTest(fake_filesystem_unittest.TestCase):
])
def test_noop_methods(self, method, method_args, expected_message):
"""Tests that certain methods are noops for OSS-Fuzz."""
- with mock.patch('logging.info') as mocked_info:
+ with mock.patch('logging.info') as mock_info:
method = getattr(self.deployment, method)
self.assertIsNone(method(*method_args))
- mocked_info.assert_called_with(expected_message)
+ mock_info.assert_called_with(expected_message)
@mock.patch('http_utils.download_and_unpack_zip', return_value=True)
- def test_download_latest_build(self, mocked_download_and_unpack_zip):
+ def test_download_latest_build(self, mock_download_and_unpack_zip):
"""Tests that downloading the latest build works as intended under normal
circumstances."""
self.assertEqual(self.deployment.download_latest_build(),
EXPECTED_LATEST_BUILD_PATH)
expected_url = ('https://storage.googleapis.com/clusterfuzz-builds/example/'
'example-address-202008030600.zip')
- mocked_download_and_unpack_zip.assert_called_with(
- expected_url, EXPECTED_LATEST_BUILD_PATH)
+ mock_download_and_unpack_zip.assert_called_with(expected_url,
+ EXPECTED_LATEST_BUILD_PATH)
@mock.patch('http_utils.download_and_unpack_zip', return_value=False)
def test_download_latest_build_fail(self, _):
@@ -136,11 +136,11 @@ class ClusterFuzzLiteTest(fake_filesystem_unittest.TestCase):
@mock.patch('filestore.github_actions.GithubActionsFilestore.download_corpus',
return_value=True)
- def test_download_corpus(self, mocked_download_corpus):
+ def test_download_corpus(self, mock_download_corpus):
"""Tests that download_corpus works for a valid project."""
self.deployment.download_corpus(EXAMPLE_FUZZER, self.corpus_dir)
- mocked_download_corpus.assert_called_with('example_crash_fuzzer',
- self.corpus_dir)
+ mock_download_corpus.assert_called_with('example_crash_fuzzer',
+ self.corpus_dir)
self.assertTrue(os.path.exists(self.corpus_dir))
@mock.patch('filestore.github_actions.GithubActionsFilestore.download_corpus',
@@ -153,14 +153,14 @@ class ClusterFuzzLiteTest(fake_filesystem_unittest.TestCase):
@mock.patch('filestore.github_actions.GithubActionsFilestore.download_build',
return_value=True)
- def test_download_latest_build(self, mocked_download_build):
+ def test_download_latest_build(self, mock_download_build):
"""Tests that downloading the latest build works as intended under normal
circumstances."""
self.assertEqual(self.deployment.download_latest_build(),
EXPECTED_LATEST_BUILD_PATH)
expected_artifact_name = 'address-latest'
- mocked_download_build.assert_called_with(expected_artifact_name,
- EXPECTED_LATEST_BUILD_PATH)
+ mock_download_build.assert_called_with(expected_artifact_name,
+ EXPECTED_LATEST_BUILD_PATH)
@mock.patch('filestore.github_actions.GithubActionsFilestore.download_build',
side_effect=Exception)
@@ -170,11 +170,11 @@ class ClusterFuzzLiteTest(fake_filesystem_unittest.TestCase):
self.assertIsNone(self.deployment.download_latest_build())
@mock.patch('filestore.github_actions.GithubActionsFilestore.' 'upload_build')
- def test_upload_latest_build(self, mocked_upload_build):
+ def test_upload_latest_build(self, mock_upload_build):
"""Tests that upload_latest_build works as intended."""
self.deployment.upload_latest_build()
- mocked_upload_build.assert_called_with('address-latest',
- '/workspace/build-out')
+ mock_upload_build.assert_called_with('address-latest',
+ '/workspace/build-out')
class NoClusterFuzzDeploymentTest(fake_filesystem_unittest.TestCase):
@@ -190,11 +190,11 @@ class NoClusterFuzzDeploymentTest(fake_filesystem_unittest.TestCase):
self.corpus_dir = os.path.join(workspace.corpora, EXAMPLE_FUZZER)
@mock.patch('logging.info')
- def test_download_corpus(self, mocked_info):
+ def test_download_corpus(self, mock_info):
"""Tests that download corpus returns the path to the empty corpus
directory."""
self.deployment.download_corpus(EXAMPLE_FUZZER, self.corpus_dir)
- mocked_info.assert_called_with(
+ mock_info.assert_called_with(
'Not downloading corpus because no ClusterFuzz deployment.')
self.assertTrue(os.path.exists(self.corpus_dir))
@@ -210,10 +210,10 @@ class NoClusterFuzzDeploymentTest(fake_filesystem_unittest.TestCase):
])
def test_noop_methods(self, method, method_args, expected_message):
"""Tests that certain methods are noops for NoClusterFuzzDeployment."""
- with mock.patch('logging.info') as mocked_info:
+ with mock.patch('logging.info') as mock_info:
method = getattr(self.deployment, method)
self.assertIsNone(method(*method_args))
- mocked_info.assert_called_with(expected_message)
+ mock_info.assert_called_with(expected_message)
class GetClusterFuzzDeploymentTest(unittest.TestCase):
diff --git a/infra/cifuzz/config_utils_test.py b/infra/cifuzz/config_utils_test.py
index a8da59ad8..32499bfd0 100644
--- a/infra/cifuzz/config_utils_test.py
+++ b/infra/cifuzz/config_utils_test.py
@@ -57,35 +57,35 @@ class BaseConfigTest(unittest.TestCase):
self.assertFalse(config.is_coverage)
@mock.patch('logging.error')
- def test_validate_no_workspace(self, mocked_error):
+ def test_validate_no_workspace(self, mock_error):
"""Tests that validate returns False if GITHUB_WORKSPACE isn't set."""
os.environ['OSS_FUZZ_PROJECT_NAME'] = 'example'
config = self._create_config()
self.assertFalse(config.validate())
- mocked_error.assert_called_with('Must set WORKSPACE.')
+ mock_error.assert_called_with('Must set WORKSPACE.')
@mock.patch('logging.error')
- def test_validate_invalid_language(self, mocked_error):
+ def test_validate_invalid_language(self, mock_error):
"""Tests that validate returns False if GITHUB_WORKSPACE isn't set."""
os.environ['OSS_FUZZ_PROJECT_NAME'] = 'example'
os.environ['WORKSPACE'] = '/workspace'
os.environ['LANGUAGE'] = 'invalid-language'
config = self._create_config()
self.assertFalse(config.validate())
- mocked_error.assert_called_with('Invalid LANGUAGE: %s. Must be one of: %s.',
- os.environ['LANGUAGE'], constants.LANGUAGES)
+ mock_error.assert_called_with('Invalid LANGUAGE: %s. Must be one of: %s.',
+ os.environ['LANGUAGE'], constants.LANGUAGES)
@mock.patch('logging.error')
- def test_validate_invalid_sanitizer(self, mocked_error):
+ def test_validate_invalid_sanitizer(self, mock_error):
"""Tests that validate returns False if GITHUB_WORKSPACE isn't set."""
os.environ['OSS_FUZZ_PROJECT_NAME'] = 'example'
os.environ['WORKSPACE'] = '/workspace'
os.environ['SANITIZER'] = 'invalid-sanitizer'
config = self._create_config()
self.assertFalse(config.validate())
- mocked_error.assert_called_with(
- 'Invalid SANITIZER: %s. Must be one of: %s.', os.environ['SANITIZER'],
- config_utils.SANITIZERS)
+ mock_error.assert_called_with('Invalid SANITIZER: %s. Must be one of: %s.',
+ os.environ['SANITIZER'],
+ config_utils.SANITIZERS)
def test_validate(self):
"""Tests that validate returns True if config is valid."""
@@ -154,13 +154,13 @@ class RunFuzzersConfigTest(unittest.TestCase):
self.assertTrue(self._create_config()._run_config_validate())
@mock.patch('logging.error')
- def test_run_config_invalid_mode(self, mocked_error):
+ def test_run_config_invalid_mode(self, mock_error):
"""Tests that _run_config_validate returns False when run_fuzzers_mode is
invalid."""
fake_mode = 'fake-mode'
os.environ['RUN_FUZZERS_MODE'] = fake_mode
self.assertFalse(self._create_config()._run_config_validate())
- mocked_error.assert_called_with(
+ mock_error.assert_called_with(
'Invalid RUN_FUZZERS_MODE: %s. Must be one of %s.', fake_mode,
config_utils.RUN_FUZZERS_MODES)
diff --git a/infra/cifuzz/continuous_integration_test.py b/infra/cifuzz/continuous_integration_test.py
index aa530532e..7c7e3eefd 100644
--- a/infra/cifuzz/continuous_integration_test.py
+++ b/infra/cifuzz/continuous_integration_test.py
@@ -31,7 +31,7 @@ class FixGitRepoForDiffTest(unittest.TestCase):
"""Tests for fix_git_repo_for_diff."""
@mock.patch('utils.execute')
- def test_fix_git_repo_for_diff(self, mocked_execute):
+ def test_fix_git_repo_for_diff(self, mock_execute):
"""Tests that fix_git_repo_for_diff works as intended."""
repo_dir = '/dir'
repo_manager_obj = repo_manager.RepoManager(repo_dir)
@@ -41,7 +41,7 @@ class FixGitRepoForDiffTest(unittest.TestCase):
'refs/remotes/origin/master'
]
- mocked_execute.assert_called_with(expected_command, location=repo_dir)
+ mock_execute.assert_called_with(expected_command, location=repo_dir)
class GetBuildCommand(unittest.TestCase):
@@ -71,14 +71,14 @@ class BuildExternalProjetDockerImage(unittest.TestCase):
"""Tests for build_external_project_docker_image."""
@mock.patch('helper.docker_build')
- def test_build_external_project_docker_image(self, mocked_docker_build):
+ def test_build_external_project_docker_image(self, mock_docker_build):
"""Tests that build_external_project_docker_image works as intended."""
build_integration_path = '.clusterfuzzlite'
project_src = '/path/to/project/src'
continuous_integration.build_external_project_docker_image(
project_src, build_integration_path)
- mocked_docker_build.assert_called_with([
+ mock_docker_build.assert_called_with([
'-t', 'external-project', '-f',
os.path.join('.clusterfuzzlite', 'Dockerfile'), project_src
])
diff --git a/infra/cifuzz/docker_test.py b/infra/cifuzz/docker_test.py
index 16a0f94e7..b356138cb 100644
--- a/infra/cifuzz/docker_test.py
+++ b/infra/cifuzz/docker_test.py
@@ -42,7 +42,7 @@ class GetDeleteImagesTest(unittest.TestCase):
"""Tests for delete_images."""
@mock.patch('utils.execute')
- def test_delete_images(self, mocked_execute): # pylint: disable=no-self-use
+ def test_delete_images(self, mock_execute): # pylint: disable=no-self-use
"""Tests that get_project_image_name works as intended."""
images = ['image']
docker.delete_images(images)
@@ -51,7 +51,7 @@ class GetDeleteImagesTest(unittest.TestCase):
mock.call(['docker', 'builder', 'prune', '-f'])
]
- mocked_execute.assert_has_calls(expected_calls)
+ mock_execute.assert_has_calls(expected_calls)
class GetBaseDockerRunArgsTest(unittest.TestCase):
diff --git a/infra/cifuzz/filestore/github_actions/github_actions_test.py b/infra/cifuzz/filestore/github_actions/github_actions_test.py
index e72ffe0fc..01d977715 100644
--- a/infra/cifuzz/filestore/github_actions/github_actions_test.py
+++ b/infra/cifuzz/filestore/github_actions/github_actions_test.py
@@ -55,122 +55,121 @@ class GithubActionsFilestoreTest(fake_filesystem_unittest.TestCase):
}
@mock.patch('filestore.github_actions.github_api.list_artifacts')
- def test_list_artifacts(self, mocked_list_artifacts):
+ def test_list_artifacts(self, mock_list_artifacts):
"""Tests that _list_artifacts works as intended."""
filestore = github_actions.GithubActionsFilestore(self.config)
filestore._list_artifacts()
- mocked_list_artifacts.assert_called_with(self.owner, self.repo,
- self._get_expected_http_headers())
+ mock_list_artifacts.assert_called_with(self.owner, self.repo,
+ self._get_expected_http_headers())
@mock.patch('logging.warning')
@mock.patch('filestore.github_actions.GithubActionsFilestore._list_artifacts',
return_value=None)
@mock.patch('filestore.github_actions.github_api.find_artifact',
return_value=None)
- def test_download_build_no_artifact(self, _, __, mocked_warning):
+ def test_download_build_no_artifact(self, _, __, mock_warning):
"""Tests that download_build returns None and doesn't exception when
find_artifact can't find an artifact."""
filestore = github_actions.GithubActionsFilestore(self.config)
name = 'name'
build_dir = 'build-dir'
self.assertFalse(filestore.download_build(name, build_dir))
- mocked_warning.assert_called_with('Could not download artifact: %s.',
- 'cifuzz-build-' + name)
+ mock_warning.assert_called_with('Could not download artifact: %s.',
+ 'cifuzz-build-' + name)
@mock.patch('logging.warning')
@mock.patch('filestore.github_actions.GithubActionsFilestore._list_artifacts',
return_value=None)
@mock.patch('filestore.github_actions.github_api.find_artifact',
return_value=None)
- def test_download_corpus_no_artifact(self, _, __, mocked_warning):
+ def test_download_corpus_no_artifact(self, _, __, mock_warning):
"""Tests that download_corpus_build returns None and doesn't exception when
find_artifact can't find an artifact."""
filestore = github_actions.GithubActionsFilestore(self.config)
name = 'name'
dst_dir = 'local-dir'
self.assertFalse(filestore.download_corpus(name, dst_dir))
- mocked_warning.assert_called_with('Could not download artifact: %s.',
- 'cifuzz-corpus-' + name)
+ mock_warning.assert_called_with('Could not download artifact: %s.',
+ 'cifuzz-corpus-' + name)
@mock.patch('filestore.github_actions.tar_directory')
@mock.patch('third_party.github_actions_toolkit.artifact.artifact_client'
'.upload_artifact')
- def test_upload_corpus(self, mocked_upload_artifact, mocked_tar_directory):
+ def test_upload_corpus(self, mock_upload_artifact, mock_tar_directory):
"""Test uploading corpus."""
self._create_local_dir()
- def mock_tar_directory(_, archive_path):
+ def mock_tar_directory_impl(_, archive_path):
self.fs.create_file(archive_path)
- mocked_tar_directory.side_effect = mock_tar_directory
+ mock_tar_directory.side_effect = mock_tar_directory_impl
filestore = github_actions.GithubActionsFilestore(self.config)
filestore.upload_corpus('target', self.local_dir)
- self.assert_upload(mocked_upload_artifact, mocked_tar_directory,
+ self.assert_upload(mock_upload_artifact, mock_tar_directory,
'corpus-target')
@mock.patch('third_party.github_actions_toolkit.artifact.artifact_client'
'.upload_artifact')
- def test_upload_crashes(self, mocked_upload_artifact):
+ def test_upload_crashes(self, mock_upload_artifact):
"""Test uploading crashes."""
self._create_local_dir()
filestore = github_actions.GithubActionsFilestore(self.config)
filestore.upload_crashes('current', self.local_dir)
- mocked_upload_artifact.assert_has_calls(
+ mock_upload_artifact.assert_has_calls(
[mock.call('crashes-current', ['/local-dir/testcase'], '/local-dir')])
@mock.patch('filestore.github_actions.tar_directory')
@mock.patch('third_party.github_actions_toolkit.artifact.artifact_client'
'.upload_artifact')
- def test_upload_build(self, mocked_upload_artifact, mocked_tar_directory):
+ def test_upload_build(self, mock_upload_artifact, mock_tar_directory):
"""Test uploading build."""
self._create_local_dir()
- def mock_tar_directory(_, archive_path):
+ def mock_tar_directory_impl(_, archive_path):
self.fs.create_file(archive_path)
- mocked_tar_directory.side_effect = mock_tar_directory
+ mock_tar_directory.side_effect = mock_tar_directory_impl
filestore = github_actions.GithubActionsFilestore(self.config)
filestore.upload_build('sanitizer', self.local_dir)
- self.assert_upload(mocked_upload_artifact, mocked_tar_directory,
+ self.assert_upload(mock_upload_artifact, mock_tar_directory,
'build-sanitizer')
@mock.patch('filestore.github_actions.tar_directory')
@mock.patch('third_party.github_actions_toolkit.artifact.artifact_client'
'.upload_artifact')
- def test_upload_coverage(self, mocked_upload_artifact, mocked_tar_directory):
+ def test_upload_coverage(self, mock_upload_artifact, mock_tar_directory):
"""Test uploading coverage."""
self._create_local_dir()
- def mock_tar_directory(_, archive_path):
+ def mock_tar_directory_impl(_, archive_path):
self.fs.create_file(archive_path)
- mocked_tar_directory.side_effect = mock_tar_directory
+ mock_tar_directory.side_effect = mock_tar_directory_impl
filestore = github_actions.GithubActionsFilestore(self.config)
filestore.upload_coverage('latest', self.local_dir)
- self.assert_upload(mocked_upload_artifact, mocked_tar_directory,
+ self.assert_upload(mock_upload_artifact, mock_tar_directory,
'coverage-latest')
- def assert_upload(self, mocked_upload_artifact, mocked_tar_directory,
+ def assert_upload(self, mock_upload_artifact, mock_tar_directory,
expected_artifact_name):
"""Tests that upload_directory invokes tar_directory and
artifact_client.upload_artifact properly."""
# Don't assert what second argument will be since it's a temporary
# directory.
- self.assertEqual(mocked_tar_directory.call_args_list[0][0][0],
- self.local_dir)
+ self.assertEqual(mock_tar_directory.call_args_list[0][0][0], self.local_dir)
# Don't assert what second and third arguments will be since they are
# temporary directories.
expected_artifact_name = 'cifuzz-' + expected_artifact_name
- self.assertEqual(mocked_upload_artifact.call_args_list[0][0][0],
+ self.assertEqual(mock_upload_artifact.call_args_list[0][0][0],
expected_artifact_name)
# Assert artifacts list contains one tarfile.
- artifacts_list = mocked_upload_artifact.call_args_list[0][0][1]
+ artifacts_list = mock_upload_artifact.call_args_list[0][0][1]
self.assertEqual(len(artifacts_list), 1)
self.assertEqual(os.path.basename(artifacts_list[0]),
expected_artifact_name + '.tar')
@@ -183,8 +182,8 @@ class GithubActionsFilestoreTest(fake_filesystem_unittest.TestCase):
@mock.patch('filestore.github_actions.GithubActionsFilestore._find_artifact')
@mock.patch('http_utils.download_and_unpack_zip')
- def test_download_artifact(self, mocked_download_and_unpack_zip,
- mocked_find_artifact):
+ def test_download_artifact(self, mock_download_and_unpack_zip,
+ mock_find_artifact):
"""Tests that _download_artifact works as intended."""
artifact_download_url = 'http://example.com/download'
artifact_listing = {
@@ -192,7 +191,7 @@ class GithubActionsFilestoreTest(fake_filesystem_unittest.TestCase):
'name': 'corpus',
'archive_download_url': artifact_download_url
}
- mocked_find_artifact.return_value = artifact_listing
+ mock_find_artifact.return_value = artifact_listing
self._create_local_dir()
with tempfile.TemporaryDirectory() as temp_dir:
@@ -203,8 +202,8 @@ class GithubActionsFilestoreTest(fake_filesystem_unittest.TestCase):
artifact_download_dst_dir = os.path.join(temp_dir, 'dst')
os.mkdir(artifact_download_dst_dir)
- def mock_download_and_unpack_zip(url, download_artifact_temp_dir,
- headers):
+ def mock_download_and_unpack_zip_impl(url, download_artifact_temp_dir,
+ headers):
self.assertEqual(url, artifact_download_url)
self.assertEqual(headers, self._get_expected_http_headers())
shutil.copy(
@@ -213,18 +212,19 @@ class GithubActionsFilestoreTest(fake_filesystem_unittest.TestCase):
os.path.basename(archive_path)))
return True
- mocked_download_and_unpack_zip.side_effect = mock_download_and_unpack_zip
+ mock_download_and_unpack_zip.side_effect = (
+ mock_download_and_unpack_zip_impl)
filestore = github_actions.GithubActionsFilestore(self.config)
self.assertTrue(
filestore._download_artifact('corpus', artifact_download_dst_dir))
- mocked_find_artifact.assert_called_with('cifuzz-corpus')
+ mock_find_artifact.assert_called_with('cifuzz-corpus')
self.assertTrue(
os.path.exists(
os.path.join(artifact_download_dst_dir,
os.path.basename(self.testcase))))
@mock.patch('filestore.github_actions.github_api.list_artifacts')
- def test_find_artifact(self, mocked_list_artifacts):
+ def test_find_artifact(self, mock_list_artifacts):
"""Tests that _find_artifact works as intended."""
artifact_listing_1 = {
'expired': False,
@@ -250,13 +250,13 @@ class GithubActionsFilestoreTest(fake_filesystem_unittest.TestCase):
artifact_listing_1, artifact_listing_2, artifact_listing_3,
artifact_listing_4
]
- mocked_list_artifacts.return_value = artifacts
+ mock_list_artifacts.return_value = artifacts
filestore = github_actions.GithubActionsFilestore(self.config)
# Test that find_artifact will return the most recent unexpired artifact
# with the correct name.
self.assertEqual(filestore._find_artifact('artifact'), artifact_listing_2)
- mocked_list_artifacts.assert_called_with(self.owner, self.repo,
- self._get_expected_http_headers())
+ mock_list_artifacts.assert_called_with(self.owner, self.repo,
+ self._get_expected_http_headers())
class TarDirectoryTest(unittest.TestCase):
diff --git a/infra/cifuzz/fuzz_target_test.py b/infra/cifuzz/fuzz_target_test.py
index ee262edad..25835b728 100644
--- a/infra/cifuzz/fuzz_target_test.py
+++ b/infra/cifuzz/fuzz_target_test.py
@@ -91,7 +91,7 @@ class IsReproducibleTest(fake_filesystem_unittest.TestCase):
"""Tests that is_reproducible returns True if crash is detected and that
is_reproducible uses the correct command to reproduce a crash."""
all_repro = [EXECUTE_FAILURE_RETVAL] * fuzz_target.REPRODUCE_ATTEMPTS
- with mock.patch('utils.execute', side_effect=all_repro) as mocked_execute:
+ with mock.patch('utils.execute', side_effect=all_repro) as mock_execute:
result = self.target.is_reproducible(self.testcase_path,
self.fuzz_target_path)
expected_command = ['reproduce', 'fuzz-target', '-runs=100']
@@ -105,21 +105,20 @@ class IsReproducibleTest(fake_filesystem_unittest.TestCase):
'TESTCASE': self.testcase_path,
'FUZZER_ARGS': '-rss_limit_mb=2560 -timeout=25'
}
- mocked_execute.assert_called_once_with(expected_command, env=expected_env)
+ mock_execute.assert_called_once_with(expected_command, env=expected_env)
self.assertTrue(result)
- self.assertEqual(1, mocked_execute.call_count)
+ self.assertEqual(1, mock_execute.call_count)
def test_flaky(self, _):
"""Tests that is_reproducible returns True if crash is detected on the last
attempt."""
last_time_repro = [EXECUTE_SUCCESS_RETVAL] * 9 + [EXECUTE_FAILURE_RETVAL]
with mock.patch('utils.execute',
- side_effect=last_time_repro) as mocked_execute:
+ side_effect=last_time_repro) as mock_execute:
self.assertTrue(
self.target.is_reproducible(self.testcase_path,
self.fuzz_target_path))
- self.assertEqual(fuzz_target.REPRODUCE_ATTEMPTS,
- mocked_execute.call_count)
+ self.assertEqual(fuzz_target.REPRODUCE_ATTEMPTS, mock_execute.call_count)
def test_nonexistent_fuzzer(self, _):
"""Tests that is_reproducible raises an error if it could not attempt
@@ -186,12 +185,12 @@ class IsCrashReportableTest(fake_filesystem_unittest.TestCase):
@mock.patch('fuzz_target.FuzzTarget.is_reproducible',
side_effect=[True, False])
@mock.patch('logging.info')
- def test_new_reproducible_crash(self, mocked_info, _):
+ def test_new_reproducible_crash(self, mock_info, _):
"""Tests that a new reproducible crash returns True."""
with tempfile.TemporaryDirectory() as tmp_dir:
self.target.out_dir = tmp_dir
self.assertTrue(self.target.is_crash_reportable(self.testcase_path))
- mocked_info.assert_called_with(
+ mock_info.assert_called_with(
'The crash is not reproducible on previous build. '
'Code change (pr/commit) introduced crash.')
@@ -218,7 +217,7 @@ class IsCrashReportableTest(fake_filesystem_unittest.TestCase):
@mock.patch('logging.info')
@mock.patch('fuzz_target.FuzzTarget.is_reproducible', return_value=[True])
- def test_reproducible_no_oss_fuzz_target(self, _, mocked_info):
+ def test_reproducible_no_oss_fuzz_target(self, _, mock_info):
"""Tests that is_crash_reportable returns True when a crash reproduces on
the PR build but the target is not in the OSS-Fuzz build (usually because it
is new)."""
@@ -231,13 +230,13 @@ class IsCrashReportableTest(fake_filesystem_unittest.TestCase):
with mock.patch(
'fuzz_target.FuzzTarget.is_reproducible',
- side_effect=is_reproducible_side_effect) as mocked_is_reproducible:
+ side_effect=is_reproducible_side_effect) as mock_is_reproducible:
with mock.patch('clusterfuzz_deployment.OSSFuzz.download_latest_build',
return_value=self.oss_fuzz_build_path):
self.assertTrue(self.target.is_crash_reportable(self.testcase_path))
- mocked_is_reproducible.assert_any_call(self.testcase_path,
- self.oss_fuzz_target_path)
- mocked_info.assert_called_with(
+ mock_is_reproducible.assert_any_call(self.testcase_path,
+ self.oss_fuzz_target_path)
+ mock_info.assert_called_with(
'Could not run previous build of target to determine if this code '
'change (pr/commit) introduced crash. Assuming crash was newly '
'introduced.')
diff --git a/infra/cifuzz/generate_coverage_report_test.py b/infra/cifuzz/generate_coverage_report_test.py
index b24eb3fe3..df2c9b206 100644
--- a/infra/cifuzz/generate_coverage_report_test.py
+++ b/infra/cifuzz/generate_coverage_report_test.py
@@ -31,7 +31,7 @@ class TestRunCoverageCommand(unittest.TestCase):
test_helpers.patch_environ(self, empty=True)
@mock.patch('utils.execute')
- def test_run_coverage_command(self, mocked_execute): # pylint: disable=no-self-use
+ def test_run_coverage_command(self, mock_execute): # pylint: disable=no-self-use
"""Tests that run_coverage_command works as intended."""
config = test_helpers.create_run_config(oss_fuzz_project_name=PROJECT,
sanitizer=SANITIZER)
@@ -51,7 +51,7 @@ class TestRunCoverageCommand(unittest.TestCase):
'CORPUS_DIR': workspace.corpora,
'COVERAGE_OUTPUT_DIR': workspace.coverage_report
}
- mocked_execute.assert_called_with(expected_command, env=expected_env)
+ mock_execute.assert_called_with(expected_command, env=expected_env)
class DownloadCorporaTest(unittest.TestCase):
diff --git a/infra/cifuzz/get_coverage_test.py b/infra/cifuzz/get_coverage_test.py
index ddde92299..fcfc9bd25 100644
--- a/infra/cifuzz/get_coverage_test.py
+++ b/infra/cifuzz/get_coverage_test.py
@@ -47,14 +47,14 @@ class GetOssFuzzFuzzerStatsDirUrlTest(unittest.TestCase):
'fuzzer_stats_dir':
'gs://oss-fuzz-coverage/systemd/fuzzer_stats/20210303'
})
- def test_get_valid_project(self, mocked_get_json_from_url):
+ def test_get_valid_project(self, mock_get_json_from_url):
"""Tests that a project's coverage report can be downloaded and parsed.
NOTE: This test relies on the PROJECT_NAME repo's coverage report.
The "example" project was not used because it has no coverage reports.
"""
result = get_coverage._get_oss_fuzz_fuzzer_stats_dir_url(PROJECT_NAME)
- (url,), _ = mocked_get_json_from_url.call_args
+ (url,), _ = mock_get_json_from_url.call_args
self.assertEqual(
'https://storage.googleapis.com/oss-fuzz-coverage/'
'latest_report_info/curl.json', url)
@@ -80,10 +80,10 @@ class OSSFuzzCoverageGetTargetCoverageTest(unittest.TestCase):
REPO_PATH, PROJECT_NAME)
@mock.patch('http_utils.get_json_from_url', return_value={})
- def test_valid_target(self, mocked_get_json_from_url):
+ def test_valid_target(self, mock_get_json_from_url):
"""Tests that a target's coverage report can be downloaded and parsed."""
self.oss_fuzz_coverage.get_target_coverage(FUZZ_TARGET)
- (url,), _ = mocked_get_json_from_url.call_args
+ (url,), _ = mock_get_json_from_url.call_args
self.assertEqual(
'https://storage.googleapis.com/oss-fuzz-coverage/'
'curl/fuzzer_stats/20200226/curl_fuzzer.json', url)
@@ -215,22 +215,22 @@ class GetOssFuzzLatestCovReportInfo(unittest.TestCase):
@mock.patch('logging.error')
@mock.patch('http_utils.get_json_from_url', return_value={'coverage': 1})
- def test_get_oss_fuzz_latest_cov_report_info(self, mocked_get_json_from_url,
- mocked_error):
+ def test_get_oss_fuzz_latest_cov_report_info(self, mock_get_json_from_url,
+ mock_error):
"""Tests that _get_oss_fuzz_latest_cov_report_info works as intended."""
result = get_coverage._get_oss_fuzz_latest_cov_report_info(self.PROJECT)
self.assertEqual(result, {'coverage': 1})
- mocked_error.assert_not_called()
- mocked_get_json_from_url.assert_called_with(self.LATEST_REPORT_INFO_URL)
+ mock_error.assert_not_called()
+ mock_get_json_from_url.assert_called_with(self.LATEST_REPORT_INFO_URL)
@mock.patch('logging.error')
@mock.patch('http_utils.get_json_from_url', return_value=None)
- def test_get_oss_fuzz_latest_cov_report_info_fail(self, _, mocked_error):
+ def test_get_oss_fuzz_latest_cov_report_info_fail(self, _, mock_error):
"""Tests that _get_oss_fuzz_latest_cov_report_info works as intended when we
can't get latest report info."""
result = get_coverage._get_oss_fuzz_latest_cov_report_info('project')
self.assertIsNone(result)
- mocked_error.assert_called_with(
+ mock_error.assert_called_with(
'Could not get the coverage report json from url: %s.',
self.LATEST_REPORT_INFO_URL)
diff --git a/infra/cifuzz/http_utils_test.py b/infra/cifuzz/http_utils_test.py
index 2f603d5dd..64d0598ac 100644
--- a/infra/cifuzz/http_utils_test.py
+++ b/infra/cifuzz/http_utils_test.py
@@ -20,7 +20,7 @@ from pyfakefs import fake_filesystem_unittest
import http_utils
-mocked_get_response = mock.MagicMock(status_code=200, content=b'')
+mock_get_response = mock.MagicMock(status_code=200, content=b'')
class DownloadUrlTest(unittest.TestCase):
@@ -29,31 +29,31 @@ class DownloadUrlTest(unittest.TestCase):
FILE_PATH = '/tmp/file'
@mock.patch('time.sleep')
- @mock.patch('requests.get', return_value=mocked_get_response)
- def test_download_url_no_error(self, mocked_urlretrieve, _):
+ @mock.patch('requests.get', return_value=mock_get_response)
+ def test_download_url_no_error(self, mock_urlretrieve, _):
"""Tests that download_url works when there is no error."""
self.assertTrue(http_utils.download_url(self.URL, self.FILE_PATH))
- self.assertEqual(1, mocked_urlretrieve.call_count)
+ self.assertEqual(1, mock_urlretrieve.call_count)
@mock.patch('time.sleep')
@mock.patch('logging.error')
@mock.patch('requests.get',
return_value=mock.MagicMock(status_code=404, content=b''))
- def test_download_url_http_error(self, mocked_get, mocked_error, _):
+ def test_download_url_http_error(self, mock_get, mock_error, _):
"""Tests that download_url doesn't retry when there is an HTTP error."""
self.assertFalse(http_utils.download_url(self.URL, self.FILE_PATH))
- mocked_error.assert_called_with(
+ mock_error.assert_called_with(
'Unable to download from: %s. Code: %d. Content: %s.', self.URL, 404,
b'')
- self.assertEqual(1, mocked_get.call_count)
+ self.assertEqual(1, mock_get.call_count)
@mock.patch('time.sleep')
@mock.patch('requests.get', side_effect=ConnectionResetError)
- def test_download_url_connection_error(self, mocked_get, mocked_sleep):
+ def test_download_url_connection_error(self, mock_get, mock_sleep):
"""Tests that download_url doesn't retry when there is an HTTP error."""
self.assertFalse(http_utils.download_url(self.URL, self.FILE_PATH))
- self.assertEqual(4, mocked_get.call_count)
- self.assertEqual(3, mocked_sleep.call_count)
+ self.assertEqual(4, mock_get.call_count)
+ self.assertEqual(3, mock_sleep.call_count)
class DownloadAndUnpackZipTest(fake_filesystem_unittest.TestCase):
@@ -62,7 +62,7 @@ class DownloadAndUnpackZipTest(fake_filesystem_unittest.TestCase):
def setUp(self):
self.setUpPyfakefs()
- @mock.patch('requests.get', return_value=mocked_get_response)
+ @mock.patch('requests.get', return_value=mock_get_response)
def test_bad_zip_download(self, _):
"""Tests download_and_unpack_zip returns none when a bad zip is passed."""
self.fs.create_file('/url_tmp.zip', contents='Test file.')
diff --git a/infra/cifuzz/run_fuzzers_test.py b/infra/cifuzz/run_fuzzers_test.py
index 5b79ac5b4..5e10046b9 100644
--- a/infra/cifuzz/run_fuzzers_test.py
+++ b/infra/cifuzz/run_fuzzers_test.py
@@ -116,10 +116,10 @@ class BaseFuzzTargetRunnerTest(unittest.TestCase):
return run_fuzzers.BaseFuzzTargetRunner(config)
def _test_initialize_fail(self, expected_error_args, **create_runner_kwargs):
- with mock.patch('logging.error') as mocked_error:
+ with mock.patch('logging.error') as mock_error:
runner = self._create_runner(**create_runner_kwargs)
self.assertFalse(runner.initialize())
- mocked_error.assert_called_with(*expected_error_args)
+ mock_error.assert_called_with(*expected_error_args)
@parameterized.parameterized.expand([(0,), (None,), (-1,)])
def test_initialize_invalid_fuzz_seconds(self, fuzz_seconds):
@@ -129,8 +129,8 @@ class BaseFuzzTargetRunnerTest(unittest.TestCase):
with tempfile.TemporaryDirectory() as tmp_dir:
out_path = os.path.join(tmp_dir, 'build-out')
os.mkdir(out_path)
- with mock.patch('utils.get_fuzz_targets') as mocked_get_fuzz_targets:
- mocked_get_fuzz_targets.return_value = [
+ with mock.patch('utils.get_fuzz_targets') as mock_get_fuzz_targets:
+ mock_get_fuzz_targets.return_value = [
os.path.join(out_path, 'fuzz_target')
]
self._test_initialize_fail(expected_error_args,
@@ -175,10 +175,10 @@ class BaseFuzzTargetRunnerTest(unittest.TestCase):
@mock.patch('utils.get_fuzz_targets')
@mock.patch('logging.error')
- def test_initialize_empty_artifacts(self, mocked_log_error,
- mocked_get_fuzz_targets):
+ def test_initialize_empty_artifacts(self, mock_log_error,
+ mock_get_fuzz_targets):
"""Tests initialize with an empty artifacts dir."""
- mocked_get_fuzz_targets.return_value = ['fuzz-target']
+ mock_get_fuzz_targets.return_value = ['fuzz-target']
with tempfile.TemporaryDirectory() as tmp_dir:
out_path = os.path.join(tmp_dir, 'build-out')
os.mkdir(out_path)
@@ -186,21 +186,20 @@ class BaseFuzzTargetRunnerTest(unittest.TestCase):
os.makedirs(artifacts_path)
runner = self._create_runner(workspace=tmp_dir)
self.assertTrue(runner.initialize())
- mocked_log_error.assert_not_called()
+ mock_log_error.assert_not_called()
self.assertTrue(os.path.isdir(artifacts_path))
@mock.patch('utils.get_fuzz_targets')
@mock.patch('logging.error')
- def test_initialize_no_artifacts(self, mocked_log_error,
- mocked_get_fuzz_targets):
+ def test_initialize_no_artifacts(self, mock_log_error, mock_get_fuzz_targets):
"""Tests initialize with no artifacts dir (the expected setting)."""
- mocked_get_fuzz_targets.return_value = ['fuzz-target']
+ mock_get_fuzz_targets.return_value = ['fuzz-target']
with tempfile.TemporaryDirectory() as tmp_dir:
out_path = os.path.join(tmp_dir, 'build-out')
os.mkdir(out_path)
runner = self._create_runner(workspace=tmp_dir)
self.assertTrue(runner.initialize())
- mocked_log_error.assert_not_called()
+ mock_log_error.assert_not_called()
self.assertTrue(os.path.isdir(os.path.join(tmp_dir, 'out', 'artifacts')))
def test_initialize_no_fuzz_targets(self):
@@ -240,9 +239,8 @@ class CiFuzzTargetRunnerTest(fake_filesystem_unittest.TestCase):
@mock.patch('utils.get_fuzz_targets')
@mock.patch('run_fuzzers.CiFuzzTargetRunner.run_fuzz_target')
@mock.patch('run_fuzzers.CiFuzzTargetRunner.create_fuzz_target_obj')
- def test_run_fuzz_targets_quits(self, mocked_create_fuzz_target_obj,
- mocked_run_fuzz_target,
- mocked_get_fuzz_targets):
+ def test_run_fuzz_targets_quits(self, mock_create_fuzz_target_obj,
+ mock_run_fuzz_target, mock_get_fuzz_targets):
"""Tests that run_fuzz_targets quits on the first crash it finds."""
workspace = 'workspace'
out_path = os.path.join(workspace, 'build-out')
@@ -253,22 +251,22 @@ class CiFuzzTargetRunnerTest(fake_filesystem_unittest.TestCase):
oss_fuzz_project_name=EXAMPLE_PROJECT)
runner = run_fuzzers.CiFuzzTargetRunner(config)
- mocked_get_fuzz_targets.return_value = ['target1', 'target2']
+ mock_get_fuzz_targets.return_value = ['target1', 'target2']
runner.initialize()
testcase = os.path.join(workspace, 'testcase')
self.fs.create_file(testcase)
stacktrace = b'stacktrace'
corpus_dir = 'corpus'
self.fs.create_dir(corpus_dir)
- mocked_run_fuzz_target.return_value = fuzz_target.FuzzResult(
+ mock_run_fuzz_target.return_value = fuzz_target.FuzzResult(
testcase, stacktrace, corpus_dir)
magic_mock = mock.MagicMock()
magic_mock.target_name = 'target1'
- mocked_create_fuzz_target_obj.return_value = magic_mock
+ mock_create_fuzz_target_obj.return_value = magic_mock
self.assertTrue(runner.run_fuzz_targets())
self.assertIn('target1-address-testcase',
os.listdir(runner.workspace.artifacts))
- self.assertEqual(mocked_run_fuzz_target.call_count, 1)
+ self.assertEqual(mock_run_fuzz_target.call_count, 1)
class BatchFuzzTargetRunnerTest(fake_filesystem_unittest.TestCase):
@@ -294,15 +292,15 @@ class BatchFuzzTargetRunnerTest(fake_filesystem_unittest.TestCase):
return_value=True)
@mock.patch('run_fuzzers.BatchFuzzTargetRunner.run_fuzz_target')
@mock.patch('run_fuzzers.BatchFuzzTargetRunner.create_fuzz_target_obj')
- def test_run_fuzz_targets_quits(self, mocked_create_fuzz_target_obj,
- mocked_run_fuzz_target, _, __):
+ def test_run_fuzz_targets_quits(self, mock_create_fuzz_target_obj,
+ mock_run_fuzz_target, _, __):
"""Tests that run_fuzz_targets doesn't quit on the first crash it finds."""
runner = run_fuzzers.BatchFuzzTargetRunner(self.config)
runner.initialize()
call_count = 0
- def mock_run_fuzz_target(_):
+ def mock_run_fuzz_target_impl(_):
nonlocal call_count
if call_count == 0:
testcase = self.testcase1
@@ -314,27 +312,28 @@ class BatchFuzzTargetRunnerTest(fake_filesystem_unittest.TestCase):
self.fs.create_dir(self.CORPUS_DIR)
return fuzz_target.FuzzResult(testcase, self.STACKTRACE, self.CORPUS_DIR)
- mocked_run_fuzz_target.side_effect = mock_run_fuzz_target
+ mock_run_fuzz_target.side_effect = mock_run_fuzz_target_impl
magic_mock = mock.MagicMock()
magic_mock.target_name = 'target1'
- mocked_create_fuzz_target_obj.return_value = magic_mock
+ mock_create_fuzz_target_obj.return_value = magic_mock
self.assertTrue(runner.run_fuzz_targets())
- self.assertEqual(mocked_run_fuzz_target.call_count, 2)
+ self.assertEqual(mock_run_fuzz_target.call_count, 2)
@mock.patch('run_fuzzers.BaseFuzzTargetRunner.run_fuzz_targets',
return_value=False)
@mock.patch('clusterfuzz_deployment.ClusterFuzzLite.upload_latest_build')
@mock.patch('clusterfuzz_deployment.ClusterFuzzLite.upload_crashes')
- def test_run_fuzz_targets_upload_crashes_and_builds(
- self, mocked_upload_crashes, mocked_upload_latest_build, _):
+ def test_run_fuzz_targets_upload_crashes_and_builds(self, mock_upload_crashes,
+ mock_upload_latest_build,
+ _):
"""Tests that run_fuzz_targets uploads crashes and builds correctly."""
runner = run_fuzzers.BatchFuzzTargetRunner(self.config)
# TODO(metzman): Don't rely on this failing gracefully.
runner.initialize()
self.assertFalse(runner.run_fuzz_targets())
- self.assertEqual(mocked_upload_crashes.call_count, 1)
- self.assertEqual(mocked_upload_latest_build.call_count, 1)
+ self.assertEqual(mock_upload_crashes.call_count, 1)
+ self.assertEqual(mock_upload_latest_build.call_count, 1)
@unittest.skipIf(not os.getenv('INTEGRATION_TESTS'),
diff --git a/infra/cifuzz/stack_parser_test.py b/infra/cifuzz/stack_parser_test.py
index faf601fd5..2c1b223ad 100644
--- a/infra/cifuzz/stack_parser_test.py
+++ b/infra/cifuzz/stack_parser_test.py
@@ -49,9 +49,9 @@ class ParseOutputTest(fake_filesystem_unittest.TestCase):
with open(fuzzer_output_path, 'rb') as fuzzer_output_handle:
fuzzer_output = fuzzer_output_handle.read()
bug_summary_path = '/bug-summary.txt'
- with mock.patch('logging.info') as mocked_info:
+ with mock.patch('logging.info') as mock_info:
stack_parser.parse_fuzzer_output(fuzzer_output, bug_summary_path)
- mocked_info.assert_not_called()
+ mock_info.assert_not_called()
with open(bug_summary_path) as bug_summary_handle:
bug_summary = bug_summary_handle.read()
@@ -67,10 +67,10 @@ class ParseOutputTest(fake_filesystem_unittest.TestCase):
def test_parse_invalid_output(self):
"""Checks that no files are created when an invalid input was given."""
artifact_path = '/bug-summary.txt'
- with mock.patch('logging.error') as mocked_error:
+ with mock.patch('logging.error') as mock_error:
stack_parser.parse_fuzzer_output(b'not a valid output_string',
artifact_path)
- assert mocked_error.call_count
+ assert mock_error.call_count
self.assertFalse(os.path.exists(artifact_path))
diff --git a/infra/helper_test.py b/infra/helper_test.py
index 6f0bc88cf..6bf2b882f 100644
--- a/infra/helper_test.py
+++ b/infra/helper_test.py
@@ -48,47 +48,47 @@ class BuildImageImplTest(unittest.TestCase):
"""Tests for build_image_impl."""
@mock.patch('helper.docker_build')
- def test_no_cache(self, mocked_docker_build):
+ def test_no_cache(self, mock_docker_build):
"""Tests that cache=False is handled properly."""
image_name = 'base-image'
helper.build_image_impl(helper.Project(image_name), cache=False)
- self.assertIn('--no-cache', mocked_docker_build.call_args_list[0][0][0])
+ self.assertIn('--no-cache', mock_docker_build.call_args_list[0][0][0])
@mock.patch('helper.docker_build')
@mock.patch('helper.pull_images')
- def test_pull(self, mocked_pull_images, _):
+ def test_pull(self, mock_pull_images, _):
"""Tests that pull=True is handled properly."""
image_name = 'base-image'
self.assertTrue(
helper.build_image_impl(helper.Project(image_name), pull=True))
- mocked_pull_images.assert_called_with()
+ mock_pull_images.assert_called_with()
@mock.patch('helper.docker_build')
- def test_base_image(self, mocked_docker_build):
+ def test_base_image(self, mock_docker_build):
"""Tests that build_image_impl works as intended with a base-image."""
image_name = 'base-image'
self.assertTrue(helper.build_image_impl(helper.Project(image_name)))
build_dir = os.path.join(helper.OSS_FUZZ_DIR,
'infra/base-images/base-image')
- mocked_docker_build.assert_called_with([
+ mock_docker_build.assert_called_with([
'-t', 'gcr.io/oss-fuzz-base/base-image', '--file',
os.path.join(build_dir, 'Dockerfile'), build_dir
])
@mock.patch('helper.docker_build')
- def test_oss_fuzz_project(self, mocked_docker_build):
+ def test_oss_fuzz_project(self, mock_docker_build):
"""Tests that build_image_impl works as intended with an OSS-Fuzz
project."""
project_name = 'example'
self.assertTrue(helper.build_image_impl(helper.Project(project_name)))
build_dir = os.path.join(helper.OSS_FUZZ_DIR, 'projects', project_name)
- mocked_docker_build.assert_called_with([
+ mock_docker_build.assert_called_with([
'-t', 'gcr.io/oss-fuzz/example', '--file',
os.path.join(build_dir, 'Dockerfile'), build_dir
])
@mock.patch('helper.docker_build')
- def test_external_project(self, mocked_docker_build):
+ def test_external_project(self, mock_docker_build):
"""Tests that build_image_impl works as intended with a non-OSS-Fuzz
project."""
with tempfile.TemporaryDirectory() as temp_dir:
@@ -99,7 +99,7 @@ class BuildImageImplTest(unittest.TestCase):
is_external=True,
build_integration_path=build_integration_path)
self.assertTrue(helper.build_image_impl(project))
- mocked_docker_build.assert_called_with([
+ mock_docker_build.assert_called_with([
'-t', 'gcr.io/oss-fuzz/example', '--file',
os.path.join(project_src_path, build_integration_path, 'Dockerfile'),
project_src_path
diff --git a/infra/utils_test.py b/infra/utils_test.py
index 3ce405523..a57e68e1f 100644
--- a/infra/utils_test.py
+++ b/infra/utils_test.py
@@ -118,17 +118,17 @@ class BinaryPrintTest(unittest.TestCase):
def test_string(self): # pylint: disable=no-self-use
"""Tests that utils.binary_print can print a regular string."""
# Should execute without raising any exceptions.
- with mock.patch('sys.stdout.buffer.write') as mocked_write:
+ with mock.patch('sys.stdout.buffer.write') as mock_write:
utils.binary_print('hello')
- mocked_write.assert_called_with('hello\n')
+ mock_write.assert_called_with('hello\n')
@unittest.skip('Causes spurious failures because of side-effects.')
def test_binary_string(self): # pylint: disable=no-self-use
"""Tests that utils.binary_print can print a bianry string."""
# Should execute without raising any exceptions.
- with mock.patch('sys.stdout.buffer.write') as mocked_write:
+ with mock.patch('sys.stdout.buffer.write') as mock_write:
utils.binary_print(b'hello')
- mocked_write.assert_called_with(b'hello\n')
+ mock_write.assert_called_with(b'hello\n')
if __name__ == '__main__':