Skip to content

Commit 6f5d6f2

Browse files
committed
Make sure the the viewer scripts exits with the correct error code when displaying the help page
Fixes #427
1 parent cdecd3a commit 6f5d6f2

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

can/viewer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def parse_args(args):
384384
choices=sorted(can.VALID_INTERFACES))
385385

386386
# Print help message when no arguments are given
387-
if len(args) < 2:
387+
if len(args) == 0:
388388
parser.print_help(sys.stderr)
389389
import errno
390390
raise SystemExit(errno.EINVAL)

test/test_viewer.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,16 @@ def test_parse_args(self):
436436
parsed_args, _, _ = parse_args(['--interface', 'pcan'])
437437
self.assertEqual(parsed_args.interface, 'pcan')
438438

439-
# Make sure the help message is printed when no arguments are given
440-
with self.assertRaises(SystemExit):
441-
parsed_args, _, _ = parse_args([])
439+
# Make sure the it exits with the correct error code when displaying the help page
440+
# See: https://github.com/hardbyte/python-can/issues/427
441+
with self.assertRaises(SystemExit) as cm:
442+
parse_args(['-h'])
443+
self.assertEqual(cm.exception.code, 0)
444+
445+
with self.assertRaises(SystemExit) as cm:
446+
parse_args([])
447+
import errno
448+
self.assertEqual(cm.exception.code, errno.EINVAL)
442449

443450

444451
if __name__ == '__main__':

0 commit comments

Comments
 (0)