From 31f3785e22ad6f00006bea5178e3f3dfa170babb Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Thu, 25 Jun 2026 12:28:57 +0200 Subject: [PATCH 1/2] =?UTF-8?q?fix(cli):=20=F0=9F=90=9B=20use=20Path=20typ?= =?UTF-8?q?e=20for=20--output-file=20option?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Set `path_type=Path` on the `--output-file` click option so the value is parsed as a `pathlib.Path` instead of a plain string, ensuring consistent path handling. --- rocrate_validator/cli/commands/validate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rocrate_validator/cli/commands/validate.py b/rocrate_validator/cli/commands/validate.py index 3f2c093ec..5c759ed03 100644 --- a/rocrate_validator/cli/commands/validate.py +++ b/rocrate_validator/cli/commands/validate.py @@ -199,7 +199,7 @@ def validate_uri(ctx, param, value): @click.option( "-o", "--output-file", - type=click.Path(), + type=click.Path(path_type=Path), default=None, show_default=True, help="Path to the output file for the validation report", From d9d73e11af8fa05036a2010260645a36b537ca1f Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Thu, 25 Jun 2026 12:34:39 +0200 Subject: [PATCH 2/2] =?UTF-8?q?test(cli):=20=E2=9C=85=20verify=20--output-?= =?UTF-8?q?file=20writes=20text=20and=20JSON=20reports?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_cli.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/test_cli.py b/tests/test_cli.py index 9d34725fd..5f0cdef3d 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import json import re from pathlib import Path from unittest.mock import patch @@ -146,6 +147,47 @@ def mock_validate(*args, **kwargs): ) +def test_validate_output_file_text_report(cli_runner: CliRunner, tmp_path: Path): + output_file = tmp_path / "report.txt" + result = cli_runner.invoke( + cli, + [ + "validate", + str(ValidROC().wrroc_paper_long_date), + "--verbose", + "--no-paging", + "-o", + str(output_file), + ], + ) + assert result.exit_code == 0, result.output + assert "AttributeError" not in result.output + assert output_file.exists(), "The text report file was not created" + assert output_file.read_text(encoding="utf-8").strip(), "The text report file is empty" + + +def test_validate_output_file_json_report(cli_runner: CliRunner, tmp_path: Path): + output_file = tmp_path / "report.json" + result = cli_runner.invoke( + cli, + [ + "validate", + str(ValidROC().wrroc_paper_long_date), + "--no-paging", + "--output-format", + "json", + "-w", + "10000", + "-o", + str(output_file), + ], + ) + assert result.exit_code == 0, result.output + assert "AttributeError" not in result.output + assert output_file.exists(), "The JSON report file was not created" + json.loads(output_file.read_text(encoding="utf-8")) # must be valid JSON + + def test_validate_with_invalid_profiles_path_dir(cli_runner: CliRunner): dummy_profiles_path = "/tmp/dummy_profiles" result = cli_runner.invoke(