/ tests / test_cli.py
test_cli.py
 1  """Verify that the CLI behaves correctly."""
 2  
 3  import logging
 4  
 5  from pytest import LogCaptureFixture, MonkeyPatch
 6  
 7  from proselint.command_line import ExitStatus, get_parser, proselint
 8  from proselint.version import __version__
 9  
10  PARSER = get_parser()
11  
12  
13  def test_exit_code_demo() -> None:
14      """Ensure that linting the demo returns an exit code of 1."""
15      assert (
16          proselint(PARSER.parse_args(("check", "--demo")), PARSER)
17          == ExitStatus.SUCCESS_ERR
18      )
19  
20  
21  def test_version(caplog: LogCaptureFixture) -> None:
22      """Ensure that the version is logged and exits correctly."""
23      with caplog.at_level("INFO", logger="proselint"):
24          for arg in ("version", "--version"):
25              result = proselint(PARSER.parse_args((arg,)), PARSER)
26              assert result == ExitStatus.SUCCESS
27              assert caplog.record_tuples == [
28                  ("proselint", logging.INFO, f"Proselint {__version__}")
29              ]
30              caplog.clear()
31  
32  
33  def test_empty_stdin(monkeypatch: MonkeyPatch) -> None:
34      """Ensure that running the linter with empty input does not crash."""
35      with monkeypatch.context() as m:
36          m.setattr("sys.stdin.read", lambda: "")
37          assert (
38              proselint(PARSER.parse_args(("check",)), PARSER)
39              == ExitStatus.SUCCESS
40          )