Skip to content

Commit 430eaa9

Browse files
committed
test: rename the fixture config to mock_config for better code search
1 parent a472bea commit 430eaa9

31 files changed

+376
-341
lines changed

tests/commands/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
@pytest.fixture()
10-
def config():
10+
def mock_config():
1111
_config = BaseConfig()
1212
_config.settings.update({"name": defaults.DEFAULT_SETTINGS["name"]})
1313
return _config

tests/commands/test_bump_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ def test_bump_dry_run(mocker: MockFixture, capsys):
608608
assert tag_exists is False
609609

610610

611-
def test_bump_in_non_git_project(tmpdir, config, mocker: MockFixture):
611+
def test_bump_in_non_git_project(tmpdir, mock_config, mocker: MockFixture):
612612
testargs = ["cz", "bump", "--yes"]
613613
mocker.patch.object(sys, "argv", testargs)
614614

tests/commands/test_changelog_command.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -279,17 +279,18 @@ def test_changelog_incremental_keep_a_changelog_sample(
279279

280280
@pytest.mark.usefixtures("tmp_commitizen_project")
281281
@pytest.mark.parametrize("dry_run", [True, False])
282-
def test_changelog_hook(mocker: MockFixture, config: BaseConfig, dry_run: bool):
282+
def test_changelog_hook(mocker: MockFixture, mock_config: BaseConfig, dry_run: bool):
283283
changelog_hook_mock = mocker.Mock()
284284
changelog_hook_mock.return_value = "cool changelog hook"
285285

286286
create_file_and_commit("feat: new file")
287287
create_file_and_commit("refactor: is in changelog")
288288
create_file_and_commit("Merge into master")
289289

290-
config.settings["change_type_order"] = ["Refactor", "Feat"] # type: ignore[typeddict-unknown-key]
290+
mock_config.settings["change_type_order"] = ["Refactor", "Feat"] # type: ignore[typeddict-unknown-key]
291291
changelog = Changelog(
292-
config, {"unreleased_version": None, "incremental": True, "dry_run": dry_run}
292+
mock_config,
293+
{"unreleased_version": None, "incremental": True, "dry_run": dry_run},
293294
)
294295
mocker.patch.object(changelog.cz, "changelog_hook", changelog_hook_mock)
295296
try:
@@ -330,7 +331,7 @@ def test_changelog_hook_customize(mocker: MockFixture, config_customize):
330331

331332

332333
@pytest.mark.usefixtures("tmp_commitizen_project")
333-
def test_changelog_release_hook(mocker: MockFixture, config):
334+
def test_changelog_release_hook(mocker: MockFixture, mock_config):
334335
def changelog_release_hook(release: dict, tag: git.GitTag) -> dict:
335336
return release
336337

@@ -340,9 +341,9 @@ def changelog_release_hook(release: dict, tag: git.GitTag) -> dict:
340341
create_file_and_commit("Merge into master")
341342
git.tag(f"0.{i + 1}.0")
342343

343-
# changelog = Changelog(config, {})
344+
# changelog = Changelog(mock_config, {})
344345
changelog = Changelog(
345-
config, {"unreleased_version": None, "incremental": True, "dry_run": False}
346+
mock_config, {"unreleased_version": None, "incremental": True, "dry_run": False}
346347
)
347348
mocker.patch.object(changelog.cz, "changelog_release_hook", changelog_release_hook)
348349
spy = mocker.spy(changelog.cz, "changelog_release_hook")
@@ -529,7 +530,7 @@ def test_changelog_with_different_tag_name_and_changelog_content(
529530
cli.main()
530531

531532

532-
def test_changelog_in_non_git_project(tmpdir, config, mocker: MockFixture):
533+
def test_changelog_in_non_git_project(tmpdir, mock_config, mocker: MockFixture):
533534
testargs = ["cz", "changelog", "--incremental"]
534535
mocker.patch.object(sys, "argv", testargs)
535536

@@ -1382,7 +1383,7 @@ def test_changelog_prerelease_rev_with_use_scheme_semver(
13821383

13831384

13841385
@pytest.mark.usefixtures("tmp_commitizen_project")
1385-
def test_changelog_uses_version_tags_for_header(mocker: MockFixture, config):
1386+
def test_changelog_uses_version_tags_for_header(mocker: MockFixture, mock_config):
13861387
"""Tests that changelog headers always use version tags even if there are non-version tags
13871388
13881389
This tests a scenario fixed in this commit:
@@ -1396,7 +1397,7 @@ def test_changelog_uses_version_tags_for_header(mocker: MockFixture, config):
13961397
write_patch = mocker.patch("commitizen.commands.changelog.out.write")
13971398

13981399
changelog = Changelog(
1399-
config, {"dry_run": True, "incremental": True, "unreleased_version": None}
1400+
mock_config, {"dry_run": True, "incremental": True, "unreleased_version": None}
14001401
)
14011402

14021403
with pytest.raises(DryRunExit):
@@ -1411,7 +1412,7 @@ def test_changelog_uses_version_tags_for_header(mocker: MockFixture, config):
14111412

14121413
@pytest.mark.usefixtures("tmp_commitizen_project")
14131414
def test_changelog_from_current_version_tag_with_nonversion_tag(
1414-
mocker: MockFixture, config
1415+
mocker: MockFixture, mock_config
14151416
):
14161417
"""Tests that changelog generation for a single version works even if
14171418
there is a non-version tag in the list of tags
@@ -1450,7 +1451,7 @@ def test_changelog_from_current_version_tag_with_nonversion_tag(
14501451
write_patch = mocker.patch("commitizen.commands.changelog.out.write")
14511452

14521453
changelog = Changelog(
1453-
config,
1454+
mock_config,
14541455
{
14551456
"dry_run": True,
14561457
"incremental": False,

tests/commands/test_check_command.py

Lines changed: 60 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,17 @@ def test_check_conventional_commit_succeeds(mocker: MockFixture, capsys):
141141
),
142142
),
143143
)
144-
def test_check_no_conventional_commit(commit_msg, config, mocker: MockFixture, tmpdir):
144+
def test_check_no_conventional_commit(
145+
commit_msg, mock_config, mocker: MockFixture, tmpdir
146+
):
145147
with pytest.raises(InvalidCommitMessageError):
146148
error_mock = mocker.patch("commitizen.out.error")
147149

148150
tempfile = tmpdir.join("temp_commit_file")
149151
tempfile.write(commit_msg)
150152

151153
check_cmd = commands.Check(
152-
config=config, arguments={"commit_msg_file": tempfile}
154+
config=mock_config, arguments={"commit_msg_file": tempfile}
153155
)
154156
check_cmd()
155157
error_mock.assert_called_once()
@@ -164,56 +166,62 @@ def test_check_no_conventional_commit(commit_msg, config, mocker: MockFixture, t
164166
"bump: 0.0.1 -> 1.0.0",
165167
),
166168
)
167-
def test_check_conventional_commit(commit_msg, config, mocker: MockFixture, tmpdir):
169+
def test_check_conventional_commit(
170+
commit_msg, mock_config, mocker: MockFixture, tmpdir
171+
):
168172
success_mock = mocker.patch("commitizen.out.success")
169173

170174
tempfile = tmpdir.join("temp_commit_file")
171175
tempfile.write(commit_msg)
172176

173-
check_cmd = commands.Check(config=config, arguments={"commit_msg_file": tempfile})
177+
check_cmd = commands.Check(
178+
config=mock_config, arguments={"commit_msg_file": tempfile}
179+
)
174180

175181
check_cmd()
176182
success_mock.assert_called_once()
177183

178184

179-
def test_check_command_when_commit_file_not_found(config):
185+
def test_check_command_when_commit_file_not_found(mock_config):
180186
with pytest.raises(FileNotFoundError):
181-
commands.Check(config=config, arguments={"commit_msg_file": "no_such_file"})()
187+
commands.Check(
188+
config=mock_config, arguments={"commit_msg_file": "no_such_file"}
189+
)()
182190

183191

184-
def test_check_a_range_of_git_commits(config, mocker: MockFixture):
192+
def test_check_a_range_of_git_commits(mock_config, mocker: MockFixture):
185193
success_mock = mocker.patch("commitizen.out.success")
186194
mocker.patch(
187195
"commitizen.git.get_commits", return_value=_build_fake_git_commits(COMMIT_LOG)
188196
)
189197

190198
check_cmd = commands.Check(
191-
config=config, arguments={"rev_range": "HEAD~10..master"}
199+
config=mock_config, arguments={"rev_range": "HEAD~10..master"}
192200
)
193201

194202
check_cmd()
195203
success_mock.assert_called_once()
196204

197205

198-
def test_check_a_range_of_git_commits_and_failed(config, mocker: MockFixture):
206+
def test_check_a_range_of_git_commits_and_failed(mock_config, mocker: MockFixture):
199207
error_mock = mocker.patch("commitizen.out.error")
200208
mocker.patch(
201209
"commitizen.git.get_commits",
202210
return_value=_build_fake_git_commits(["This commit does not follow rule"]),
203211
)
204212
check_cmd = commands.Check(
205-
config=config, arguments={"rev_range": "HEAD~10..master"}
213+
config=mock_config, arguments={"rev_range": "HEAD~10..master"}
206214
)
207215

208216
with pytest.raises(InvalidCommitMessageError):
209217
check_cmd()
210218
error_mock.assert_called_once()
211219

212220

213-
def test_check_command_with_invalid_argument(config):
221+
def test_check_command_with_invalid_argument(mock_config):
214222
with pytest.raises(InvalidCommandArgumentError) as excinfo:
215223
commands.Check(
216-
config=config,
224+
config=mock_config,
217225
arguments={"commit_msg_file": "some_file", "rev_range": "HEAD~10..master"},
218226
)
219227
assert (
@@ -223,18 +231,20 @@ def test_check_command_with_invalid_argument(config):
223231

224232

225233
@pytest.mark.usefixtures("tmp_commitizen_project")
226-
def test_check_command_with_empty_range(config, mocker: MockFixture):
234+
def test_check_command_with_empty_range(mock_config, mocker: MockFixture):
227235
# must initialize git with a commit
228236
create_file_and_commit("feat: initial")
229237

230-
check_cmd = commands.Check(config=config, arguments={"rev_range": "master..master"})
238+
check_cmd = commands.Check(
239+
config=mock_config, arguments={"rev_range": "master..master"}
240+
)
231241
with pytest.raises(NoCommitsFoundError) as excinfo:
232242
check_cmd()
233243

234244
assert "No commit found with range: 'master..master'" in str(excinfo)
235245

236246

237-
def test_check_a_range_of_failed_git_commits(config, mocker: MockFixture):
247+
def test_check_a_range_of_failed_git_commits(mock_config, mocker: MockFixture):
238248
ill_formated_commits_msgs = [
239249
"First commit does not follow rule",
240250
"Second commit does not follow rule",
@@ -245,98 +255,102 @@ def test_check_a_range_of_failed_git_commits(config, mocker: MockFixture):
245255
return_value=_build_fake_git_commits(ill_formated_commits_msgs),
246256
)
247257
check_cmd = commands.Check(
248-
config=config, arguments={"rev_range": "HEAD~10..master"}
258+
config=mock_config, arguments={"rev_range": "HEAD~10..master"}
249259
)
250260

251261
with pytest.raises(InvalidCommitMessageError) as excinfo:
252262
check_cmd()
253263
assert all([msg in str(excinfo.value) for msg in ill_formated_commits_msgs])
254264

255265

256-
def test_check_command_with_valid_message(config, mocker: MockFixture):
266+
def test_check_command_with_valid_message(mock_config, mocker: MockFixture):
257267
success_mock = mocker.patch("commitizen.out.success")
258268
check_cmd = commands.Check(
259-
config=config, arguments={"message": "fix(scope): some commit message"}
269+
config=mock_config, arguments={"message": "fix(scope): some commit message"}
260270
)
261271

262272
check_cmd()
263273
success_mock.assert_called_once()
264274

265275

266-
def test_check_command_with_invalid_message(config, mocker: MockFixture):
276+
def test_check_command_with_invalid_message(mock_config, mocker: MockFixture):
267277
error_mock = mocker.patch("commitizen.out.error")
268-
check_cmd = commands.Check(config=config, arguments={"message": "bad commit"})
278+
check_cmd = commands.Check(config=mock_config, arguments={"message": "bad commit"})
269279

270280
with pytest.raises(InvalidCommitMessageError):
271281
check_cmd()
272282
error_mock.assert_called_once()
273283

274284

275-
def test_check_command_with_empty_message(config, mocker: MockFixture):
285+
def test_check_command_with_empty_message(mock_config, mocker: MockFixture):
276286
error_mock = mocker.patch("commitizen.out.error")
277-
check_cmd = commands.Check(config=config, arguments={"message": ""})
287+
check_cmd = commands.Check(config=mock_config, arguments={"message": ""})
278288

279289
with pytest.raises(InvalidCommitMessageError):
280290
check_cmd()
281291
error_mock.assert_called_once()
282292

283293

284-
def test_check_command_with_allow_abort_arg(config, mocker: MockFixture):
294+
def test_check_command_with_allow_abort_arg(mock_config, mocker: MockFixture):
285295
success_mock = mocker.patch("commitizen.out.success")
286296
check_cmd = commands.Check(
287-
config=config, arguments={"message": "", "allow_abort": True}
297+
config=mock_config, arguments={"message": "", "allow_abort": True}
288298
)
289299

290300
check_cmd()
291301
success_mock.assert_called_once()
292302

293303

294-
def test_check_command_with_allow_abort_config(config, mocker: MockFixture):
304+
def test_check_command_with_allow_abort_config(mock_config, mocker: MockFixture):
295305
success_mock = mocker.patch("commitizen.out.success")
296-
config.settings["allow_abort"] = True
297-
check_cmd = commands.Check(config=config, arguments={"message": ""})
306+
mock_config.settings["allow_abort"] = True
307+
check_cmd = commands.Check(config=mock_config, arguments={"message": ""})
298308

299309
check_cmd()
300310
success_mock.assert_called_once()
301311

302312

303-
def test_check_command_override_allow_abort_config(config, mocker: MockFixture):
313+
def test_check_command_override_allow_abort_config(mock_config, mocker: MockFixture):
304314
error_mock = mocker.patch("commitizen.out.error")
305-
config.settings["allow_abort"] = True
315+
mock_config.settings["allow_abort"] = True
306316
check_cmd = commands.Check(
307-
config=config, arguments={"message": "", "allow_abort": False}
317+
config=mock_config, arguments={"message": "", "allow_abort": False}
308318
)
309319

310320
with pytest.raises(InvalidCommitMessageError):
311321
check_cmd()
312322
error_mock.assert_called_once()
313323

314324

315-
def test_check_command_with_allowed_prefixes_arg(config, mocker: MockFixture):
325+
def test_check_command_with_allowed_prefixes_arg(mock_config, mocker: MockFixture):
316326
success_mock = mocker.patch("commitizen.out.success")
317327
check_cmd = commands.Check(
318-
config=config,
328+
config=mock_config,
319329
arguments={"message": "custom! test", "allowed_prefixes": ["custom!"]},
320330
)
321331

322332
check_cmd()
323333
success_mock.assert_called_once()
324334

325335

326-
def test_check_command_with_allowed_prefixes_config(config, mocker: MockFixture):
336+
def test_check_command_with_allowed_prefixes_config(mock_config, mocker: MockFixture):
327337
success_mock = mocker.patch("commitizen.out.success")
328-
config.settings["allowed_prefixes"] = ["custom!"]
329-
check_cmd = commands.Check(config=config, arguments={"message": "custom! test"})
338+
mock_config.settings["allowed_prefixes"] = ["custom!"]
339+
check_cmd = commands.Check(
340+
config=mock_config, arguments={"message": "custom! test"}
341+
)
330342

331343
check_cmd()
332344
success_mock.assert_called_once()
333345

334346

335-
def test_check_command_override_allowed_prefixes_config(config, mocker: MockFixture):
347+
def test_check_command_override_allowed_prefixes_config(
348+
mock_config, mocker: MockFixture
349+
):
336350
error_mock = mocker.patch("commitizen.out.error")
337-
config.settings["allow_abort"] = ["fixup!"]
351+
mock_config.settings["allow_abort"] = ["fixup!"]
338352
check_cmd = commands.Check(
339-
config=config,
353+
config=mock_config,
340354
arguments={"message": "fixup! test", "allowed_prefixes": ["custom!"]},
341355
)
342356

@@ -429,23 +443,25 @@ def test_check_command_shows_description_when_use_help_option(
429443
file_regression.check(out, extension=".txt")
430444

431445

432-
def test_check_command_with_message_length_limit(config, mocker: MockFixture):
446+
def test_check_command_with_message_length_limit(mock_config, mocker: MockFixture):
433447
success_mock = mocker.patch("commitizen.out.success")
434448
message = "fix(scope): some commit message"
435449
check_cmd = commands.Check(
436-
config=config,
450+
config=mock_config,
437451
arguments={"message": message, "message_length_limit": len(message) + 1},
438452
)
439453

440454
check_cmd()
441455
success_mock.assert_called_once()
442456

443457

444-
def test_check_command_with_message_length_limit_exceeded(config, mocker: MockFixture):
458+
def test_check_command_with_message_length_limit_exceeded(
459+
mock_config, mocker: MockFixture
460+
):
445461
error_mock = mocker.patch("commitizen.out.error")
446462
message = "fix(scope): some commit message"
447463
check_cmd = commands.Check(
448-
config=config,
464+
config=mock_config,
449465
arguments={"message": message, "message_length_limit": len(message) - 1},
450466
)
451467

@@ -454,9 +470,9 @@ def test_check_command_with_message_length_limit_exceeded(config, mocker: MockFi
454470
error_mock.assert_called_once()
455471

456472

457-
def test_check_command_with_amend_prefix_default(config, mocker: MockFixture):
473+
def test_check_command_with_amend_prefix_default(mock_config, mocker: MockFixture):
458474
success_mock = mocker.patch("commitizen.out.success")
459-
check_cmd = commands.Check(config=config, arguments={"message": "amend! test"})
475+
check_cmd = commands.Check(config=mock_config, arguments={"message": "amend! test"})
460476

461477
check_cmd()
462478
success_mock.assert_called_once()

0 commit comments

Comments
 (0)