Skip to content

Commit d9d73e1

Browse files
committed
test(cli): ✅ verify --output-file writes text and JSON reports
1 parent 31f3785 commit d9d73e1

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

tests/test_cli.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import json
1516
import re
1617
from pathlib import Path
1718
from unittest.mock import patch
@@ -146,6 +147,47 @@ def mock_validate(*args, **kwargs):
146147
)
147148

148149

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+
149191
def test_validate_with_invalid_profiles_path_dir(cli_runner: CliRunner):
150192
dummy_profiles_path = "/tmp/dummy_profiles"
151193
result = cli_runner.invoke(

0 commit comments

Comments
 (0)