Introduce file creations and deletions during mutation
All checks were successful
continuous-integration/drone the build was successful

This commit is contained in:
Olivier 'reivilibre' 2021-09-13 18:51:53 +01:00
parent a1e17454d7
commit 594ead0f70

View File

@ -188,12 +188,26 @@ def randomly_mutate_file_in_descriptor(
def randomly_mutate_directory_in_descriptor( def randomly_mutate_directory_in_descriptor(
descriptor: DirectoryDescriptor, path: Path, random: Random descriptor: DirectoryDescriptor, path: Path, rng: Random
) -> None: ) -> None:
for name, value in descriptor.contents.items(): for name, value in descriptor.contents.items():
if isinstance(value, FileDescriptor): if rng.random() < 0.1:
if random.random() < 0.6: # just delete this (with low 10% chance)
randomly_mutate_file_in_descriptor(value, path.joinpath(name), random) continue
elif isinstance(value, FileDescriptor):
if rng.random() < 0.6:
randomly_mutate_file_in_descriptor(value, path.joinpath(name), rng)
else: else:
assert isinstance(value, DirectoryDescriptor) assert isinstance(value, DirectoryDescriptor)
randomly_mutate_directory_in_descriptor(value, path.joinpath(name), random) randomly_mutate_directory_in_descriptor(value, path.joinpath(name), rng)
# introduce some new files, maybe.
new_files_to_introduce = max(0, rng.randint(-3, 3))
for _ in range(new_files_to_introduce):
filename_len = rng.randint(4, 16)
filename = "".join(rng.choice(ALPHABET) for _ in range(filename_len))
filepath = path.joinpath(filename)
if rng.random() < 0.8:
generate_random_file(rng, filepath)
else:
generate_random_dir(rng, filepath, 5)