-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fix variables with null default not being required (#1919) * Got rid of walrus operator to support Python 3.7
- Loading branch information
Showing
2 changed files
with
29 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,36 @@ | ||
"""test_read_user_variable.""" | ||
import pytest | ||
from cookiecutter.prompt import read_user_variable | ||
|
||
VARIABLE = 'project_name' | ||
DEFAULT = 'Kivy Project' | ||
|
||
|
||
def test_click_invocation(mocker): | ||
@pytest.fixture | ||
def mock_prompt(mocker): | ||
"""Return a mocked version of the 'Prompt.ask' function.""" | ||
return mocker.patch('rich.prompt.Prompt.ask') | ||
|
||
|
||
def test_click_invocation(mock_prompt): | ||
"""Test click function called correctly by cookiecutter. | ||
Test for string type invocation. | ||
""" | ||
prompt = mocker.patch('rich.prompt.Prompt.ask') | ||
prompt.return_value = DEFAULT | ||
mock_prompt.return_value = DEFAULT | ||
|
||
assert read_user_variable(VARIABLE, DEFAULT) == DEFAULT | ||
|
||
prompt.assert_called_once_with(VARIABLE, default=DEFAULT) | ||
mock_prompt.assert_called_once_with(VARIABLE, default=DEFAULT) | ||
|
||
|
||
def test_input_loop_with_null_default_value(mock_prompt): | ||
"""Test `Prompt.ask` is run repeatedly until a valid answer is provided. | ||
Test for `default_value` parameter equal to None. | ||
""" | ||
# Simulate user providing None input initially and then a valid input | ||
mock_prompt.side_effect = [None, DEFAULT] | ||
|
||
assert read_user_variable(VARIABLE, None) == DEFAULT | ||
assert mock_prompt.call_count == 2 |