Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b4b38bb

Browse files
committed
test(Init): cover _ask_tag test
1 parent e1376d3 commit b4b38bb

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

tests/commands/test_init_command.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,94 @@ def test_init_command_shows_description_when_use_help_option(
266266

267267
out, _ = capsys.readouterr()
268268
file_regression.check(out, extension=".txt")
269+
270+
271+
def test_init_with_confirmed_tag_format(config, mocker: MockFixture, tmpdir):
272+
mocker.patch(
273+
"commitizen.commands.init.get_tag_names", return_value=["v0.0.2", "v0.0.1"]
274+
)
275+
mocker.patch("commitizen.commands.init.get_latest_tag_name", return_value="v0.0.2")
276+
mocker.patch(
277+
"questionary.select",
278+
side_effect=[
279+
FakeQuestion("pyproject.toml"),
280+
FakeQuestion("cz_conventional_commits"),
281+
FakeQuestion("commitizen"),
282+
FakeQuestion("semver"),
283+
],
284+
)
285+
mocker.patch("questionary.confirm", return_value=FakeQuestion(True))
286+
mocker.patch("questionary.text", return_value=FakeQuestion("$version"))
287+
mocker.patch("questionary.checkbox", return_value=FakeQuestion(None))
288+
289+
with tmpdir.as_cwd():
290+
commands.Init(config)()
291+
with open("pyproject.toml", encoding="utf-8") as toml_file:
292+
assert 'tag_format = "v$version"' in toml_file.read()
293+
294+
295+
def test_init_with_no_existing_tags(config, mocker: MockFixture, tmpdir):
296+
mocker.patch("commitizen.commands.init.get_tag_names", return_value=[])
297+
mocker.patch("commitizen.commands.init.get_latest_tag_name", return_value="v1.0.0")
298+
mocker.patch(
299+
"questionary.select",
300+
side_effect=[
301+
FakeQuestion("pyproject.toml"),
302+
FakeQuestion("cz_conventional_commits"),
303+
FakeQuestion("commitizen"),
304+
FakeQuestion("semver"),
305+
],
306+
)
307+
mocker.patch("questionary.confirm", return_value=FakeQuestion(False))
308+
mocker.patch("questionary.text", return_value=FakeQuestion("$version"))
309+
mocker.patch("questionary.checkbox", return_value=FakeQuestion(None))
310+
311+
with tmpdir.as_cwd():
312+
commands.Init(config)()
313+
with open("pyproject.toml", encoding="utf-8") as toml_file:
314+
assert 'version = "0.0.1"' in toml_file.read()
315+
316+
317+
def test_init_with_no_existing_latest_tag(config, mocker: MockFixture, tmpdir):
318+
mocker.patch("commitizen.commands.init.get_latest_tag_name", return_value=None)
319+
mocker.patch(
320+
"questionary.select",
321+
side_effect=[
322+
FakeQuestion("pyproject.toml"),
323+
FakeQuestion("cz_conventional_commits"),
324+
FakeQuestion("commitizen"),
325+
FakeQuestion("semver"),
326+
],
327+
)
328+
mocker.patch("questionary.confirm", return_value=FakeQuestion(True))
329+
mocker.patch("questionary.text", return_value=FakeQuestion("$version"))
330+
mocker.patch("questionary.checkbox", return_value=FakeQuestion(None))
331+
332+
with tmpdir.as_cwd():
333+
commands.Init(config)()
334+
with open("pyproject.toml", encoding="utf-8") as toml_file:
335+
assert 'version = "0.0.1"' in toml_file.read()
336+
337+
338+
def test_init_with_existing_tags(config, mocker: MockFixture, tmpdir):
339+
expected_tags = ["v1.0.0", "v0.9.0", "v0.8.0"]
340+
mocker.patch("commitizen.commands.init.get_tag_names", return_value=expected_tags)
341+
mocker.patch("commitizen.commands.init.get_latest_tag_name", return_value="v1.0.0")
342+
mocker.patch(
343+
"questionary.select",
344+
side_effect=[
345+
FakeQuestion("pyproject.toml"),
346+
FakeQuestion("cz_conventional_commits"),
347+
FakeQuestion("commitizen"),
348+
FakeQuestion("semver"), # Select version scheme first
349+
FakeQuestion("v1.0.0"), # Then select the latest tag
350+
],
351+
)
352+
mocker.patch("questionary.confirm", return_value=FakeQuestion(True))
353+
mocker.patch("questionary.text", return_value=FakeQuestion("$version"))
354+
mocker.patch("questionary.checkbox", return_value=FakeQuestion(None))
355+
356+
with tmpdir.as_cwd():
357+
commands.Init(config)()
358+
with open("pyproject.toml", encoding="utf-8") as toml_file:
359+
assert 'version = "1.0.0"' in toml_file.read()

0 commit comments

Comments
 (0)