Skip to content

Commit 6f0c39c

Browse files
authored
Merge pull request crs4#183 from kikkomep/fix/issue-182
fix(cli): 🐛 write validation report to --output-file (crs4#182)
2 parents 871cf9d + d9d73e1 commit 6f0c39c

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

rocrate_validator/cli/commands/validate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def validate_uri(ctx, param, value):
199199
@click.option(
200200
"-o",
201201
"--output-file",
202-
type=click.Path(),
202+
type=click.Path(path_type=Path),
203203
default=None,
204204
show_default=True,
205205
help="Path to the output file for the validation report",

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)