1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-12 07:43:59 +00:00

adding binaries in tests

This commit is contained in:
deadc0de6
2017-03-15 21:54:23 +01:00
parent 17426ca9e5
commit 9850714064
2 changed files with 26 additions and 9 deletions

View File

@@ -36,13 +36,19 @@ def get_tempfolder():
return tempfile.mkdtemp(suffix=TMPSUFFIX)
def create_random_file(folder, content=None):
def create_random_file(folder, content=None, binary=False):
'''Create a new file in folder with random content.'''
fname = get_string(8)
mode = 'w'
if binary:
mode = 'wb'
if content is None:
content = get_string(100)
if binary:
content = bytes(get_string(100), 'ascii')
else:
content = get_string(100)
path = os.path.join(folder, fname)
with open(path, 'w') as f:
with open(path, mode) as f:
f.write(content)
return path, content