def test(text, fail=True, beep=False, config="editor*", message=None, call=0, history=False): @command(arg_parser=CommandParser(Choice(("action", None), "cmd_err", "error", "message"))) def cmd(editor, args): nonlocal calls calls += 1 if args.action == "cmd_err": raise mod.CommandError("cmd_err") if args.action == "error": raise Exception("error") if args.action == "message": return args.action calls = 0 messages = [] with test_app(config) as app: bar = mod.CommandBar(app.windows[0], app.text_commander) app.text_commander.add_command(cmd, None, None) def bar_message(msg, *args, exc_info=False, **kw): if exc_info: log.info(str(msg), exc_info=True) messages.append(str(msg)) bar.message = bar_message with expect_beep(beep): bar.execute(text) eq_(messages, [message] if message else []) eq_(bar.failed_command, text if fail else None) eq_(calls, call) eq_(bar.get_history(""), text if history else None) eq_(bar._cached_parser, (None, None, None))
def test(command, focus, recent="DEBAC", prev=0, _config=CONFIG): with test_app(_config) as app: tapp = test_app(app) for doc in recent: app.windows[0].current_editor = tapp.get("editor(%s)" % doc) editor = app.windows[0].current_editor bar = CommandTester(mod.doc, editor=editor) if prev: bar("doc previous %s" % prev) with expect_beep(focus is BEEP): bar(command) if focus is BEEP: focus = recent[-1] state = test_app.split(_config) def f(item): return (item + "*") if focus in item else item eq_(tapp.state, " ".join([f(item) for item in state]))