|
| 1 | +import sys |
| 2 | + |
| 3 | +import pytest |
| 4 | +from pytest_mock import MockFixture |
| 5 | + |
| 6 | +from commitizen import cli |
| 7 | +from commitizen.commands import Example, Info, ListCz, Schema |
| 8 | + |
| 9 | + |
| 10 | +@pytest.mark.skipif( |
| 11 | + sys.version_info < (3, 13), |
| 12 | + reason="The output message of argparse is different between Python 3.13 and lower than Python 3.13", |
| 13 | +) |
| 14 | +@pytest.mark.parametrize( |
| 15 | + "command", |
| 16 | + [ |
| 17 | + "bump", |
| 18 | + "changelog", |
| 19 | + "check", |
| 20 | + "commit", |
| 21 | + "example", |
| 22 | + "info", |
| 23 | + "init", |
| 24 | + "ls", |
| 25 | + "schema", |
| 26 | + "version", |
| 27 | + ], |
| 28 | +) |
| 29 | +def test_command_shows_description_when_use_help_option( |
| 30 | + mocker: MockFixture, |
| 31 | + capsys, |
| 32 | + file_regression, |
| 33 | + monkeypatch: pytest.MonkeyPatch, |
| 34 | + command: str, |
| 35 | +): |
| 36 | + """Test that the command shows the description when the help option is used. |
| 37 | +
|
| 38 | + Note: If the command description changes, please run `pytest tests/commands/test_common_command.py --regen-all` to regenerate the test files. |
| 39 | + """ |
| 40 | + # Force consistent terminal output |
| 41 | + monkeypatch.setenv("COLUMNS", "80") |
| 42 | + monkeypatch.setenv("TERM", "dumb") |
| 43 | + monkeypatch.setenv("LC_ALL", "C") |
| 44 | + monkeypatch.setenv("LANG", "C") |
| 45 | + monkeypatch.setenv("NO_COLOR", "1") |
| 46 | + monkeypatch.setenv("PAGER", "cat") |
| 47 | + |
| 48 | + testargs = ["cz", command, "--help"] |
| 49 | + mocker.patch.object(sys, "argv", testargs) |
| 50 | + with pytest.raises(SystemExit): |
| 51 | + cli.main() |
| 52 | + |
| 53 | + out, _ = capsys.readouterr() |
| 54 | + file_regression.check(out, extension=".txt") |
| 55 | + |
| 56 | + |
| 57 | +@pytest.mark.parametrize( |
| 58 | + "command", |
| 59 | + [ |
| 60 | + Example, |
| 61 | + Info, |
| 62 | + ListCz, |
| 63 | + Schema, |
| 64 | + ], |
| 65 | +) |
| 66 | +def test_simple_command_call_once(config, mocker: MockFixture, command): |
| 67 | + write_mock = mocker.patch("commitizen.out.write") |
| 68 | + command(config)() |
| 69 | + write_mock.assert_called_once() |
0 commit comments