diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-02-06 18:03:49 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-02-06 18:16:45 +0200 |
commit | 61aca01941d3bdf324a207f2b53dbf7128169142 (patch) | |
tree | 861aa3b61e16e2a486c61eabf1bf2e27a223679e /subplot/data.py | |
parent | ad98db921aa3d710ad7c448c6a1b818f4359d73a (diff) | |
download | obnam2-61aca01941d3bdf324a207f2b53dbf7128169142.tar.gz |
test: add scenario for checking chunk-size
Diffstat (limited to 'subplot/data.py')
-rw-r--r-- | subplot/data.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/subplot/data.py b/subplot/data.py index 2a54037..f3faf2b 100644 --- a/subplot/data.py +++ b/subplot/data.py @@ -5,14 +5,17 @@ import random import yaml -def create_file_with_random_data(ctx, filename=None): - N = 128 - data = "".join(chr(random.randint(0, 255)) for i in range(N)).encode("UTF-8") +def create_file_with_given_data(ctx, filename=None, data=None): + logging.debug(f"creating file {filename} with {data!r}") dirname = os.path.dirname(filename) or "." - logging.debug(f"create_file_with_random_data: dirname={dirname}") os.makedirs(dirname, exist_ok=True) - with open(filename, "wb") as f: - f.write(data) + open(filename, "wb").write(data.encode("UTF-8")) + + +def create_file_with_random_data(ctx, filename=None): + N = 128 + data = "".join(chr(random.randint(0, 255)) for i in range(N)) + create_file_with_given_data(ctx, filename=filename, data=data) def create_nonutf8_filename(ctx, dirname=None): |