Skip to content

Commit f289ff6

Browse files
committed
test(commands/init): add tests cases for the whole init process
1 parent 7a0915b commit f289ff6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

‎tests/commands/test_init_command.py

+34
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,40 @@
11
from commitizen import commands
22

33

4+
class FakeQuestion:
5+
def __init__(self, expected_return):
6+
self.expected_return = expected_return
7+
8+
def ask(self):
9+
return self.expected_return
10+
11+
12+
def test_init(tmpdir, mocker, config):
13+
mocker.patch(
14+
"questionary.select",
15+
side_effect=[
16+
FakeQuestion("pyproject.toml"),
17+
FakeQuestion("cz_conventional_commits"),
18+
],
19+
)
20+
mocker.patch("questionary.confirm", return_value=FakeQuestion("y"))
21+
mocker.patch("questionary.text", return_value=FakeQuestion("y"))
22+
expected_config = (
23+
"[tool.commitizen]\n"
24+
'name = "cz_conventional_commits"\n'
25+
'version = "0.0.1"\n'
26+
'tag_format = "y"\n'
27+
)
28+
29+
with tmpdir.as_cwd():
30+
commands.Init(config)()
31+
32+
with open("pyproject.toml", "r") as toml_file:
33+
config_data = toml_file.read()
34+
35+
assert config_data == expected_config
36+
37+
438
def test_init_when_config_already_exists(config, capsys):
539
# Set config path
640
path = "tests/pyproject.toml"

0 commit comments

Comments
 (0)