forked from josch/img2pdf
Make sure we are using the correct IO class in Python 2.
This commit is contained in:
parent
162721b88e
commit
18d637ea34
1 changed files with 13 additions and 5 deletions
|
@ -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'))
|
||||||
|
|
Loading…
Reference in a new issue