|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
| 15 | +import json |
15 | 16 | import re |
16 | 17 | from pathlib import Path |
17 | 18 | from unittest.mock import patch |
@@ -146,6 +147,47 @@ def mock_validate(*args, **kwargs): |
146 | 147 | ) |
147 | 148 |
|
148 | 149 |
|
| 150 | +def test_validate_output_file_text_report(cli_runner: CliRunner, tmp_path: Path): |
| 151 | + output_file = tmp_path / "report.txt" |
| 152 | + result = cli_runner.invoke( |
| 153 | + cli, |
| 154 | + [ |
| 155 | + "validate", |
| 156 | + str(ValidROC().wrroc_paper_long_date), |
| 157 | + "--verbose", |
| 158 | + "--no-paging", |
| 159 | + "-o", |
| 160 | + str(output_file), |
| 161 | + ], |
| 162 | + ) |
| 163 | + assert result.exit_code == 0, result.output |
| 164 | + assert "AttributeError" not in result.output |
| 165 | + assert output_file.exists(), "The text report file was not created" |
| 166 | + assert output_file.read_text(encoding="utf-8").strip(), "The text report file is empty" |
| 167 | + |
| 168 | + |
| 169 | +def test_validate_output_file_json_report(cli_runner: CliRunner, tmp_path: Path): |
| 170 | + output_file = tmp_path / "report.json" |
| 171 | + result = cli_runner.invoke( |
| 172 | + cli, |
| 173 | + [ |
| 174 | + "validate", |
| 175 | + str(ValidROC().wrroc_paper_long_date), |
| 176 | + "--no-paging", |
| 177 | + "--output-format", |
| 178 | + "json", |
| 179 | + "-w", |
| 180 | + "10000", |
| 181 | + "-o", |
| 182 | + str(output_file), |
| 183 | + ], |
| 184 | + ) |
| 185 | + assert result.exit_code == 0, result.output |
| 186 | + assert "AttributeError" not in result.output |
| 187 | + assert output_file.exists(), "The JSON report file was not created" |
| 188 | + json.loads(output_file.read_text(encoding="utf-8")) # must be valid JSON |
| 189 | + |
| 190 | + |
149 | 191 | def test_validate_with_invalid_profiles_path_dir(cli_runner: CliRunner): |
150 | 192 | dummy_profiles_path = "/tmp/dummy_profiles" |
151 | 193 | result = cli_runner.invoke( |
|
0 commit comments