def test_interactive_help(mock_input, capfd): mock_input.set_side_effect('?', 'n') assert autofix_lib._interactive_check(use_color=False) is False out, _ = capfd.readouterr() assert out == ('***Looks good [y,n,s,q,?]? <<?\n' 'y (yes): yes it looks good, commit and continue.\n' 'n (no): no, do not commit this repository.\n' 's (shell): open an interactive shell in the repo.\n' 'q (quit, ^C): early exit from the autofixer.\n' '? (help): show this help message.\n' '***Looks good [y,n,s,q,?]? <<n\n')
def test_interactive_shell(mock_input, capfd): mock_input.set_side_effect('s', 'n') with mock.patch.dict(os.environ, {'SHELL': 'echo'}): assert autofix_lib._interactive_check(use_color=False) is False out, _ = capfd.readouterr() assert out == ( '***Looks good [y,n,s,q,?]? <<s\n' 'Opening an interactive shell, type `exit` to continue.\n' 'Any modifications will be committed.\n' # A newline from echo '\n' '***Looks good [y,n,s,q,?]? <<n\n')
def test_interactive_control_c(mock_input, capfd): mock_input.set_side_effect(KeyboardInterrupt) with pytest.raises(SystemExit): autofix_lib._interactive_check(use_color=False) out, _ = capfd.readouterr() assert out == ('***Looks good [y,n,s,q,?]? ^C\n' 'Goodbye!\n')
def test_interactive_no(mock_input, capfd): mock_input.set_side_effect('n') assert autofix_lib._interactive_check(use_color=False) is False out, _ = capfd.readouterr() assert out == '***Looks good [y,n,s,q,?]? <<n\n'
def test_interactive_yes(mock_input, capfd): mock_input.side_effect = _get_input_side_effect('y') assert autofix_lib._interactive_check(use_color=False) is True out, _ = capfd.readouterr() assert out == '***Looks good [y,n,s,q,?]? <<y\n'
def test_interactive_quit(mock_input, capfd): mock_input.side_effect = _get_input_side_effect('q') with pytest.raises(SystemExit): autofix_lib._interactive_check(use_color=False) out, _ = capfd.readouterr() assert out == ('***Looks good [y,n,s,q,?]? <<q\n' 'Goodbye!\n')