# Test case for shutil.make_archive() to make sure that, given identical # inputs, an identical tarfile is output. import os import random import shutil import tempfile def create_tar(tar_path): '''Create a tar with some dummy files. The data is the same each time but it is written to disk in a random order. ''' tempdir = tempfile.mkdtemp() try: contents = ['a', 'b', 'c', 'd'] atime = 1234578 random.shuffle(contents) for filename in contents: path = os.path.join(tempdir, filename) with open(path, 'w') as f: f.write('Blah\n') os.utime(path, (atime, atime)) shutil.make_archive(base_name=tar_path, format='tar', root_dir=tempdir) finally: shutil.rmtree(tempdir) for i in range(0,3): path = '/tmp/tar-%i' % i create_tar(path) print(path + '.tar')