Skip to content

Commit

Permalink
Rename pyfakefs functions.
Browse files Browse the repository at this point in the history
Functions were renamed to be pep-8 conformant:
pytest-dev/pyfakefs#186
  • Loading branch information
oliverchang committed Jul 31, 2019
1 parent 8d2ba62 commit 57f5099
Show file tree
Hide file tree
Showing 23 changed files with 211 additions and 209 deletions.
16 changes: 8 additions & 8 deletions src/python/tests/core/bot/fuzzers/afl/afl_launcher_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class LauncherTestBase(fake_filesystem_unittest.TestCase):

def setUp(self):
test_utils.set_up_pyfakefs(self)
self.fs.CreateDirectory(self.INPUT_DIR)
self.fs.create_dir(self.INPUT_DIR)
if not os.path.exists(self.TEMP_DIR):
self.fs.CreateDirectory(self.TEMP_DIR)
self.fs.create_dir(self.TEMP_DIR)

self._create_file(fuzzer.AFL_DUMMY_INPUT)
test_helpers.patch(self, [
Expand All @@ -65,7 +65,7 @@ def _create_file(self, filename, directory=None, contents=' '):
directory = self.INPUT_DIR

file_path = os.path.join(directory, filename)
return file_path, self.fs.CreateFile(file_path, contents=contents)
return file_path, self.fs.create_file(file_path, contents=contents)

def _assert_elements_equal(self, l1, l2):
"""Assert that the elements of |l1| and |l2|. Modifies |l1| and |l2| by
Expand Down Expand Up @@ -249,7 +249,7 @@ def test_create_new_if_needed_subdirs(self):
self._create_file('small_1')
self._create_oversized_file(filename='too_big_1')
subdirectory = os.path.join(self.INPUT_DIR, 'subdir')
self.fs.CreateDirectory(subdirectory)
self.fs.create_dir(subdirectory)
self._create_file('small_2', directory=subdirectory)
self._create_oversized_file(directory=subdirectory, filename='too_big_2')
afl_input = self._new_afl_input()
Expand Down Expand Up @@ -654,7 +654,7 @@ def test_fuzzer_stderr_ioerror(self):
def test_fuzzer_stderr(self):
"""Test AflRunner.fuzzer_stderr works correctly."""
stderr = 'hello'
self.fs.CreateFile(self.runner.stderr_file_path, contents=stderr)
self.fs.create_file(self.runner.stderr_file_path, contents=stderr)
self.assertIsNone(self.runner._fuzzer_stderr)
self.assertEqual(self.runner.fuzzer_stderr, stderr)

Expand Down Expand Up @@ -697,7 +697,7 @@ def _initialization_for_run_afl(self):

# Make sure this initialized or else it will remove CRASHES_DIR.
self.runner.afl_output # pylint: disable=pointless-statement
self.fs.CreateDirectory(self.CRASHES_DIR)
self.fs.create_dir(self.CRASHES_DIR)
self.runner.initial_max_total_time = 100
self.mock.run_and_wait.side_effect = (
lambda *args, **kwargs: self._process_result())
Expand Down Expand Up @@ -897,7 +897,7 @@ def test_list_full_file_paths(self):

# Test it works with a subdirectory by not returning it:
dummy_dir = os.path.join(self.INPUT_DIR, 'dummydir')
self.fs.CreateDirectory(dummy_dir)
self.fs.create_dir(dummy_dir)
self._create_file(self.DUMMY_2_FILENAME, directory=dummy_dir)

self._assert_elements_equal(
Expand All @@ -922,7 +922,7 @@ def _get_unique_feature(self):

def _create_file(self, path, size=1):
"""Creates a file at |path| that is |size| bytes large."""
self.fs.CreateFile(path, contents=size * 'A')
self.fs.create_file(path, contents=size * 'A')

def test_corpus_element(self):
"""Tests CorpusElement class."""
Expand Down
4 changes: 2 additions & 2 deletions src/python/tests/core/bot/fuzzers/builtin_fuzzers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class BuiltinFuzzersSetupTest(fake_filesystem_unittest.TestCase):
def setUp(self):
helpers.patch_environ(self)
test_utils.set_up_pyfakefs(self)
self.fs.CreateDirectory('/input')
self.fs.CreateDirectory('/output')
self.fs.create_dir('/input')
self.fs.create_dir('/output')

helpers.patch(self, [
'bot.fuzzers.libFuzzer.fuzzer.LibFuzzer.run',
Expand Down
8 changes: 4 additions & 4 deletions src/python/tests/core/bot/fuzzers/builtin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def setUp(self):
])

test_utils.set_up_pyfakefs(self)
self.fs.CreateDirectory('/input')
self.fs.CreateDirectory('/output')
self.fs.create_dir('/input')
self.fs.create_dir('/output')

environment.set_value('BUILD_DIR', '/build_dir')
environment.set_value('FAIL_RETRIES', 1)
Expand All @@ -56,7 +56,7 @@ def setUp(self):
self.mock.get_fuzz_targets.return_value = [
'/build_dir/target',
]
self.fs.CreateFile(
self.fs.create_file(
'/build_dir/target.owners',
contents='[email protected]\n[email protected]')

Expand Down Expand Up @@ -87,7 +87,7 @@ def test_run(self):

def test_run_with_labels(self):
"""Test running an engine fuzzer with a labels file."""
self.fs.CreateFile('/build_dir/target.labels', contents='label1\nlabel2\n')
self.fs.create_file('/build_dir/target.labels', contents='label1\nlabel2\n')

fuzzer = TestEngineFuzzer()
result = fuzzer.run('/input', '/output', 1)
Expand Down
28 changes: 14 additions & 14 deletions src/python/tests/core/bot/fuzzers/engine_common_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ class GetIssueOwnersTest(fake_filesystem_unittest.TestCase):

def setUp(self):
test_utils.set_up_pyfakefs(self)
self.fs.CreateDirectory('/test')
self.fs.create_dir('/test')

def test_no_file(self):
self.assertEqual([], engine_common.get_issue_owners('/test/does_not_exist'))

def test_empty_file(self):
self.fs.CreateFile('/test/fuzz_target.owners', contents='')
self.fs.create_file('/test/fuzz_target.owners', contents='')
self.assertEqual([], engine_common.get_issue_owners('/test/fuzz_target'))

def test_all_allowed(self):
self.fs.CreateFile('/test/fuzz_target.owners', contents='*')
self.fs.create_file('/test/fuzz_target.owners', contents='*')
self.assertEqual([], engine_common.get_issue_owners('/test/fuzz_target'))

def test_sections(self):
"""Test sections."""
self.fs.CreateFile(
self.fs.create_file(
'/test/fuzz_target.owners',
contents=('file://ENG_REVIEW_OWNERS\n'
' \n'
Expand All @@ -70,27 +70,27 @@ class GetIssueLabelsTest(fake_filesystem_unittest.TestCase):

def setUp(self):
test_utils.set_up_pyfakefs(self)
self.fs.CreateDirectory('/test')
self.fs.create_dir('/test')

def test_no_file(self):
"""Test no labels file."""
self.assertEqual([], engine_common.get_issue_labels('/test/does_not_exist'))

def test_empty_file(self):
"""Test empty file."""
self.fs.CreateFile('/test/fuzz_target.labels', contents='')
self.fs.create_file('/test/fuzz_target.labels', contents='')
self.assertEqual([], engine_common.get_issue_labels('/test/fuzz_target'))

def test_well_formed(self):
"""Test well formed labels file."""
self.fs.CreateFile(
self.fs.create_file(
'/test/fuzz_target.labels', contents='label1\nlabel2\nlabel3\n')
self.assertEqual(['label1', 'label2', 'label3'],
engine_common.get_issue_labels('/test/fuzz_target'))

def test_empty_lines(self):
"""Test labels file with empty lines."""
self.fs.CreateFile(
self.fs.create_file(
'/test/fuzz_target.labels', contents='label1\n\t\nlabel2\n \nlabel3\n')
self.assertEqual(['label1', 'label2', 'label3'],
engine_common.get_issue_labels('/test/fuzz_target'))
Expand Down Expand Up @@ -215,14 +215,14 @@ def setUp(self):
test_helpers.patch_environ(self)
self.build_dir = '/test'
self.fuzzer_name = 'fuzz_target'
self.fs.CreateDirectory(self.build_dir)
self.fs.create_dir(self.build_dir)

def _setup_fuzzer(self, fuzzer_name=None):
"""Create a file to represent the fuzzer."""
if fuzzer_name is None:
fuzzer_name = self.fuzzer_name
fuzzer_path = os.path.join(self.build_dir, fuzzer_name)
self.fs.CreateFile(fuzzer_path)
self.fs.create_file(fuzzer_path)
return fuzzer_path

def _find_fuzzer_path(self, fuzzer_name=None):
Expand Down Expand Up @@ -251,7 +251,7 @@ def test_finds_fuzzer_with_legacy_prefix_in_name_and_env(self):

def test_only_finds_file(self):
"""Test that a directory is never returned."""
self.fs.CreateDirectory(os.path.join(self.build_dir, self.fuzzer_name))
self.fs.create_dir(os.path.join(self.build_dir, self.fuzzer_name))
self.assertIsNone(self._find_fuzzer_path())


Expand Down Expand Up @@ -303,7 +303,7 @@ def setUp(self):

def _create_seed_corpus(self, extension):
seed_corpus_archive_path = self.archive_path_without_extension + extension
self.fs.CreateFile(seed_corpus_archive_path)
self.fs.create_file(seed_corpus_archive_path)
return seed_corpus_archive_path

def _get_seed_corpus_path(self, fuzz_target_path):
Expand Down Expand Up @@ -372,7 +372,7 @@ def setUp(self):
self.seed_corpus_subdirs_contents = seed_corpus_handle.read()

test_utils.set_up_pyfakefs(self)
self.fs.CreateDirectory(self.CORPUS_DIRECTORY)
self.fs.create_dir(self.CORPUS_DIRECTORY)

def _unpack_seed_corpus_if_needed(self, *args, **kwargs):
return engine_common.unpack_seed_corpus_if_needed(
Expand Down Expand Up @@ -400,7 +400,7 @@ def _create_corpus_files(self, num_files):
filenames = []
for file_num in range(num_files):
file_num = str(file_num)
self.fs.CreateFile(os.path.join(self.CORPUS_DIRECTORY, file_num))
self.fs.create_file(os.path.join(self.CORPUS_DIRECTORY, file_num))
filenames.append(file_num)
return filenames

Expand Down
Loading

0 comments on commit 57f5099

Please sign in to comment.