1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
from unittest.mock import MagicMock
from ...utils import NoMatchString, PartialMatchString
def test_override_is_used(convert_command):
"""The override value is used even if PEP621 data is present."""
(convert_command.base_path / "pyproject.toml").write_text(
'[project]\nname="test-name"', encoding="utf-8"
)
assert convert_command.input_app_name("OVERRIDE") == "OVERRIDE"
def test_no_pep621_data(convert_command, monkeypatch):
"""The app directory is used if there is no PEP621-name."""
mock_text_question = MagicMock()
monkeypatch.setattr(convert_command.console, "text_question", mock_text_question)
convert_command.base_path /= "test-app-name"
convert_command.input_app_name(None)
mock_text_question.assert_called_once_with(
intro=PartialMatchString(
"Based on your PEP508 formatted directory name, we suggest an app name of 'test-app-name'"
),
description="App Name",
default="test-app-name",
validator=convert_command.validate_app_name,
override_value=None,
)
def test_valid_pep621_app_name(convert_command):
"""The PEP621-name is used if present and valid."""
(convert_command.base_path / "pyproject.toml").write_text(
'[project]\nname="test-name"', encoding="utf-8"
)
assert convert_command.input_app_name(None) == "test-name"
def test_pep621_name_is_canonicalized(convert_command):
(convert_command.base_path / "pyproject.toml").write_text(
'[project]\nname="test.name"', encoding="utf-8"
)
assert convert_command.input_app_name(None) == "test-name"
def test_invalid_hint_app_name(convert_command, monkeypatch):
"""A placeholder is used if there's no PEP621 name and the app directory is an
invalid name."""
mock_text_question = MagicMock()
monkeypatch.setattr(convert_command.console, "text_question", mock_text_question)
convert_command.base_path /= "!app_name"
convert_command.input_app_name(None)
mock_text_question.assert_called_once_with(
intro=NoMatchString(
"Based on your PEP508 formatted directory name, we suggest an app name of 'test-app-name'"
),
description="App Name",
default="hello-world",
validator=convert_command.validate_app_name,
override_value=None,
)
def test_hint_is_canonicalized(convert_command, monkeypatch):
"""The app directory name is canonicalized when used as a hint."""
mock_text_question = MagicMock()
monkeypatch.setattr(convert_command.console, "text_question", mock_text_question)
convert_command.base_path /= "test-app_name"
convert_command.input_app_name(None)
mock_text_question.assert_called_once_with(
intro=PartialMatchString(
"Based on your PEP508 formatted directory name, we suggest an app name of 'test-app-name'"
),
description="App Name",
default="test-app-name",
validator=convert_command.validate_app_name,
override_value=None,
)
|