Skip to content

Commit ae143db

Browse files
committed
test(Init): improve coverage for _ask_tag_format
1 parent 6f9a3d2 commit ae143db

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/commands/test_init_command.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,38 @@ def test_pre_commit_exec_failed(
255255
commands.Init(config)()
256256

257257

258+
class TestAskTagFormat:
259+
def test_confirm_v_tag_format(self, mocker: MockFixture, config):
260+
init = commands.Init(config)
261+
mocker.patch("questionary.confirm", return_value=FakeQuestion(True))
262+
263+
result = init._ask_tag_format("v1.0.0")
264+
assert result == r"v$version"
265+
266+
def test_reject_v_tag_format(self, mocker: MockFixture, config):
267+
init = commands.Init(config)
268+
mocker.patch("questionary.confirm", return_value=FakeQuestion(False))
269+
mocker.patch("questionary.text", return_value=FakeQuestion("custom-$version"))
270+
271+
result = init._ask_tag_format("v1.0.0")
272+
assert result == "custom-$version"
273+
274+
def test_non_v_tag_format(self, mocker: MockFixture, config):
275+
init = commands.Init(config)
276+
mocker.patch("questionary.text", return_value=FakeQuestion("custom-$version"))
277+
278+
result = init._ask_tag_format("1.0.0")
279+
assert result == "custom-$version"
280+
281+
def test_empty_input_returns_default(self, mocker: MockFixture, config):
282+
init = commands.Init(config)
283+
mocker.patch("questionary.confirm", return_value=FakeQuestion(False))
284+
mocker.patch("questionary.text", return_value=FakeQuestion(""))
285+
286+
result = init._ask_tag_format("v1.0.0")
287+
assert result == "$version" # This is the default format from DEFAULT_SETTINGS
288+
289+
258290
@skip_below_py_3_10
259291
def test_init_command_shows_description_when_use_help_option(
260292
mocker: MockFixture, capsys, file_regression

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy