Introduce file creations and deletions during mutation
All checks were successful
continuous-integration/drone the build was successful
All checks were successful
continuous-integration/drone the build was successful
This commit is contained in:
parent
a1e17454d7
commit
594ead0f70
@ -188,12 +188,26 @@ def randomly_mutate_file_in_descriptor(
|
||||
|
||||
|
||||
def randomly_mutate_directory_in_descriptor(
|
||||
descriptor: DirectoryDescriptor, path: Path, random: Random
|
||||
descriptor: DirectoryDescriptor, path: Path, rng: Random
|
||||
) -> None:
|
||||
for name, value in descriptor.contents.items():
|
||||
if isinstance(value, FileDescriptor):
|
||||
if random.random() < 0.6:
|
||||
randomly_mutate_file_in_descriptor(value, path.joinpath(name), random)
|
||||
if rng.random() < 0.1:
|
||||
# just delete this (with low 10% chance)
|
||||
continue
|
||||
elif isinstance(value, FileDescriptor):
|
||||
if rng.random() < 0.6:
|
||||
randomly_mutate_file_in_descriptor(value, path.joinpath(name), rng)
|
||||
else:
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user