mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2026-02-02 14:45:47 +00:00
More small tidyups
- switch to using sys.exit instead of exit - always exit with error-code 1 - don't bother testing error-codes - documentation wording tweak
This commit is contained in:
@@ -7,7 +7,7 @@ Pinout
|
|||||||
|
|
||||||
The gpiozero package contains a database of information about the various
|
The gpiozero package contains a database of information about the various
|
||||||
revisions of Raspberry Pi. This is queried by the ``pinout`` command-line
|
revisions of Raspberry Pi. This is queried by the ``pinout`` command-line
|
||||||
tool to write details of the GPIO pins available.
|
tool to output details of the GPIO pins available.
|
||||||
|
|
||||||
Unless specified, the revision of the current device will be detected. A
|
Unless specified, the revision of the current device will be detected. A
|
||||||
particular revision may be selected with the --revision command-line
|
particular revision may be selected with the --revision command-line
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ def parse_args(args):
|
|||||||
except argparse.ArgumentError as ex:
|
except argparse.ArgumentError as ex:
|
||||||
print('Error parsing arguments.')
|
print('Error parsing arguments.')
|
||||||
parser.error(str(ex.message))
|
parser.error(str(ex.message))
|
||||||
exit(-1)
|
sys.exit(1)
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ def main():
|
|||||||
pi_info().pprint(color=args.color)
|
pi_info().pprint(color=args.color)
|
||||||
except IOError:
|
except IOError:
|
||||||
print('This device is not a Raspberry Pi')
|
print('This device is not a Raspberry Pi')
|
||||||
exit(2)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
pi_info(args.revision).pprint(color=args.color)
|
pi_info(args.revision).pprint(color=args.color)
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ from gpiozero.cli import pinout
|
|||||||
def test_args_incorrect():
|
def test_args_incorrect():
|
||||||
with pytest.raises(SystemExit) as ex:
|
with pytest.raises(SystemExit) as ex:
|
||||||
pinout.parse_args(['--nonexistentarg'])
|
pinout.parse_args(['--nonexistentarg'])
|
||||||
assert ex.value.code == 2
|
|
||||||
|
|
||||||
|
|
||||||
def test_args_color():
|
def test_args_color():
|
||||||
args = pinout.parse_args([])
|
args = pinout.parse_args([])
|
||||||
@@ -26,15 +24,12 @@ def test_args_color():
|
|||||||
args = pinout.parse_args(['--monochrome'])
|
args = pinout.parse_args(['--monochrome'])
|
||||||
assert args.color is False
|
assert args.color is False
|
||||||
|
|
||||||
|
|
||||||
def test_args_revision():
|
def test_args_revision():
|
||||||
args = pinout.parse_args(['--revision', '000d'])
|
args = pinout.parse_args(['--revision', '000d'])
|
||||||
assert args.revision == '000d'
|
assert args.revision == '000d'
|
||||||
|
|
||||||
|
|
||||||
def test_help(capsys):
|
def test_help(capsys):
|
||||||
with pytest.raises(SystemExit) as ex:
|
with pytest.raises(SystemExit) as ex:
|
||||||
pinout.parse_args(['--help'])
|
pinout.parse_args(['--help'])
|
||||||
out, err = capsys.readouterr()
|
out, err = capsys.readouterr()
|
||||||
assert 'GPIO pinout' in out
|
assert 'GPIO pinout' in out
|
||||||
assert ex.value.code == 0
|
|
||||||
|
|||||||
Reference in New Issue
Block a user