1""" 2Generate zip test data files. 3""" 4 5import zipfile 6 7 8def make_zip_file(tree, dst): 9 """ 10 Zip the files in tree into a new zipfile at dst. 11 """ 12 with zipfile.ZipFile(dst, 'w') as zf: 13 for name, contents in walk(tree): 14 zf.writestr(name, contents) 15 zipfile._path.CompleteDirs.inject(zf) 16 return dst 17 18 19def walk(tree, prefix=''): 20 for name, contents in tree.items(): 21 if isinstance(contents, dict): 22 yield from walk(contents, prefix=f'{prefix}{name}/') 23 else: 24 yield f'{prefix}{name}', contents 25