src/tests/__init__.py: fix CommandLineTests on python3

main
parent 78183c642b
commit 0639dbd47c
Signed by untrusted user: josch
GPG Key ID: F2CBA5C78FBD83E1

@ -435,21 +435,29 @@ def tiff_header_for_ccitt(width, height, img_size, ccitt_group=4):
class CommandLineTests(unittest.TestCase): class CommandLineTests(unittest.TestCase):
def test_main_help(self): def test_main_help(self):
# silence output
sys_stdout = sys.stdout
if PY3: if PY3:
sys.stdout = TextIOWrapper(BytesIO()) 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: else:
# silence output
sys_stdout = sys.stdout
sys.stdout = BytesIO() sys.stdout = BytesIO()
try: try:
img2pdf.main(['img2pdf', '--help']) img2pdf.main(['img2pdf', '--help'])
except SystemExit: except SystemExit:
# argparse does sys.exit(0) on --help # argparse does sys.exit(0) on --help
res = sys.stdout.getvalue() res = sys.stdout.getvalue()
self.assertIn('img2pdf', res) self.assertIn('img2pdf', res)
finally: finally:
sys.stdout = sys_stdout sys.stdout = sys_stdout
def test_suite(): def test_suite():

Loading…
Cancel
Save