Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion can/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def parse_args(args):
choices=sorted(can.VALID_INTERFACES))

# Print help message when no arguments are given
if len(args) < 2:
if len(args) == 0:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be just:

if not args:

parser.print_help(sys.stderr)
import errno
raise SystemExit(errno.EINVAL)
Expand Down
13 changes: 10 additions & 3 deletions test/test_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,16 @@ def test_parse_args(self):
parsed_args, _, _ = parse_args(['--interface', 'pcan'])
self.assertEqual(parsed_args.interface, 'pcan')

# Make sure the help message is printed when no arguments are given
with self.assertRaises(SystemExit):
parsed_args, _, _ = parse_args([])
# Make sure it exits with the correct error code when displaying the help page
# See: https://github.com/hardbyte/python-can/issues/427
with self.assertRaises(SystemExit) as cm:
parse_args(['-h'])
self.assertEqual(cm.exception.code, 0)

with self.assertRaises(SystemExit) as cm:
parse_args([])
import errno
self.assertEqual(cm.exception.code, errno.EINVAL)


if __name__ == '__main__':
Expand Down