Ejemplo n.º 1
0
def test_check_extract_archive_custom_metadata(test_dir, testname,
                                               monkeypatch):
    """When extracting an archive and checking the result, 
    check should not report any file to be missing in the archive.

    Same as test_check_extract_archive(), but now using an archive
    having custom metadata.  Issue #25.
    """
    archive_path = test_dir / "archive-custom-md.tar"
    with TemporaryFile(dir=str(test_dir)) as tmpf:
        archive = Archive()
        tmpf.write("Hello world!\n".encode("ascii"))
        tmpf.seek(0)
        archive.add_metadata(".msg.txt", tmpf)
        archive.create(archive_path, "", [Path("base")], workdir=test_dir)
    check_dir = test_dir / testname
    check_dir.mkdir()
    monkeypatch.chdir(str(check_dir))
    with tarfile.open(str(archive_path), "r") as tarf:
        tarf.extractall()
    with TemporaryFile(mode="w+t", dir=str(test_dir)) as f:
        args = ["check", str(archive_path), "base"]
        callscript("archive-tool.py", args, stdout=f)
        f.seek(0)
        assert set(get_output(f)) == set()
Ejemplo n.º 2
0
def test_create_metadata_vs_content(test_dir, testname, monkeypatch):
    """Add additional custom metadata to the archive,
    using a name that conflicts with a content file.
    """
    monkeypatch.chdir(test_dir)
    name = archive_name(tags=[testname])
    p = Path("base")
    with TemporaryFile(dir=test_dir) as tmpf:
        archive = Archive()
        tmpf.write("Hello world!\n".encode("ascii"))
        tmpf.seek(0)
        with pytest.raises(ArchiveCreateError) as err:
            archive.add_metadata("msg.txt", tmpf)
            archive.create(Path(name), "", [p])
        assert "filename is reserved" in str(err.value)
Ejemplo n.º 3
0
def test_create_duplicate_metadata(test_dir, testname, monkeypatch):
    """Add additional custom metadata to the archive,
    using a name that is already taken.
    """
    monkeypatch.chdir(test_dir)
    name = archive_name(tags=[testname])
    p = Path("base")
    with TemporaryFile(dir=test_dir) as tmpf:
        archive = Archive()
        tmpf.write("Hello world!\n".encode("ascii"))
        tmpf.seek(0)
        with pytest.raises(ArchiveCreateError) as err:
            archive.add_metadata(".manifest.yaml", tmpf)
            archive.create(Path(name), "", [p])
        assert "duplicate metadata" in str(err.value)
Ejemplo n.º 4
0
def test_create_custom_metadata(test_dir, monkeypatch):
    """Add additional custom metadata to the archive.
    """
    monkeypatch.chdir(test_dir)
    archive_path = Path("archive-custom-md.tar")
    p = Path("base", "data")
    with TemporaryFile(dir=test_dir) as tmpf:
        archive = Archive()
        tmpf.write("Hello world!\n".encode("ascii"))
        tmpf.seek(0)
        archive.add_metadata(".msg.txt", tmpf)
        archive.create(archive_path, "", [p])
    with Archive().open(archive_path) as archive:
        metadata = ( "base/.manifest.yaml", "base/.msg.txt" )
        assert archive.manifest.metadata == metadata
        md = archive.get_metadata(".msg.txt")
        assert md.path == archive.basedir / ".msg.txt"
        assert md.fileobj.read() == "Hello world!\n".encode("ascii")
        check_manifest(archive.manifest, testdata)
        archive.verify()