|
| 1 | +import pytest |
| 2 | +from tomlkit import parse |
| 3 | + |
| 4 | +from commitizen.cz.customize import CustomizeCommitsCz |
| 5 | +from commitizen.config import Config |
| 6 | + |
| 7 | + |
| 8 | +@pytest.fixture(scope="module") |
| 9 | +def config(): |
| 10 | + _conf = Config() |
| 11 | + toml_str = """ |
| 12 | + [tool.commitizen.customize] |
| 13 | + # message_template should follow the python string formatting spec |
| 14 | + message_template = "{change_type}: {message}" |
| 15 | + example = "feature: this feature eanable customize through config file" |
| 16 | + schema = "<type>: <body>" |
| 17 | +
|
| 18 | + [[tool.commitizen.customize.questions]] |
| 19 | + type = "list" |
| 20 | + name = "change_type" |
| 21 | + choices = ["feature", "bug fix"] |
| 22 | + message = "Select the type of change you are committing" |
| 23 | +
|
| 24 | + [[tool.commitizen.customize.questions]] |
| 25 | + type = "input" |
| 26 | + name = "message" |
| 27 | + message = "Body." |
| 28 | + """ |
| 29 | + _conf.update(parse(toml_str)["tool"]["commitizen"]) |
| 30 | + return _conf.config |
| 31 | + |
| 32 | + |
| 33 | +def test_questions(config): |
| 34 | + cz = CustomizeCommitsCz(config) |
| 35 | + questions = cz.questions() |
| 36 | + expected_questions = [ |
| 37 | + { |
| 38 | + "type": "list", |
| 39 | + "name": "change_type", |
| 40 | + "choices": ["feature", "bug fix"], |
| 41 | + "message": "Select the type of change you are committing", |
| 42 | + }, |
| 43 | + {"type": "input", "name": "message", "message": "Body."}, |
| 44 | + ] |
| 45 | + assert list(questions) == expected_questions |
| 46 | + |
| 47 | + |
| 48 | +def test_answer(config): |
| 49 | + cz = CustomizeCommitsCz(config) |
| 50 | + answers = { |
| 51 | + "change_type": "feature", |
| 52 | + "message": "this feature eanable customize through config file", |
| 53 | + } |
| 54 | + message = cz.message(answers) |
| 55 | + assert message == "feature: this feature eanable customize through config file" |
| 56 | + |
| 57 | + |
| 58 | +def test_example(config): |
| 59 | + cz = CustomizeCommitsCz(config) |
| 60 | + assert "feature: this feature eanable customize through config file" in cz.example() |
| 61 | + |
| 62 | + |
| 63 | +def test_schema(config): |
| 64 | + cz = CustomizeCommitsCz(config) |
| 65 | + assert "<type>: <body>" in cz.schema() |
0 commit comments