|
1 | 1 | import sys
|
| 2 | +from io import StringIO |
2 | 3 | from typing import List
|
3 | 4 |
|
4 | 5 | import pytest
|
@@ -190,12 +191,12 @@ def test_check_a_range_of_git_commits_and_failed(config, mocker):
|
190 | 191 | error_mock.assert_called_once()
|
191 | 192 |
|
192 | 193 |
|
193 |
| -@pytest.mark.parametrize( |
194 |
| - "args", [{"rev_range": "HEAD~10..master", "commit_msg_file": "some_file"}, {}] |
195 |
| -) |
196 |
| -def test_check_command_with_invalid_argment(args, config): |
| 194 | +def test_check_command_with_invalid_argment(config): |
197 | 195 | with pytest.raises(InvalidCommandArgumentError) as excinfo:
|
198 |
| - commands.Check(config=config, arguments=args) |
| 196 | + commands.Check( |
| 197 | + config=config, |
| 198 | + arguments={"commit_msg_file": "some_file", "rev_range": "HEAD~10..master"}, |
| 199 | + ) |
199 | 200 | assert "One and only one argument is required for check command!" in str(
|
200 | 201 | excinfo.value
|
201 | 202 | )
|
@@ -245,3 +246,23 @@ def test_check_command_with_invalid_message(config, mocker):
|
245 | 246 | with pytest.raises(InvalidCommitMessageError):
|
246 | 247 | check_cmd()
|
247 | 248 | error_mock.assert_called_once()
|
| 249 | + |
| 250 | + |
| 251 | +def test_check_command_with_pipe_message(mocker, capsys): |
| 252 | + testargs = ["cz", "check"] |
| 253 | + mocker.patch.object(sys, "argv", testargs) |
| 254 | + mocker.patch("sys.stdin", StringIO("fix(scope): some commit message")) |
| 255 | + |
| 256 | + cli.main() |
| 257 | + out, _ = capsys.readouterr() |
| 258 | + assert "Commit validation: successful!" in out |
| 259 | + |
| 260 | + |
| 261 | +def test_check_command_with_pipe_message_and_failed(mocker): |
| 262 | + testargs = ["cz", "check"] |
| 263 | + mocker.patch.object(sys, "argv", testargs) |
| 264 | + mocker.patch("sys.stdin", StringIO("bad commit message")) |
| 265 | + |
| 266 | + with pytest.raises(InvalidCommitMessageError) as excinfo: |
| 267 | + cli.main() |
| 268 | + assert "commit validation: failed!" in str(excinfo.value) |
0 commit comments