Пример #1
0
def test_prompt(cli_runner):
    with cli_runner.isolation() as outstreams:
        cmd = ClickCmd(hist_file='.history')

        cmd.prompt = 'foobar > '

        cmd.cmdloop()

        output = outstreams[0].getvalue() \
            .decode(cli_runner.charset, 'replace').replace('\r\n', '\n')

    assert output == 'foobar > \n'

    os.remove('.history')
Пример #2
0
def test_prompt(monkeypatch):
    stdin = StringIO()
    stdout = StringIO()

    monkeypatch.setattr('sys.stdin', stdin)
    monkeypatch.setattr('sys.stdout', stdout)
    cmd = ClickCmd(hist_file='.history')

    cmd.prompt = 'foobar > '

    cmd.cmdloop()

    assert stdout.getvalue() == 'foobar > \n'

    os.remove('.history')
Пример #3
0
def test_prompt(monkeypatch):
    stdin = StringIO()
    stdout = StringIO()

    monkeypatch.setattr('sys.stdin', stdin)
    monkeypatch.setattr('sys.stdout', stdout)
    cmd = ClickCmd(hist_file='.history')

    cmd.prompt = 'foobar > '

    cmd.cmdloop()

    assert stdout.getvalue() == 'foobar > \n'

    os.remove('.history')
Пример #4
0
def test_changable_prompt(cli_runner):
    with cli_runner.isolation(input='\n\n\n') as outstreams:

        cmd = ClickCmd(hist_file='.history')

        class Prompt(object):
            def __init__(self):
                self.num = 0

            def __call__(self):
                self.num += 1
                return "prompt #{} > ".format(self.num)

        cmd.prompt = Prompt()

        cmd.cmdloop()

        output = outstreams[0].getvalue() \
            .decode(cli_runner.charset, 'replace').replace('\r\n', '\n')

    assert output == 'prompt #1 > prompt #2 > prompt #3 > prompt #4 > \n'

    os.remove('.history')