1
0
Fork 0
forked from josch/img2pdf

Make sure we are using the correct IO class in Python 2.

This commit is contained in:
Stephan Richter 2017-05-22 12:31:52 -04:00
parent 162721b88e
commit 18d637ea34

View file

@ -1,14 +1,23 @@
import unittest import unittest
import os
import img2pdf import img2pdf
import os
import struct
import sys
import zlib import zlib
from PIL import Image from PIL import Image
from io import BytesIO from io import StringIO, BytesIO
import struct
HERE = os.path.dirname(__file__) HERE = os.path.dirname(__file__)
PY3 = sys.version_info[0] >= 3
if PY3:
PdfReaderIO = StringIO
else:
PdfReaderIO = BytesIO
# convert +set date:create +set date:modify -define png:exclude-chunk=time # convert +set date:create +set date:modify -define png:exclude-chunk=time
# we define some variables so that the table below can be narrower # we define some variables so that the table below can be narrower
@ -470,10 +479,9 @@ def test_suite():
orig_imgdata = inf.read() orig_imgdata = inf.read()
output = img2pdf.convert(orig_imgdata, nodate=True, output = img2pdf.convert(orig_imgdata, nodate=True,
with_pdfrw=with_pdfrw) with_pdfrw=with_pdfrw)
from io import StringIO, BytesIO
from pdfrw import PdfReader, PdfName, PdfWriter from pdfrw import PdfReader, PdfName, PdfWriter
from pdfrw.py23_diffs import convert_load, convert_store from pdfrw.py23_diffs import convert_load, convert_store
x = PdfReader(StringIO(convert_load(output))) x = PdfReader(PdfReaderIO(convert_load(output)))
self.assertEqual(sorted(x.keys()), [PdfName.Info, PdfName.Root, self.assertEqual(sorted(x.keys()), [PdfName.Info, PdfName.Root,
PdfName.Size]) PdfName.Size])
self.assertIn(x.Root.Pages.Count, ('1', '2')) self.assertIn(x.Root.Pages.Count, ('1', '2'))