diff --git a/dcicutils/file_utils.py b/dcicutils/file_utils.py index a1bd0def5..eb865fd64 100644 --- a/dcicutils/file_utils.py +++ b/dcicutils/file_utils.py @@ -104,11 +104,26 @@ def are_files_equal(filea: str, fileb: str) -> bool: def create_random_file(file: Optional[str] = None, prefix: Optional[str] = None, suffix: Optional[str] = None, nbytes: int = 1024, binary: bool = False) -> str: - if not file: + if not isinstance(nbytes, int) or nbytes < 0: + nbytes = 0 + if not isinstance(file, str) or not file: + if not isinstance(prefix, str): + prefix = "" + if not isinstance(suffix, str): + suffix = "" file = create_temporary_file_name(prefix=prefix, suffix=suffix) with open(file, "wb" if binary is True else "w") as f: if binary is True: f.write(os.urandom(nbytes)) else: - f.write(''.join(random.choices(string.ascii_letters + string.digits, k=nbytes))) + nchars = 81 + nlines = nbytes // nchars + nremainder = nbytes % nchars + for n in range(nlines): + f.write("".join(random.choices(string.ascii_letters + string.digits, k=nchars - 1))) + f.write("\n") + if nremainder > 1: + f.write("".join(random.choices(string.ascii_letters + string.digits, k=nremainder - 1))) + if nremainder > 0: + f.write("\n") return file diff --git a/pyproject.toml b/pyproject.toml index 65a60a7e6..b335f35d0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "dcicutils" -version = "8.8.4.1b9" # TODO: To become 8.8.5 +version = "8.8.4.1b10" # TODO: To become 8.8.5 description = "Utility package for interacting with the 4DN Data Portal and other 4DN resources" authors = ["4DN-DCIC Team "] license = "MIT"