Merge pull request #137 from pubs/fix/135

Fixes tests for printing help on `--help` and without argument.
main
Olivier Mangin 7 years ago committed by GitHub
commit 857ebdef00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -39,11 +39,10 @@ class FakeSystemExit(Exception):
Added explicit __init__ so SystemExit.code functionality could be emulated. Added explicit __init__ so SystemExit.code functionality could be emulated.
Taking form from https://stackoverflow.com/a/26938914/1634191 Taking form from https://stackoverflow.com/a/26938914/1634191
""" """
def __init__(self, message, code=None, *args): def __init__(self, code=None, *args):
self.message = message
self.code = code self.code = code
super(FakeSystemExit, self).__init__(
super(FakeSystemExit, self).__init__(message, *args) "Exited with code: {}.".format(self.code), *args)
# code for fake fs # code for fake fs
@ -202,7 +201,6 @@ class TestAlone(CommandTestCase):
self.assertEqual(cm.exception.code, 2) self.assertEqual(cm.exception.code, 2)
@unittest.skipIf(sys.version_info.major == 2, "not supported for Python2")
def test_alone_prints_help(self): def test_alone_prints_help(self):
# capturing the output of `pubs --help` is difficult because argparse # capturing the output of `pubs --help` is difficult because argparse
# raises as SystemExit(0) after calling `print_help`, and this gets # raises as SystemExit(0) after calling `print_help`, and this gets
@ -210,14 +208,15 @@ class TestAlone(CommandTestCase):
# `pubs --help` isn't too easy unless substantially reorganization of # `pubs --help` isn't too easy unless substantially reorganization of
# the parser and testing context is made. instead, the exit codes of # the parser and testing context is made. instead, the exit codes of
# the two usecases are compared. # the two usecases are compared.
with self.assertRaises(FakeSystemExit) as cm1: with self.assertRaises(FakeSystemExit) as cm1:
self.execute_cmds(['pubs']) self.execute_cmds(['pubs'])
self.assertEqual(cm1.exception.code, 2)
def test_help_prints_help(self):
# see test_alone_prints_help
with self.assertRaises(FakeSystemExit) as cm2: with self.assertRaises(FakeSystemExit) as cm2:
self.execute_cmds(['pubs', '--help']) self.execute_cmds(['pubs init', 'pubs --help'])
self.assertEqual(cm2.exception.code, 0)
self.assertEqual(cm1.exception.code, cm2.exception.code, 2)
class TestInit(CommandTestCase): class TestInit(CommandTestCase):

Loading…
Cancel
Save