コード例 #1
0
def test_return_correct_last_value():
    with Runner("python3", __file__) as h:
        h.await_text("Which pill ?")
        for _ in range(30):
            h.press("Down")
        h.press("Enter")
        assert "You choose 30" in h.screenshot()
コード例 #2
0
ファイル: test_hecate.py プロジェクト: wileykestner/hecate
def test_can_capture_curses_hline_and_vline_characters():
    with Runner("./tests/fixtures/box.py") as h:
        h.await_text("┌──────────┐")
        h.await_text("│I am a box│")
        h.await_text("└──────────┘")
        h.press("q")
        h.await_exit()
コード例 #3
0
def test_search_after_moved_cursor_down():
    with Runner("python3", __file__) as h:
        h.await_text("Which pill ?")
        for _ in range(30):
            h.press("Down")
        h.press("1")
        assert "1. 1" in h.screenshot()
コード例 #4
0
ファイル: test_hecate.py プロジェクト: wileykestner/hecate
def test_can_send_enter():
    with Runner("cat") as h:
        h.write("hi")
        h.press("Enter")
        h.write("there")
        h.await_text("there")
        assert "hi\nthere" in h.screenshot()
コード例 #5
0
ファイル: test_hecate.py プロジェクト: wileykestner/hecate
def test_uses_last_screenshot_if_server_goes_away():
    with Runner("cat") as h:
        h.write("Hello")
        h.await_text("Hello")
        h.kill("SIGKILL")
        with pytest.raises(AbnormalExit):
            h.await_exit()
        controller = h.report_variables()[r.CONTROLLER]
        os.kill(controller, signal.SIGKILL)
        assert "Hello" in h.screenshot()
コード例 #6
0
ファイル: test_hecate.py プロジェクト: wileykestner/hecate
def test_sets_the_console_size_appropriately():
    with Runner("cat", width=10, height=100) as h:
        h.write("." * 100)
        h.press("Enter")
        h.write("Squirrel")
        h.await_text("Squirrel")
        assert "." * 10 + "\n" + "." * 10 in h.screenshot()
        h.press("Enter")
        h.press("C-d")
        h.await_exit()
コード例 #7
0
def runner():
    """Seed 1
    1  *  2  *  1           1  *
    1  1  2  1  1  1  1  1  1  1
    1  1           1  *  1
    *  1           1  1  1
    1  1        1  1  2  1  1
             1  2  *  3  *  2
             1  *  2  4  *  3
             1  1  1  2  *  2
    """
    with Runner(sys.executable, "-m", "minesweeper_vim.ui", "--seed", "1") as h:
        yield h
コード例 #8
0
def test_inital_grepping(executable_path, tmpdir):
    lines = ['line {}'.format(i) for i in range(5)]
    text_file_path = tmpdir.join('regular_file.txt')
    with text_file_path.open('w') as fh:
        fh.write('\n'.join(lines))
    with Runner(executable_path, str(text_file_path)) as term:
        for line in lines:
            term.await_text(line)
        term.press('g')
        term.press('0')
        term.press('Enter')
        term.await_text(lines[0])
        assert lines[1] not in term.screenshot()
        term.press('q')
コード例 #9
0
def test_greps_switching_in_circle(executable_path, tmpdir):
    lines = ['foo {}'.format(i)
             for i in range(5)] + ['bar {}'.format(i) for i in range(5)]
    greps = [
        lines,
        [line for line in lines if 'bar' in line],
        [line for line in lines if 'bar' in line and '0' in line],
    ]

    def check_term_lines(term, lines_included, lines_not_included):
        term.await_text(lines_included[-1])
        screenshot = term.screenshot()
        for line in lines_included:
            assert line in screenshot
        for line in lines_not_included:
            assert line not in screenshot

    text_file_path = tmpdir.join('regular_file.txt')
    with text_file_path.open('w') as fh:
        fh.write('\n'.join(lines))

    with Runner(executable_path, str(text_file_path)) as term:
        for line in lines:
            term.await_text(line)
        for c in 'gbar':
            term.press(c)
        term.press('Enter')
        for c in 'gbar 0':
            term.press(c)
        term.press('Enter')

        check_term_lines(term, greps[2], set(lines) - set(greps[2]))
        term.press('S-Left')
        check_term_lines(term, greps[1], set(lines) - set(greps[1]))
        term.press('S-Left')
        check_term_lines(term, greps[0], set(lines) - set(greps[0]))
        term.press('S-Left')
        check_term_lines(term, greps[2], set(lines) - set(greps[2]))
        term.press('S-Right')
        check_term_lines(term, greps[0], set(lines) - set(greps[0]))

        term.press('q')
コード例 #10
0
ファイル: test_hecate.py プロジェクト: wileykestner/hecate
def test_can_run_vim():
    f = tempfile.mktemp()
    with Runner("/usr/bin/vim") as h:
        h.await_text("VIM")
        h.press("i")
        h.write("Hello world")
        h.press("Enter")
        h.write("Goodbye world")
        h.press("Escape")
        h.write("dd")
        h.write(":w " + f)
        h.press("Enter")
        h.write(":q")
        h.press("Enter")
        # Second enter because if running with unset environment in tox it will
        # complain that it can't write viminfo and tell you to press enter to
        # continue.
        h.press("Enter")
        h.await_exit()
    with open(f) as r:
        text = r.read()
        assert "Hello world" in text
        assert "Goodbye world" not in text
コード例 #11
0
def test_2_greps(executable_path, tmpdir):
    lines = ['line {}'.format(i) for i in range(5)]
    rows = ['row {}'.format(i) for i in range(5)]
    text_file_path = tmpdir.join('regular_file.txt')
    with text_file_path.open('w') as fh:
        fh.write('\n'.join(lines + rows))
    with Runner(executable_path, str(text_file_path)) as term:
        for line in lines:
            term.await_text(line)
        for row in rows:
            term.await_text(row)
        term.press('g')
        for c in 'row':
            term.press(c)
        term.press('Enter')
        term.await_text(rows[0])
        assert 'line' not in term.screenshot()
        term.press('g')
        term.press('0')
        term.press('Enter')
        term.await_text(rows[0])
        assert 'line' not in term.screenshot()
        assert rows[1] not in term.screenshot()
        term.press('q')
コード例 #12
0
ファイル: test_hecate.py プロジェクト: wileykestner/hecate
def test_can_launch_a_simple_program():
    f = tempfile.mktemp()
    with Runner("bash", "-c", "echo hello world > %s" % (f, )):
        return
    with open(f) as r:
        assert "Hello world" in r.read()
コード例 #13
0
def test_return_correct_first_value():
    with Runner("python3", __file__) as h:
        h.await_text("Which pill ?")
        h.press("Enter")
        assert "You choose 1" in h.screenshot()
コード例 #14
0
def test_long_cursor_down():
    with Runner("python3", __file__) as h:
        h.await_text("Which pill ?")
        for _ in range(30):
            h.press("Down")
        assert ">    19. 30" in h.screenshot()
コード例 #15
0
def test_escape_exit():
    with Runner("python3", __file__) as h:
        h.await_text("Which pill ?")
        h.press("Escape")
        h.press("Escape")
        h.await_exit(timeout=5)
コード例 #16
0
def test_search_item():
    with Runner("python3", __file__) as h:
        h.await_text("Which pill ?")
        h.press("1")
        h.press("3")
        assert ">     1. 13" in h.screenshot()
コード例 #17
0
def term(executable_path, temporary_text_file):
    with Runner(executable_path, temporary_text_file, width=COLS,
                height=ROWS) as r:
        yield r
        r.press('q')
コード例 #18
0
ファイル: test_hecate.py プロジェクト: wileykestner/hecate
def test_can_send_signals_to_child():
    with pytest.raises(AbnormalExit):
        with Runner(sys.executable, PRINTER) as h:
            for s in ["SIGTERM", "SIGUSR1", "SIGQUIT"]:
                h.kill(s)
                h.await_text(s)
コード例 #19
0
ファイル: test_hecate.py プロジェクト: wileykestner/hecate
def test_can_send_eof():
    with Runner("cat") as h:
        h.press("C-d")
        h.await_exit()
コード例 #20
0
ファイル: test_hecate.py プロジェクト: wileykestner/hecate
def test_reports_abnormal_exit():
    with pytest.raises(AbnormalExit):
        with Runner("cat", "/does/not/exist/no/really"):
            pass
コード例 #21
0
ファイル: test_hecate.py プロジェクト: wileykestner/hecate
def test_can_kill_vim():
    with Runner("vim") as h:
        h.await_text("VIM")
        h.press(":")
        h.press("q")
        h.press("Enter")
コード例 #22
0
def test_move_cursor_down():
    with Runner("python3", __file__) as h:
        h.await_text("Which pill ?")
        h.press("Down")
        assert ">     2. 2" in h.screenshot()
コード例 #23
0
def test_minibuffer_shows_unsupported_keystrokes(executable_path):
    with Runner(executable_path) as term:
        for c in 'abcklmxyz':
            term.press(c)
            term.await_text(c)
        term.press('q')
コード例 #24
0
ファイル: test_hecate.py プロジェクト: wileykestner/hecate
def test_can_write_unicode():
    with Runner("cat") as h:
        h.write("☃")
        h.await_text("☃")