Esempio n. 1
0
    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"
Esempio n. 2
0
 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()
Esempio n. 3
0
 def test_notify(self):
     notify = (
         "************************************************************\n"
         "*                                                          *\n"
         "*                           foo                            *\n"
         "*                                                          *\n"
         "************************************************************")
     with capture_stdout() as capture:
         ui.notify("foo")
     assert notify.strip() == capture.result.strip()
Esempio n. 4
0
 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()
Esempio n. 5
0
 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()
Esempio n. 6
0
 def test_notify(self):
     notify = (
         "************************************************************\n"
         "*                                                          *\n"
         "*                           foo                            *\n"
         "*                                                          *\n"
         "************************************************************"
     )
     with capture_stdout() as capture:
         ui.notify("foo")
     assert notify.strip() == capture.result.strip()
Esempio n. 7
0
 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()
Esempio n. 8
0
    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'])
Esempio n. 9
0
    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'])
Esempio n. 10
0
 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"
Esempio n. 11
0
 def test_message(self):
     with capture_stdout() as capture:
         ui.message("foo bar baz")
     assert capture.result == "foo bar baz\n"
Esempio n. 12
0
 def test_ticker(self):
     with capture_stdout() as capture:
         ui.ticker()
     assert capture.result == ""
Esempio n. 13
0
 def test_message(self):
     with capture_stdout() as capture:
         ui.message("foo bar baz")
     assert capture.result == "foo bar baz\n"
Esempio n. 14
0
 def test_ticker(self):
     with capture_stdout() as capture:
         ui.ticker()
     assert capture.result == ""
Esempio n. 15
0
 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"