def test_help_displayed(args: List[str], capsys: CaptureFixture): try: # -h raises it, no args doesn’t. Maybe not ideal but meh. main(args) except SystemExit as se: assert se.code == 0 captured = capsys.readouterr() assert captured.out.startswith('usage: ')
def test_help_output(set_path: type(None), capsys: CaptureFixture): with pytest.raises(SystemExit, match='^0$'): main(['-h']) captured = capsys.readouterr() assert re.search( r'^positional arguments:\n\s+\{settings,[\w,-]*testbin[\w,-]*\}$', captured.out, re.MULTILINE, )
def test_external(set_path: type(None)): # We need to capture the output manually, since subprocesses don’t write to sys.stderr cmd = main(['testbin', '-t', '--testarg', 'testpos'], stdout=PIPE, encoding='utf-8', check=True) assert cmd.stdout == 'test -t --testarg testpos\n'
def test_error_wrong_command(capsys: CaptureFixture): with pytest.raises(SystemExit, match='^2$'): main(['idonotexist--']) captured = capsys.readouterr() assert 'No command “idonotexist--”. Choose from' in captured.err
def test_builtin_settings(capsys: CaptureFixture): main(['settings']) captured = capsys.readouterr() assert captured.out == f'{scanpy.settings}\n'