Skip to content

Commit 79ce43e

Browse files
committed
test: rename fixture config to default_config to avoid name conflict
1 parent bc1542c commit 79ce43e

26 files changed

+405
-364
lines changed

tests/commands/conftest.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,9 @@
44
import pytest
55
from pytest_mock import MockerFixture, MockType
66

7-
from commitizen import defaults
8-
from commitizen.config import BaseConfig
97
from commitizen.config.json_config import JsonConfig
108

119

12-
@pytest.fixture
13-
def config() -> BaseConfig:
14-
_config = BaseConfig()
15-
_config.settings.update({"name": defaults.DEFAULT_SETTINGS["name"]})
16-
return _config
17-
18-
1910
@pytest.fixture
2011
def config_customize() -> JsonConfig:
2112
json_string = r"""{
@@ -50,11 +41,6 @@ def changelog_path() -> str:
5041
return os.path.join(os.getcwd(), "CHANGELOG.md")
5142

5243

53-
@pytest.fixture
54-
def config_path() -> str:
55-
return os.path.join(os.getcwd(), "pyproject.toml")
56-
57-
5844
@pytest.fixture
5945
def success_mock(mocker: MockerFixture) -> MockType:
6046
return mocker.patch("commitizen.out.success")

tests/commands/test_changelog_command.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def test_changelog_incremental_keep_a_changelog_sample(
256256
@pytest.mark.usefixtures("tmp_commitizen_project")
257257
@pytest.mark.parametrize("dry_run", [True, False])
258258
def test_changelog_hook(
259-
mocker: MockFixture, config: BaseConfig, dry_run: bool, util: UtilFixture
259+
mocker: MockFixture, default_config: BaseConfig, dry_run: bool, util: UtilFixture
260260
):
261261
changelog_hook_mock = mocker.Mock()
262262
changelog_hook_mock.return_value = "cool changelog hook"
@@ -265,9 +265,10 @@ def test_changelog_hook(
265265
util.create_file_and_commit("refactor: is in changelog")
266266
util.create_file_and_commit("Merge into master")
267267

268-
config.settings["change_type_order"] = ["Refactor", "Feat"] # type: ignore[typeddict-unknown-key]
268+
default_config.settings["change_type_order"] = ["Refactor", "Feat"] # type: ignore[typeddict-unknown-key]
269269
changelog = Changelog(
270-
config, {"unreleased_version": None, "incremental": True, "dry_run": dry_run}
270+
default_config,
271+
{"unreleased_version": None, "incremental": True, "dry_run": dry_run},
271272
)
272273
mocker.patch.object(changelog.cz, "changelog_hook", changelog_hook_mock)
273274
if dry_run:
@@ -312,7 +313,7 @@ def test_changelog_hook_customize(
312313

313314
@pytest.mark.usefixtures("tmp_commitizen_project")
314315
def test_changelog_release_hook(
315-
mocker: MockFixture, config: BaseConfig, util: UtilFixture
316+
mocker: MockFixture, default_config: BaseConfig, util: UtilFixture
316317
):
317318
def changelog_release_hook(release: dict, tag: git.GitTag) -> dict:
318319
return release
@@ -325,7 +326,8 @@ def changelog_release_hook(release: dict, tag: git.GitTag) -> dict:
325326

326327
# changelog = Changelog(config, {})
327328
changelog = Changelog(
328-
config, {"unreleased_version": None, "incremental": True, "dry_run": False}
329+
default_config,
330+
{"unreleased_version": None, "incremental": True, "dry_run": False},
329331
)
330332
mocker.patch.object(changelog.cz, "changelog_release_hook", changelog_release_hook)
331333
spy = mocker.spy(changelog.cz, "changelog_release_hook")
@@ -1196,7 +1198,7 @@ def test_changelog_prerelease_rev_with_use_scheme_semver(
11961198

11971199
@pytest.mark.usefixtures("tmp_commitizen_project")
11981200
def test_changelog_uses_version_tags_for_header(
1199-
mocker: MockFixture, config: BaseConfig, util: UtilFixture
1201+
mocker: MockFixture, default_config: BaseConfig, util: UtilFixture
12001202
):
12011203
"""Tests that changelog headers always use version tags even if there are non-version tags
12021204
@@ -1211,7 +1213,8 @@ def test_changelog_uses_version_tags_for_header(
12111213
write_patch = mocker.patch("commitizen.commands.changelog.out.write")
12121214

12131215
changelog = Changelog(
1214-
config, {"dry_run": True, "incremental": True, "unreleased_version": None}
1216+
default_config,
1217+
{"dry_run": True, "incremental": True, "unreleased_version": None},
12151218
)
12161219

12171220
with pytest.raises(DryRunExit):
@@ -1227,7 +1230,7 @@ def test_changelog_uses_version_tags_for_header(
12271230
@pytest.mark.usefixtures("tmp_commitizen_project")
12281231
@pytest.mark.freeze_time("2022-02-13")
12291232
def test_changelog_from_current_version_tag_with_nonversion_tag(
1230-
mocker: MockFixture, config: BaseConfig, util: UtilFixture
1233+
mocker: MockFixture, default_config: BaseConfig, util: UtilFixture
12311234
):
12321235
"""Tests that changelog generation for a single version works even if
12331236
there is a non-version tag in the list of tags
@@ -1251,7 +1254,7 @@ def test_changelog_from_current_version_tag_with_nonversion_tag(
12511254

12521255
with pytest.raises(DryRunExit):
12531256
Changelog(
1254-
config,
1257+
default_config,
12551258
{
12561259
"dry_run": True,
12571260
"incremental": False,

tests/commands/test_check_command.py

Lines changed: 66 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ def test_check_conventional_commit_succeeds(
123123
),
124124
),
125125
)
126-
def test_check_no_conventional_commit(commit_msg, config, tmpdir):
126+
def test_check_no_conventional_commit(commit_msg, default_config, tmpdir):
127127
tempfile = tmpdir.join("temp_commit_file")
128128
tempfile.write(commit_msg)
129129

130130
with pytest.raises(InvalidCommitMessageError):
131-
commands.Check(config=config, arguments={"commit_msg_file": tempfile})()
131+
commands.Check(config=default_config, arguments={"commit_msg_file": tempfile})()
132132

133133

134134
@pytest.mark.parametrize(
@@ -140,44 +140,50 @@ def test_check_no_conventional_commit(commit_msg, config, tmpdir):
140140
"bump: 0.0.1 -> 1.0.0",
141141
),
142142
)
143-
def test_check_conventional_commit(commit_msg, config, success_mock: MockType, tmpdir):
143+
def test_check_conventional_commit(
144+
commit_msg, default_config, success_mock: MockType, tmpdir
145+
):
144146
tempfile = tmpdir.join("temp_commit_file")
145147
tempfile.write(commit_msg)
146-
commands.Check(config=config, arguments={"commit_msg_file": tempfile})()
148+
commands.Check(config=default_config, arguments={"commit_msg_file": tempfile})()
147149
success_mock.assert_called_once()
148150

149151

150-
def test_check_command_when_commit_file_not_found(config):
152+
def test_check_command_when_commit_file_not_found(default_config):
151153
with pytest.raises(FileNotFoundError):
152-
commands.Check(config=config, arguments={"commit_msg_file": "no_such_file"})()
154+
commands.Check(
155+
config=default_config, arguments={"commit_msg_file": "no_such_file"}
156+
)()
153157

154158

155159
def test_check_a_range_of_git_commits(
156-
config, success_mock: MockType, mocker: MockFixture
160+
default_config, success_mock: MockType, mocker: MockFixture
157161
):
158162
mocker.patch(
159163
"commitizen.git.get_commits", return_value=_build_fake_git_commits(COMMIT_LOG)
160164
)
161165

162-
commands.Check(config=config, arguments={"rev_range": "HEAD~10..master"})()
166+
commands.Check(config=default_config, arguments={"rev_range": "HEAD~10..master"})()
163167
success_mock.assert_called_once()
164168

165169

166-
def test_check_a_range_of_git_commits_and_failed(config, mocker: MockFixture):
170+
def test_check_a_range_of_git_commits_and_failed(default_config, mocker: MockFixture):
167171
mocker.patch(
168172
"commitizen.git.get_commits",
169173
return_value=_build_fake_git_commits(["This commit does not follow rule"]),
170174
)
171175

172176
with pytest.raises(InvalidCommitMessageError) as excinfo:
173-
commands.Check(config=config, arguments={"rev_range": "HEAD~10..master"})()
177+
commands.Check(
178+
config=default_config, arguments={"rev_range": "HEAD~10..master"}
179+
)()
174180
assert "This commit does not follow rule" in str(excinfo.value)
175181

176182

177-
def test_check_command_with_invalid_argument(config):
183+
def test_check_command_with_invalid_argument(default_config):
178184
with pytest.raises(InvalidCommandArgumentError) as excinfo:
179185
commands.Check(
180-
config=config,
186+
config=default_config,
181187
arguments={"commit_msg_file": "some_file", "rev_range": "HEAD~10..master"},
182188
)
183189
assert (
@@ -187,15 +193,17 @@ def test_check_command_with_invalid_argument(config):
187193

188194

189195
@pytest.mark.usefixtures("tmp_commitizen_project")
190-
def test_check_command_with_empty_range(config: BaseConfig, util: UtilFixture):
196+
def test_check_command_with_empty_range(default_config: BaseConfig, util: UtilFixture):
191197
# must initialize git with a commit
192198
util.create_file_and_commit("feat: initial")
193199
with pytest.raises(NoCommitsFoundError) as excinfo:
194-
commands.Check(config=config, arguments={"rev_range": "master..master"})()
200+
commands.Check(
201+
config=default_config, arguments={"rev_range": "master..master"}
202+
)()
195203
assert "No commit found with range: 'master..master'" in str(excinfo)
196204

197205

198-
def test_check_a_range_of_failed_git_commits(config, mocker: MockFixture):
206+
def test_check_a_range_of_failed_git_commits(default_config, mocker: MockFixture):
199207
ill_formatted_commits_msgs = [
200208
"First commit does not follow rule",
201209
"Second commit does not follow rule",
@@ -207,59 +215,66 @@ def test_check_a_range_of_failed_git_commits(config, mocker: MockFixture):
207215
)
208216

209217
with pytest.raises(InvalidCommitMessageError) as excinfo:
210-
commands.Check(config=config, arguments={"rev_range": "HEAD~10..master"})()
218+
commands.Check(
219+
config=default_config, arguments={"rev_range": "HEAD~10..master"}
220+
)()
211221
assert all([msg in str(excinfo.value) for msg in ill_formatted_commits_msgs])
212222

213223

214-
def test_check_command_with_valid_message(config, success_mock: MockType):
224+
def test_check_command_with_valid_message(default_config, success_mock: MockType):
215225
commands.Check(
216-
config=config, arguments={"message": "fix(scope): some commit message"}
226+
config=default_config,
227+
arguments={"message": "fix(scope): some commit message"},
217228
)()
218229
success_mock.assert_called_once()
219230

220231

221232
@pytest.mark.parametrize("message", ["bad commit", ""])
222-
def test_check_command_with_invalid_message(config, message):
233+
def test_check_command_with_invalid_message(default_config, message):
223234
with pytest.raises(InvalidCommitMessageError):
224-
commands.Check(config=config, arguments={"message": message})()
235+
commands.Check(config=default_config, arguments={"message": message})()
225236

226237

227-
def test_check_command_with_allow_abort_arg(config, success_mock):
228-
commands.Check(config=config, arguments={"message": "", "allow_abort": True})()
238+
def test_check_command_with_allow_abort_arg(default_config, success_mock):
239+
commands.Check(
240+
config=default_config, arguments={"message": "", "allow_abort": True}
241+
)()
229242
success_mock.assert_called_once()
230243

231244

232-
def test_check_command_with_allow_abort_config(config, success_mock):
233-
config.settings["allow_abort"] = True
234-
commands.Check(config=config, arguments={"message": ""})()
245+
def test_check_command_with_allow_abort_config(default_config, success_mock):
246+
default_config.settings["allow_abort"] = True
247+
commands.Check(config=default_config, arguments={"message": ""})()
235248
success_mock.assert_called_once()
236249

237250

238-
def test_check_command_override_allow_abort_config(config):
239-
config.settings["allow_abort"] = True
251+
def test_check_command_override_allow_abort_config(default_config):
252+
default_config.settings["allow_abort"] = True
240253
with pytest.raises(InvalidCommitMessageError):
241-
commands.Check(config=config, arguments={"message": "", "allow_abort": False})()
254+
commands.Check(
255+
config=default_config, arguments={"message": "", "allow_abort": False}
256+
)()
242257

243258

244-
def test_check_command_with_allowed_prefixes_arg(config, success_mock):
259+
def test_check_command_with_allowed_prefixes_arg(default_config, success_mock):
245260
commands.Check(
246-
config=config,
261+
config=default_config,
247262
arguments={"message": "custom! test", "allowed_prefixes": ["custom!"]},
248263
)()
249264
success_mock.assert_called_once()
250265

251266

252-
def test_check_command_with_allowed_prefixes_config(config, success_mock):
253-
config.settings["allowed_prefixes"] = ["custom!"]
254-
commands.Check(config=config, arguments={"message": "custom! test"})()
267+
def test_check_command_with_allowed_prefixes_config(default_config, success_mock):
268+
default_config.settings["allowed_prefixes"] = ["custom!"]
269+
commands.Check(config=default_config, arguments={"message": "custom! test"})()
255270
success_mock.assert_called_once()
256271

257272

258-
def test_check_command_override_allowed_prefixes_config(config):
259-
config.settings["allow_abort"] = ["fixup!"]
273+
def test_check_command_override_allowed_prefixes_config(default_config):
274+
default_config.settings["allow_abort"] = ["fixup!"]
260275
with pytest.raises(InvalidCommitMessageError):
261276
commands.Check(
262-
config=config,
277+
config=default_config,
263278
arguments={"message": "fixup! test", "allowed_prefixes": ["custom!"]},
264279
)()
265280

@@ -336,58 +351,58 @@ def test_check_conventional_commit_succeed_with_git_diff(
336351
assert "Commit validation: successful!" in out
337352

338353

339-
def test_check_command_with_message_length_limit(config, success_mock):
354+
def test_check_command_with_message_length_limit(default_config, success_mock):
340355
message = "fix(scope): some commit message"
341356
commands.Check(
342-
config=config,
357+
config=default_config,
343358
arguments={"message": message, "message_length_limit": len(message) + 1},
344359
)()
345360
success_mock.assert_called_once()
346361

347362

348-
def test_check_command_with_message_length_limit_exceeded(config):
363+
def test_check_command_with_message_length_limit_exceeded(default_config):
349364
message = "fix(scope): some commit message"
350365
with pytest.raises(CommitMessageLengthExceededError):
351366
commands.Check(
352-
config=config,
367+
config=default_config,
353368
arguments={"message": message, "message_length_limit": len(message) - 1},
354369
)()
355370

356371

357-
def test_check_command_with_amend_prefix_default(config, success_mock):
358-
commands.Check(config=config, arguments={"message": "amend! test"})()
372+
def test_check_command_with_amend_prefix_default(default_config, success_mock):
373+
commands.Check(config=default_config, arguments={"message": "amend! test"})()
359374
success_mock.assert_called_once()
360375

361376

362-
def test_check_command_with_config_message_length_limit(config, success_mock):
377+
def test_check_command_with_config_message_length_limit(default_config, success_mock):
363378
message = "fix(scope): some commit message"
364-
config.settings["message_length_limit"] = len(message) + 1
379+
default_config.settings["message_length_limit"] = len(message) + 1
365380
commands.Check(
366-
config=config,
381+
config=default_config,
367382
arguments={"message": message},
368383
)()
369384
success_mock.assert_called_once()
370385

371386

372-
def test_check_command_with_config_message_length_limit_exceeded(config):
387+
def test_check_command_with_config_message_length_limit_exceeded(default_config):
373388
message = "fix(scope): some commit message"
374-
config.settings["message_length_limit"] = len(message) - 1
389+
default_config.settings["message_length_limit"] = len(message) - 1
375390
with pytest.raises(CommitMessageLengthExceededError):
376391
commands.Check(
377-
config=config,
392+
config=default_config,
378393
arguments={"message": message},
379394
)()
380395

381396

382397
def test_check_command_cli_overrides_config_message_length_limit(
383-
config, success_mock: MockType
398+
default_config, success_mock: MockType
384399
):
385400
message = "fix(scope): some commit message"
386-
config.settings["message_length_limit"] = len(message) - 1
401+
default_config.settings["message_length_limit"] = len(message) - 1
387402
for message_length_limit in [len(message) + 1, 0]:
388403
success_mock.reset_mock()
389404
commands.Check(
390-
config=config,
405+
config=default_config,
391406
arguments={
392407
"message": message,
393408
"message_length_limit": message_length_limit,

0 commit comments

Comments
 (0)