Skip to content

Commit ef6fa32

Browse files
committed
test(init): add yaml not a dict test case
1 parent 8ec67c5 commit ef6fa32

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

commitizen/commands/init.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,14 @@ def _ask_config_path(self) -> str:
134134
"pyproject.toml" if self.project_info.has_pyproject else ".cz.toml"
135135
)
136136

137-
return questionary.select(
138-
"Please choose a supported config file: ",
139-
choices=CONFIG_FILES,
140-
default=default_path,
141-
style=self.cz.style,
142-
).unsafe_ask()
137+
return str(
138+
questionary.select(
139+
"Please choose a supported config file: ",
140+
choices=CONFIG_FILES,
141+
default=default_path,
142+
style=self.cz.style,
143+
).unsafe_ask()
144+
)
143145

144146
def _ask_name(self) -> str:
145147
return str(

tests/commands/test_init_command.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,19 @@ def test_pre_commit_config_yaml_without_repos(_, default_choice, tmpdir, config)
226226
# Should use DEFAULT_CONFIG since the file content doesn't have 'repos' key
227227
check_pre_commit_config([CZ_HOOK_CONFIG])
228228

229+
def test_pre_commit_config_yaml_not_a_dict(_, default_choice, tmpdir, config):
230+
with tmpdir.as_cwd():
231+
# Write a dictionary YAML content without 'repos' key
232+
p = tmpdir.join(PRE_COMMIT_CONFIG_FILENAME)
233+
p.write(
234+
yaml.safe_dump(["item1", "item2"])
235+
) # Dictionary without 'repos' key
236+
237+
commands.Init(config)()
238+
check_cz_config(default_choice)
239+
# Should use DEFAULT_CONFIG since the file content doesn't have 'repos' key
240+
check_pre_commit_config([CZ_HOOK_CONFIG])
241+
229242
def test_cz_hook_exists_in_pre_commit_config(_, default_choice, tmpdir, config):
230243
with tmpdir.as_cwd():
231244
p = tmpdir.join(PRE_COMMIT_CONFIG_FILENAME)

tests/test_git.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ def test_get_commits_with_signature():
269269

270270
def test_get_tag_names_has_correct_arrow_annotation():
271271
arrow_annotation = inspect.getfullargspec(git.get_tag_names).annotations["return"]
272+
272273
assert arrow_annotation == "list[str]"
273274

274275

0 commit comments

Comments
 (0)