This commit is contained in:
@@ -1,62 +0,0 @@
|
||||
import pytest
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||
from slic.utils.ask_yes_no import *
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from unittest.mock import patch
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"default, user_input, expected_output, expected_prompt",
|
||||
[
|
||||
(None, 'y', True, "Question? [y/n] "),
|
||||
(None, 'yes', True, "Question? [y/n] "),
|
||||
(None, 'n', True, "Question? [y/n] "), #False
|
||||
(None, 'no', False, "Question? [y/n] "), #False
|
||||
(None, ['maybe', 'y'], True, "Question? [y/n] "),
|
||||
(None, ['', 'no'], False, "Question? [y/n] "),
|
||||
(None, ['invalid', 'yes'], True, "Question? [y/n] "),
|
||||
('y', 'y', True, "Question? [Y/n] "),
|
||||
('y', 'n', True, "Question? [Y/n] "), #False
|
||||
('y', '', True, "Question? [Y/n] "),
|
||||
('n', 'y', True, "Question? [y/N] "),
|
||||
('n', 'n', True, "Question? [y/N] "), #False
|
||||
('n', '', False, "Question? [y/N] "),
|
||||
]
|
||||
)
|
||||
def test_ask_yes_no_with_defaults(default, user_input, expected_output, expected_prompt):
|
||||
patch_target = 'slic.utils.ask_yes_no.read_input'
|
||||
|
||||
if isinstance(user_input, list):
|
||||
input_patch = patch(patch_target, side_effect=user_input)
|
||||
else:
|
||||
input_patch = patch(patch_target, return_value=user_input)
|
||||
|
||||
with input_patch as mock_input:
|
||||
result = ask_yes_no("Question", default=default)
|
||||
assert result == expected_output
|
||||
|
||||
first_prompt = mock_input.call_args_list[0][0][0]
|
||||
assert first_prompt == expected_prompt
|
||||
|
||||
|
||||
def test_ask_yes_no_ctrl_c():
|
||||
with patch('slic.utils.ask_yes_no.read_input', side_effect=KeyboardInterrupt):
|
||||
result = ask_yes_no("Question?", default=None, ctrl_c="n")
|
||||
assert result is False
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"ctrl_d, expected_result",
|
||||
[
|
||||
('n', False),
|
||||
('y', True),
|
||||
]
|
||||
)
|
||||
def test_ask_yes_no_ctrl_d(ctrl_d, expected_result):
|
||||
with patch('slic.utils.ask_yes_no.read_input', side_effect=EOFError):
|
||||
result = ask_yes_no("Question?", default="y", ctrl_d=ctrl_d)
|
||||
assert result == expected_result
|
||||
|
||||
|
||||
Reference in New Issue
Block a user