def test_command(self): doc = """Usage: command foo""" config = _fake_config with raises(DocoptExit): args = docopt(str(doc)) class SmallCommand(Command): def __init__(self, config, args): self.config = config self.args = args self.manager = _manager(token=config['api_token']) def foo(self): print("foo-answer") def bar(self): print("bar-answer") with capture_stdout() as capture: output = SmallCommand(config, docopt(str(doc), argv=['foo'])).run() assert capture.result == "foo-answer\n" with capture_stdout() as capture: output = SmallCommand(config, []).run("bar") assert capture.result == "bar-answer\n"
def test_warning(self): warning = ( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" "! !\n" "! foo !\n" "! !\n" "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n") with capture_stdout() as capture: ui.warning("foo") assert warning.strip() == capture.result.strip()
def test_notify(self): notify = ( "************************************************************\n" "* *\n" "* foo *\n" "* *\n" "************************************************************") with capture_stdout() as capture: ui.notify("foo") assert notify.strip() == capture.result.strip()
def test_heading(self): heading = ( "------------------------------------------------------------\n" "| |\n" "| foo |\n" "| |\n" "------------------------------------------------------------\n") with capture_stdout() as capture: ui.heading("foo") assert heading.strip() == capture.result.strip()
def test_warning(self): warning = ( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" "! !\n" "! foo !\n" "! !\n" "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" ) with capture_stdout() as capture: ui.warning("foo") assert warning.strip() == capture.result.strip()
def test_notify(self): notify = ( "************************************************************\n" "* *\n" "* foo *\n" "* *\n" "************************************************************" ) with capture_stdout() as capture: ui.notify("foo") assert notify.strip() == capture.result.strip()
def test_heading(self): heading = ( "------------------------------------------------------------\n" "| |\n" "| foo |\n" "| |\n" "------------------------------------------------------------\n" ) with capture_stdout() as capture: ui.heading("foo") assert heading.strip() == capture.result.strip()
def test_command(self): doc = """Usage: command foo""" argv = ['foo'] class SmallCommand(Command): def foo(self): print("foo-answer") def bar(self): print("bar-answer") command = SmallCommand(doc, argv=argv) with capture_stdout() as capture: output = command.run() assert capture.result == "foo-answer\n" with capture_stdout() as capture: output = command.run("bar") assert capture.result == "bar-answer\n" with raises(DocoptExit): command = SmallCommand(doc, argv=['baz'])
def test_rsa_keygen(self): _call.side_effect = lambda x: print("generating a public key" % x) with capture_stdout() as capture: configure.rsa_keygen("foo") assert capture.result == "generating a public key\n"
def test_message(self): with capture_stdout() as capture: ui.message("foo bar baz") assert capture.result == "foo bar baz\n"
def test_ticker(self): with capture_stdout() as capture: ui.ticker() assert capture.result == ""