|
1 | 1 | """Test command line interface.""" |
2 | 2 |
|
3 | 3 | import logging |
| 4 | +import subprocess |
| 5 | +import sys |
4 | 6 | from pathlib import Path |
| 7 | +from textwrap import dedent |
5 | 8 |
|
6 | 9 | import pytest |
7 | 10 | from click.testing import CliRunner |
@@ -54,6 +57,83 @@ def test_no_cache(self, tmp_path_cwd, caplog): |
54 | 57 | # Check that at least one collected file was logged as "(cached)" |
55 | 58 | assert "cached" not in "\n".join(caplog.messages) |
56 | 59 |
|
| 60 | + @pytest.mark.slow |
| 61 | + @pytest.mark.parametrize("workers", [1, 2]) |
| 62 | + def test_fail_on_warning(self, workers, tmp_path_cwd): |
| 63 | + source_with_warning = dedent( |
| 64 | + ''' |
| 65 | + def foo(x: str): |
| 66 | + """ |
| 67 | + Parameters |
| 68 | + ---------- |
| 69 | + x : int |
| 70 | + """ |
| 71 | + ''' |
| 72 | + ) |
| 73 | + package = tmp_path_cwd / "src/sample_package" |
| 74 | + package.mkdir(parents=True) |
| 75 | + init_py = package / "__init__.py" |
| 76 | + with init_py.open("x") as io: |
| 77 | + io.write(source_with_warning) |
| 78 | + |
| 79 | + result = subprocess.run( |
| 80 | + [ |
| 81 | + sys.executable, |
| 82 | + "-m", |
| 83 | + "docstub", |
| 84 | + "run", |
| 85 | + "--quiet", |
| 86 | + "--quiet", |
| 87 | + "--fail-on-warning", |
| 88 | + "--workers", |
| 89 | + str(workers), |
| 90 | + str(package), |
| 91 | + ], |
| 92 | + check=False, |
| 93 | + capture_output=True, |
| 94 | + text=True, |
| 95 | + ) |
| 96 | + assert result.returncode == 1 |
| 97 | + |
| 98 | + @pytest.mark.slow |
| 99 | + @pytest.mark.parametrize("workers", [1, 2]) |
| 100 | + def test_no_output_exit_code(self, workers, tmp_path_cwd): |
| 101 | + faulty_source = dedent( |
| 102 | + ''' |
| 103 | + def foo(x): |
| 104 | + """ |
| 105 | + Parameters |
| 106 | + ---------- |
| 107 | + x : doctype with syntax error |
| 108 | + """ |
| 109 | + ''' |
| 110 | + ) |
| 111 | + package = tmp_path_cwd / "src/sample_package" |
| 112 | + package.mkdir(parents=True) |
| 113 | + init_py = package / "__init__.py" |
| 114 | + with init_py.open("x") as io: |
| 115 | + io.write(faulty_source) |
| 116 | + |
| 117 | + result = subprocess.run( |
| 118 | + [ |
| 119 | + sys.executable, |
| 120 | + "-m", |
| 121 | + "docstub", |
| 122 | + "run", |
| 123 | + "--quiet", |
| 124 | + "--quiet", |
| 125 | + "--workers", |
| 126 | + str(workers), |
| 127 | + str(package), |
| 128 | + ], |
| 129 | + check=False, |
| 130 | + capture_output=True, |
| 131 | + text=True, |
| 132 | + ) |
| 133 | + assert result.stdout == "" |
| 134 | + assert result.stderr == "" |
| 135 | + assert result.returncode == 1 |
| 136 | + |
57 | 137 |
|
58 | 138 | class Test_clean: |
59 | 139 | @pytest.mark.parametrize("verbosity", [["-v"], ["--verbose"], []]) |
|
0 commit comments