Skip to content

refactor(Init): fix unbounded variable in _ask_tag_format #1529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: v4-9-0-test
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test(Init): improve coverage for _ask_tag_format
  • Loading branch information
bearomorphism committed Jun 10, 2025
commit ae143dbaba645d3f663c1d339b1ba471cd69093c
32 changes: 32 additions & 0 deletions tests/commands/test_init_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,38 @@ def test_pre_commit_exec_failed(
commands.Init(config)()


class TestAskTagFormat:
def test_confirm_v_tag_format(self, mocker: MockFixture, config):
init = commands.Init(config)
mocker.patch("questionary.confirm", return_value=FakeQuestion(True))

result = init._ask_tag_format("v1.0.0")
assert result == r"v$version"

def test_reject_v_tag_format(self, mocker: MockFixture, config):
init = commands.Init(config)
mocker.patch("questionary.confirm", return_value=FakeQuestion(False))
mocker.patch("questionary.text", return_value=FakeQuestion("custom-$version"))

result = init._ask_tag_format("v1.0.0")
assert result == "custom-$version"

def test_non_v_tag_format(self, mocker: MockFixture, config):
init = commands.Init(config)
mocker.patch("questionary.text", return_value=FakeQuestion("custom-$version"))

result = init._ask_tag_format("1.0.0")
assert result == "custom-$version"

def test_empty_input_returns_default(self, mocker: MockFixture, config):
init = commands.Init(config)
mocker.patch("questionary.confirm", return_value=FakeQuestion(False))
mocker.patch("questionary.text", return_value=FakeQuestion(""))

result = init._ask_tag_format("v1.0.0")
assert result == "$version" # This is the default format from DEFAULT_SETTINGS


@skip_below_py_3_10
def test_init_command_shows_description_when_use_help_option(
mocker: MockFixture, capsys, file_regression
Expand Down