示例#1
0
def bad_metadata_dir():
    """
    Two tuple consisting of md5 hash and base directory. These should match a
    directory tree constructed from the md5 hash, and the target directory
    should contain a single invalid info.json file.
    """
    tmpdir = tempfile.mkdtemp()
    md5 = hashlib.md5()
    md5.update(str(random.random()))
    md5 = md5.hexdigest()
    dpath = os.path.join(tmpdir, os.sep.join(pathcomps(md5)))
    os.makedirs(dpath)
    with open(os.path.join(dpath, 'info.json'), 'wb') as f:
        f.write('bogus\n')
    yield md5, tmpdir
    shutil.rmtree(tmpdir)
示例#2
0
def md5dirs():
    """
    Generate 20 random hashes, and create MD5-base directory structures for
    them, returning the three-tuple of hashes, directories, and base directory.

    Base directory is created using ``tempfile.mkdtemp()`` call.
    """
    tmpdir = tempfile.mkdtemp()
    hashes = []
    dirs = []
    for i in range(20):
        md5 = hashlib.md5()
        md5.update(str(random.random()).encode('utf8'))
        h = md5.hexdigest()
        cpath = os.sep.join(pathcomps(h))
        dpath = os.path.join(tmpdir, cpath)
        os.makedirs(dpath)
        hashes.append(h)
        dirs.append(dpath)
    yield hashes, dirs, tmpdir
    shutil.rmtree(tmpdir)