예제 #1
0
def _feed_cli_with_input(text, editing_mode=EditingMode.EMACS, clipboard=None,
                         history=None):
    """
    Create a CommandLineInterface, feed it with the given user input and return
    the CLI object.

    This returns a (result, CLI) tuple.
    """
    # If the given text doesn't end with a newline, the interface won't finish.
    assert text.endswith('\n')

    loop = PosixEventLoop()
    try:
        inp = PipeInput()
        inp.send_text(text)
        cli = CommandLineInterface(
            application=Application(
                buffer=Buffer(accept_action=AcceptAction.RETURN_DOCUMENT,
                              history=history),
                editing_mode=editing_mode,
                clipboard=clipboard or InMemoryClipboard(),
                key_bindings_registry=KeyBindingManager.for_prompt().registry,
            ),
            eventloop=loop,
            input=inp,
            output=DummyOutput())
        result = cli.run()
        return result, cli
    finally:
        loop.close()
        inp.close()
예제 #2
0
def feed_app_with_input(type, message, text, **kwargs):
    """
    Create a CommandLineInterface, feed it with the given user input and return
    the CLI object.

    This returns a (result, CLI) tuple.
    note: this only works if you import your prompt and then this function!!
    """
    # If the given text doesn't end with a newline, the interface won't finish.
    assert text.endswith('\n')

    application = getattr(prompts, type).question(message, **kwargs)

    loop = PosixEventLoop()
    try:
        inp = PipeInput()
        inp.send_text(text)
        cli = CommandLineInterface(
            application=application,
            eventloop=loop,
            input=inp,
            output=DummyOutput())
        result = cli.run()
        return result, cli
    finally:
        loop.close()
        inp.close()
예제 #3
0
def _feed_cli_with_input(text,
                         editing_mode=EditingMode.EMACS,
                         clipboard=None,
                         history=None):
    """
    Create a CommandLineInterface, feed it with the given user input and return
    the CLI object.

    This returns a (result, CLI) tuple.
    """
    # If the given text doesn't end with a newline, the interface won't finish.
    assert text.endswith('\n')

    from prompt_toolkit.eventloop.posix import PosixEventLoop as EventLoop
    loop = EventLoop()
    try:
        inp = PipeInput()
        inp.send_text(text)
        cli = CommandLineInterface(application=Application(
            buffer=Buffer(accept_action=AcceptAction.RETURN_DOCUMENT,
                          history=history),
            editing_mode=editing_mode,
            clipboard=clipboard or InMemoryClipboard(),
            key_bindings_registry=KeyBindingManager.for_prompt().registry,
        ),
                                   eventloop=loop,
                                   input=inp,
                                   output=DummyOutput())
        result = cli.run()
        return result, cli
    finally:
        loop.close()
        inp.close()
class KeyBindingsTest(unittest.TestCase):
    def init(self):
        self.input = PipeInput()
        output = DummyOutput()
        # self.shell = Shell(input=self.input, output=output)
        self.processor = InputProcessor

    def tearDown(self):
        self.input.close()
예제 #5
0
class KeysTest(unittest.TestCase):
    def setUp(self):
        self.input = PipeInput()
        output = DummyOutput()
        self.aws_shell = AWSShell(None,
                                  mock.Mock(),
                                  mock.Mock(),
                                  input=self.input,
                                  output=output)
        self.processor = self.aws_shell.cli.input_processor

    def tearDown(self):
        self.input.close()

    def feed_key(self, key):
        self.processor.feed(KeyPress(key, u''))
        self.processor.process_keys()

    def test_F2(self):
        match_fuzzy = self.aws_shell.model_completer.match_fuzzy
        self.feed_key(Keys.F2)
        assert match_fuzzy != self.aws_shell.model_completer.match_fuzzy

    def test_F3(self):
        enable_vi_bindings = self.aws_shell.enable_vi_bindings
        with self.assertRaises(InputInterrupt):
            self.feed_key(Keys.F3)
        assert enable_vi_bindings != self.aws_shell.enable_vi_bindings

    def test_F4(self):
        show_completion_columns = self.aws_shell.show_completion_columns
        with self.assertRaises(InputInterrupt):
            self.feed_key(Keys.F4)
        assert show_completion_columns != \
            self.aws_shell.show_completion_columns

    def test_F5(self):
        show_help = self.aws_shell.show_help
        with self.assertRaises(InputInterrupt):
            self.feed_key(Keys.F5)
        assert show_help != self.aws_shell.show_help

    def test_F9(self):
        assert self.aws_shell.cli.current_buffer_name == u'DEFAULT_BUFFER'
        self.feed_key(Keys.F9)
        assert self.aws_shell.cli.current_buffer_name == u'clidocs'

    def test_F10(self):
        self.feed_key(Keys.F10)
        assert self.aws_shell.cli.is_exiting
예제 #6
0
class KeysTest(unittest.TestCase):

    def setUp(self):
        self.input = PipeInput()
        output = DummyOutput()
        self.aws_shell = AWSShell(None, mock.Mock(), mock.Mock(),
                                  input=self.input, output=output)
        self.processor = self.aws_shell.cli.input_processor

    def tearDown(self):
        self.input.close()

    def feed_key(self, key):
        self.processor.feed(KeyPress(key, u''))
        self.processor.process_keys()

    def test_F2(self):
        match_fuzzy = self.aws_shell.model_completer.match_fuzzy
        self.feed_key(Keys.F2)
        assert match_fuzzy != self.aws_shell.model_completer.match_fuzzy

    def test_F3(self):
        enable_vi_bindings = self.aws_shell.enable_vi_bindings
        with self.assertRaises(InputInterrupt):
            self.feed_key(Keys.F3)
            assert enable_vi_bindings != self.aws_shell.enable_vi_bindings

    def test_F4(self):
        show_completion_columns = self.aws_shell.show_completion_columns
        with self.assertRaises(InputInterrupt):
            self.feed_key(Keys.F4)
            assert show_completion_columns != \
                self.aws_shell.show_completion_columns

    def test_F5(self):
        show_help = self.aws_shell.show_help
        with self.assertRaises(InputInterrupt):
            self.feed_key(Keys.F5)
            assert show_help != self.aws_shell.show_help

    def test_F10(self):
        self.feed_key(Keys.F10)
        assert self.aws_shell.cli.is_exiting
예제 #7
0
def _feed_cli_with_input(text, editing_mode=EditingMode.EMACS):
    """
    Create a CommandLineInterface, feed it with the given user input and return
    the CLI object.

    This returns a (result, CLI) tuple.
    """
    # If the given text doesn't end with a newline, the interface won't finish.
    assert text.endswith('\n')

    loop = PosixEventLoop()
    try:
        inp = PipeInput()
        inp.send_text(text)
        cli = CommandLineInterface(
            application=Application(editing_mode=editing_mode),
            eventloop=loop,
            input=inp,
            output=DummyOutput())
        result = cli.run()
        return result, cli
    finally:
        loop.close()
        inp.close()