Exemple #1
0
def check_archive(archive, tmp_path):
    assert sorted(
        archive.getnames()) == ['test', 'test/test2.txt', 'test1.txt']
    expected = []
    expected.append({'filename': 'test'})
    expected.append({
        'lastwritetime': 12786932616,
        'as_datetime': datetime(2006, 3, 15, 21, 43, 36, 0, UTC()),
        'filename': 'test/test2.txt'
    })
    expected.append({
        'lastwritetime': 12786932628,
        'as_datetime': datetime(2006, 3, 15, 21, 43, 48, 0, UTC()),
        'filename': 'test1.txt'
    })
    for i, cf in enumerate(archive.files):
        assert cf.filename == expected[i]['filename']
        if not cf.is_directory:
            assert cf.lastwritetime // 10000000 == expected[i]['lastwritetime']
            assert cf.lastwritetime.as_datetime().replace(
                microsecond=0) == expected[i]['as_datetime']
    archive.extractall(path=tmp_path)
    assert tmp_path.joinpath('test/test2.txt').open('rb').read() == bytes(
        'This file is located in a folder.', 'ascii')
    assert tmp_path.joinpath('test1.txt').open('rb').read() == bytes(
        'This file is located in the root.', 'ascii')
Exemple #2
0
def check_archive(archive, tmp_path, return_dict: bool):
    assert sorted(archive.getnames()) == ["test", "test/test2.txt", "test1.txt"]
    expected = []
    expected.append({"filename": "test"})
    expected.append(
        {
            "lastwritetime": 12786932616,
            "as_datetime": datetime(2006, 3, 15, 21, 43, 36, 0, UTC()),
            "filename": "test/test2.txt",
        }
    )
    expected.append(
        {
            "lastwritetime": 12786932628,
            "as_datetime": datetime(2006, 3, 15, 21, 43, 48, 0, UTC()),
            "filename": "test1.txt",
        }
    )
    for i, cf in enumerate(archive.files):
        assert cf.filename == expected[i]["filename"]
        if not cf.is_directory:
            assert cf.lastwritetime // 10000000 == expected[i]["lastwritetime"]
            assert cf.lastwritetime.as_datetime().replace(microsecond=0) == expected[i]["as_datetime"]
    if not return_dict:
        archive.extractall(path=tmp_path)
        assert tmp_path.joinpath("test/test2.txt").open("rb").read() == bytes("This file is located in a folder.", "ascii")
        assert tmp_path.joinpath("test1.txt").open("rb").read() == bytes("This file is located in the root.", "ascii")
    else:
        _dict = archive.readall()
        actual = _dict["test/test2.txt"].read()
        assert actual == bytes("This file is located in a folder.", "ascii")
        actual = _dict["test1.txt"].read()
        assert actual == bytes("This file is located in the root.", "ascii")
    archive.close()