def test_excepthook_raise_system_exit_127(): sys.excepthook = sys.__excepthook__ # restore (changed by prev tests) cli.App(args=()) # should set sys.excepthook which raises SystemExit(127) with pytest.raises(SystemExit) as e: sys.excepthook(None, None, None) assert e.value.code == 127
def test_guess_fmt_aliases(): class FakeFP(object): name = None aliases = { 'yml': 'yaml', } fake_fp = FakeFP() for ext in sorted(aliases): fake_fp.name = 'filename.' + ext assert aliases[ext] == cli.App(args=()).guess_fmt(fake_fp, 'default')
def test_get_dumper_unsupported_fmt(): with pytest.raises(RuntimeError, match='Unsupported output format: garbage'): cli.App(args=()).get_dumper('garbage')
def test_guess_fmt_ignore_fp_defaults(): for fp in sys.stdin, sys.stdout, sys.stderr: assert 'default' == cli.App(args=()).guess_fmt(fp, 'default')
def test_excepthook_overrided(): orig_id = id(sys.excepthook) cli.App(args=()) assert orig_id != id(sys.excepthook)
def test_exit_code_wrong_args(fullname): with pytest.raises(SystemExit) as e: cli.App(args=('--unsupported-option')).run() assert e.value.code == 2
def test_run(): with pytest.raises(NotImplementedError): cli.App(args=()).run()