See if not using a temp file fixes the weird test failure on travis

This commit is contained in:
Kovid Goyal 2019-08-07 20:07:33 +05:30
parent b4a8771232
commit 470e6b56fe
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 19 additions and 26 deletions

View File

@ -163,7 +163,6 @@ def test_save_to(src, dest):
def test_podofo():
import tempfile
from io import BytesIO
from calibre.ebooks.metadata.book.base import Metadata
from calibre.ebooks.metadata.xmp import metadata_to_xmp_packet
@ -179,19 +178,14 @@ def test_podofo():
buf = BytesIO()
p.save_to_fileobj(buf)
raw = buf.getvalue()
with tempfile.NamedTemporaryFile(delete=False) as f:
f.write(raw)
try:
p = podofo.PDFDoc()
p.open(f.name)
if (p.title, p.author) != (mi.title, mi.authors[0]):
raise ValueError('podofo failed to set title and author in Info dict %s != %s' % (
(p.title, p.author), (mi.title, mi.authors[0])))
if not p.get_xmp_metadata():
raise ValueError('podofo failed to write XMP packet')
del p
finally:
os.remove(f.name)
p = podofo.PDFDoc()
p.load(raw)
if (p.title, p.author) != (mi.title, mi.authors[0]):
raise ValueError('podofo failed to set title and author in Info dict %s != %s' % (
(p.title, p.author), (mi.title, mi.authors[0])))
if not p.get_xmp_metadata():
raise ValueError('podofo failed to write XMP packet')
del p
if __name__ == '__main__':

View File

@ -43,19 +43,18 @@ static PyObject *
PDFDoc_load(PDFDoc *self, PyObject *args) {
char *buffer; Py_ssize_t size;
if (PyArg_ParseTuple(args, BYTES_FMT, &buffer, &size)) {
try {
#if PODOFO_VERSION <= 0x000905
self->doc->Load(buffer, (long)size);
#else
self->doc->LoadFromBuffer(buffer, (long)size);
#endif
} catch(const PdfError & err) {
podofo_set_exception(err);
return NULL;
}
} else return NULL;
if (!PyArg_ParseTuple(args, BYTES_FMT, &buffer, &size)) return NULL;
try {
#if PODOFO_VERSION <= 0x000905
self->doc->Load(buffer, (long)size);
#else
self->doc->LoadFromBuffer(buffer, (long)size);
#endif
} catch(const PdfError & err) {
podofo_set_exception(err);
return NULL;
}
Py_RETURN_NONE;
}