def getmsgs(): """Yield a couple of test mails along with appropriate folder names. """ mails = Archive().open(testdata) idx = yaml.safe_load(mails.get_metadata(".index.yaml").fileobj) for folder in sorted(idx.keys()): for msg_path in idx[folder]: msgbytes = mails._file.extractfile(msg_path).read() msg = email.message_from_bytes(msgbytes) testmails.append((folder, msg)) yield (folder, msgbytes)
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()