summaryrefslogtreecommitdiff
path: root/src/tests/__init__.py
diff options
context:
space:
mode:
authorJohannes 'josch' Schauer <josch@debian.org>2020-04-28 13:41:41 +0200
committerJohannes 'josch' Schauer <josch@debian.org>2020-04-28 13:41:41 +0200
commitbfa3c202c5b422b27b6ffc074697f6e64a53b6b3 (patch)
tree43cf2aa36a1ef5a008078c8b47f33ad5e9850c25 /src/tests/__init__.py
parente7866e5e3c125b734332dd93843ef683332c0a43 (diff)
New upstream version 0.3.5
Diffstat (limited to 'src/tests/__init__.py')
-rw-r--r--src/tests/__init__.py42
1 files changed, 14 insertions, 28 deletions
diff --git a/src/tests/__init__.py b/src/tests/__init__.py
index 807aa84..7997218 100644
--- a/src/tests/__init__.py
+++ b/src/tests/__init__.py
@@ -10,12 +10,7 @@ from io import StringIO, BytesIO, TextIOWrapper
HERE = os.path.dirname(__file__)
-PY3 = sys.version_info[0] >= 3
-
-if PY3:
- PdfReaderIO = StringIO
-else:
- PdfReaderIO = BytesIO
+PdfReaderIO = StringIO
# Recompressing the image stream makes the comparison robust against output
# preserving changes in the zlib compress output bitstream
@@ -480,29 +475,15 @@ def tiff_header_for_ccitt(width, height, img_size, ccitt_group=4):
class CommandLineTests(unittest.TestCase):
def test_main_help(self):
- if PY3:
- from contextlib import redirect_stdout
- f = StringIO()
- with redirect_stdout(f):
- try:
- img2pdf.main(['img2pdf', '--help'])
- except SystemExit:
- pass
- res = f.getvalue()
- self.assertIn('img2pdf', res)
- else:
- # silence output
- sys_stdout = sys.stdout
- sys.stdout = BytesIO()
-
+ from contextlib import redirect_stdout
+ f = StringIO()
+ with redirect_stdout(f):
try:
img2pdf.main(['img2pdf', '--help'])
except SystemExit:
- # argparse does sys.exit(0) on --help
- res = sys.stdout.getvalue()
- self.assertIn('img2pdf', res)
- finally:
- sys.stdout = sys_stdout
+ pass
+ res = f.getvalue()
+ self.assertIn('img2pdf', res)
def test_suite():
@@ -554,12 +535,17 @@ def test_suite():
assert os.path.isfile(outputf)
def handle(self, f=inputf, out=outputf, with_pdfrw=with_pdfrw):
+ try:
+ from pdfrw import PdfReader, PdfName, PdfWriter
+ from pdfrw.py23_diffs import convert_load, convert_store
+ except ImportError:
+ # the test requires pdfrw
+ self.skipTest("this test requires pdfrw")
+ return
with open(f, "rb") as inf:
orig_imgdata = inf.read()
output = img2pdf.convert(orig_imgdata, nodate=True,
with_pdfrw=with_pdfrw)
- from pdfrw import PdfReader, PdfName, PdfWriter
- from pdfrw.py23_diffs import convert_load, convert_store
x = PdfReader(PdfReaderIO(convert_load(output)))
self.assertEqual(sorted(x.keys()), [PdfName.Info, PdfName.Root,
PdfName.Size])