Пример #1
0
def test_live_console_input_no_prompt_with_running() -> None:
    with patch('builtins.input', return_value="Hello") as mock_input:
        program = console.input().provide(ConsoleEnvironment(LiveConsole()))
        output = unsafe_run(program)

    assert output == "Hello"
    mock_input.assert_called_with()
Пример #2
0
def test_live_console_print_with_running() -> None:
    with patch('builtins.print', return_value=None) as mock_print:
        program = console.print("Hello world").provide(
            ConsoleEnvironment(LiveConsole()))
        output = unsafe_run(program)
        assert output is None
    mock_print.assert_called_with("Hello world")
Пример #3
0
def test_live_console_input_with_keyboard_interrupt() -> None:
    with patch('builtins.input', side_effect=KeyboardInterrupt) as mock_input:
        program = console.input("Prompt").provide(
            ConsoleEnvironment(LiveConsole()))

        with pytest.raises(KeyboardInterrupt):
            unsafe_run(program)
    mock_input.assert_called_with("Prompt")
Пример #4
0
def test_live_console_input_with_eof_error() -> None:
    with patch('builtins.input', side_effect=EOFError) as mock_input:
        program = console.input("Prompt").provide(
            ConsoleEnvironment(LiveConsole()))

        with pytest.raises(EOFError):
            unsafe_run(program)
    mock_input.assert_called_with("Prompt")
Пример #5
0
def test_mock_console_print() -> None:
    mock_console = MockConsole()
    output = unsafe_run(
        (console.print("Hello") << console.print("World")).provide(
            ConsoleEnvironment(mock_console)))
    assert output is None

    assert mock_console.effects == [
        console_effect.Print("Hello"),
        console_effect.Print("World")
    ]
Пример #6
0
def test_live_console_input_no_prompt_without_running() -> None:
    with patch('builtins.input') as mock_input:
        console.input().provide(ConsoleEnvironment(LiveConsole()))
    mock_input.assert_not_called()
Пример #7
0
def test_live_console_print_without_running() -> None:
    with patch('builtins.print') as mock_print:
        console.print("Hello world").provide(ConsoleEnvironment(LiveConsole()))
    mock_print.assert_not_called()