diff --git a/testsuite/helpers/__init__.py b/testsuite/helpers/__init__.py index cf75c23..d9789d5 100644 --- a/testsuite/helpers/__init__.py +++ b/testsuite/helpers/__init__.py @@ -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)