From 470e6b56fe46c06288c449a6b986c9b8dba3f0e2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 7 Aug 2019 20:07:33 +0530 Subject: [PATCH] See if not using a temp file fixes the weird test failure on travis --- src/calibre/utils/podofo/__init__.py | 22 ++++++++-------------- src/calibre/utils/podofo/doc.cpp | 23 +++++++++++------------ 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/src/calibre/utils/podofo/__init__.py b/src/calibre/utils/podofo/__init__.py index 9cefa3f364..65f09f78c6 100644 --- a/src/calibre/utils/podofo/__init__.py +++ b/src/calibre/utils/podofo/__init__.py @@ -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__': diff --git a/src/calibre/utils/podofo/doc.cpp b/src/calibre/utils/podofo/doc.cpp index 60bb6d69b9..e5c5154a23 100644 --- a/src/calibre/utils/podofo/doc.cpp +++ b/src/calibre/utils/podofo/doc.cpp @@ -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; }