|
1 | 1 | import pytest
|
2 | 2 |
|
| 3 | +from commitizen import defaults |
3 | 4 | from commitizen.config import BaseConfig, JsonConfig, TomlConfig, YAMLConfig
|
4 | 5 | from commitizen.cz.conventional_commits import ConventionalCommitsCz
|
5 | 6 | from commitizen.cz.customize import CustomizeCommitsCz
|
|
316 | 317 | fix: PATCH
|
317 | 318 | hotfix: PATCH
|
318 | 319 | """
|
| 320 | +EMPTY_TOML_STR = """ |
| 321 | +[tool.commitizen] |
| 322 | +name = "cz_customize" |
| 323 | +[tool.commitizen.customize] |
| 324 | +info = "This is a customized cz with emojis 🎉!" |
| 325 | +""" |
| 326 | + |
| 327 | +EMPTY_JSON_STR = """ |
| 328 | +{ |
| 329 | + "commitizen": { |
| 330 | + "name": "cz_customize", |
| 331 | + "customize": { |
| 332 | + "info": "This is a customized cz with emojis 🎉!" |
| 333 | + } |
| 334 | + } |
| 335 | +} |
| 336 | +""" |
| 337 | + |
| 338 | +EMPTY_YAML_STR = """ |
| 339 | +commitizen: |
| 340 | + name: cz_customize |
| 341 | + customize: |
| 342 | + info: This is a customized cz with emojis 🎉! |
| 343 | +""" |
319 | 344 |
|
320 | 345 |
|
321 | 346 | @pytest.fixture(
|
@@ -365,6 +390,17 @@ def config_with_unicode(request):
|
365 | 390 | return request.param
|
366 | 391 |
|
367 | 392 |
|
| 393 | +@pytest.fixture( |
| 394 | + params=[ |
| 395 | + TomlConfig(data=EMPTY_TOML_STR, path="not_exist.toml"), |
| 396 | + JsonConfig(data=EMPTY_JSON_STR, path="not_exist.json"), |
| 397 | + YAMLConfig(data=EMPTY_YAML_STR, path="not_exist.yaml"), |
| 398 | + ] |
| 399 | +) |
| 400 | +def empty_config(request): |
| 401 | + return request.param |
| 402 | + |
| 403 | + |
368 | 404 | def test_initialize_cz_customize_failed():
|
369 | 405 | with pytest.raises(MissingCzCustomizeConfigError) as excinfo:
|
370 | 406 | config = BaseConfig()
|
@@ -565,8 +601,8 @@ def test_info_with_info_path(tmpdir, config_info):
|
565 | 601 |
|
566 | 602 | def test_info_without_info(config_without_info):
|
567 | 603 | cz = CustomizeCommitsCz(config_without_info)
|
568 |
| - cz_super = ConventionalCommitsCz(config_without_info) |
569 |
| - assert cz.info() == cz_super.info() |
| 604 | + conventional_commits = ConventionalCommitsCz(config_without_info) |
| 605 | + assert cz.info() == conventional_commits.info() |
570 | 606 |
|
571 | 607 |
|
572 | 608 | def test_commit_parser(config):
|
@@ -600,3 +636,48 @@ def test_change_type_map(config):
|
600 | 636 | def test_change_type_map_unicode(config_with_unicode):
|
601 | 637 | cz = CustomizeCommitsCz(config_with_unicode)
|
602 | 638 | assert cz.change_type_map == {"✨ feature": "Feat", "🐛 bug fix": "Fix"}
|
| 639 | + |
| 640 | + |
| 641 | +def test_questions_without_config(empty_config): |
| 642 | + cz = CustomizeCommitsCz(empty_config) |
| 643 | + empty_config.settings.update({"name": defaults.DEFAULT_SETTINGS["name"]}) |
| 644 | + conventional_commits = ConventionalCommitsCz(empty_config) |
| 645 | + assert cz.questions() == conventional_commits.questions() |
| 646 | + |
| 647 | + |
| 648 | +def test_message_without_config(empty_config): |
| 649 | + cz = CustomizeCommitsCz(empty_config) |
| 650 | + empty_config.settings.update({"name": defaults.DEFAULT_SETTINGS["name"]}) |
| 651 | + conventional_commits = ConventionalCommitsCz(empty_config) |
| 652 | + answers = { |
| 653 | + "prefix": "fix", |
| 654 | + "scope": "users", |
| 655 | + "subject": "email pattern corrected", |
| 656 | + "is_breaking_change": False, |
| 657 | + "body": "", |
| 658 | + "footer": "", |
| 659 | + } |
| 660 | + message = conventional_commits.message(answers) |
| 661 | + assert message == "fix(users): email pattern corrected" |
| 662 | + assert cz.message(answers) == message |
| 663 | + |
| 664 | + |
| 665 | +def test_example_with_config(empty_config): |
| 666 | + cz = CustomizeCommitsCz(empty_config) |
| 667 | + empty_config.settings.update({"name": defaults.DEFAULT_SETTINGS["name"]}) |
| 668 | + conventional_commits = ConventionalCommitsCz(empty_config) |
| 669 | + assert cz.example() == conventional_commits.example() |
| 670 | + |
| 671 | + |
| 672 | +def test_schema_pattern_with_config(empty_config): |
| 673 | + cz = CustomizeCommitsCz(empty_config) |
| 674 | + empty_config.settings.update({"name": defaults.DEFAULT_SETTINGS["name"]}) |
| 675 | + conventional_commits = ConventionalCommitsCz(empty_config) |
| 676 | + assert cz.schema_pattern() == conventional_commits.schema_pattern() |
| 677 | + |
| 678 | + |
| 679 | +def test_schema_without_config(empty_config): |
| 680 | + cz = CustomizeCommitsCz(empty_config) |
| 681 | + empty_config.settings.update({"name": defaults.DEFAULT_SETTINGS["name"]}) |
| 682 | + conventional_commits = ConventionalCommitsCz(empty_config) |
| 683 | + assert cz.schema() == conventional_commits.schema() |
0 commit comments