Skip to content

Commit eac7f66

Browse files
authored
Merge pull request #105 from kikkomep/doc/issue-98
cli: improve description of the `skip-checks` option
2 parents 03b55ad + 309ce8f commit eac7f66

2 files changed

Lines changed: 75 additions & 2 deletions

File tree

rocrate_validator/cli/commands/validate.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ def get_single_char(console: Optional[Console] = None, end: str = "\n",
157157
type=click.STRING,
158158
default=None,
159159
show_default=True,
160+
metavar="Profile-ID",
160161
help="Identifier of the profile to use for validation",
161162
)
162163
@click.option(
@@ -198,7 +199,17 @@ def get_single_char(console: Optional[Console] = None, end: str = "\n",
198199
type=click.STRING,
199200
default=None,
200201
show_default=True,
201-
help="List of checks to skip"
202+
metavar="Fully-Qualified-Check-IDs",
203+
help=(
204+
"[bold yellow]Fully-Qualified-Check-IDs[/bold yellow] is a comma-separated list of checks to skip "
205+
"(may be specified multiple times). Each check must be specified by its "
206+
"Fully Qualified Identifier, e.g., [bold cyan]ro-crate-1.1_12.1[/bold cyan]. The fully qualified "
207+
"check identifier has the format <Profile-ID>_<Requirement_#>.<RequirementCheck_#>, "
208+
"where <Requirement_#> is the position number of the Requirement in the profile, "
209+
"and <RequirementCheck_#> is the position number of the RequirementCheck within that Requirement. "
210+
"You can find the Fully-Qualified-Check IDs using: "
211+
"[bold orange1]rocrate-validator profiles describe <Profile-ID> -v[/bold orange1]"
212+
),
202213
)
203214
@click.option(
204215
'-v',
@@ -281,6 +292,25 @@ def validate(ctx,
281292
if rocrate_uri:
282293
logger.debug("rocrate_path: %s", os.path.abspath(rocrate_uri))
283294

295+
# Parse the skip_checks option
296+
logger.debug("skip_checks: %s", skip_checks)
297+
# Parse the skip_checks option
298+
skip_checks_list = []
299+
if skip_checks:
300+
try:
301+
for s in skip_checks:
302+
skip_checks_list.extend(_.strip() for _ in s.split(",") if _.strip())
303+
logger.debug("skip_checks_list: %s", skip_checks_list)
304+
except Exception as e:
305+
logger.error("Error parsing skip_checks: %s", e)
306+
if logger.isEnabledFor(logging.DEBUG):
307+
logger.exception("Error parsing skip_checks: %s", e)
308+
raise ValueError(
309+
f"Invalid skip_checks value: {s}. "
310+
"It must be a comma-separated list of Fully Qualified Check IDs."
311+
)
312+
logger.debug("Skip checks: %s", skip_checks_list)
313+
284314
try:
285315
# Validation settings
286316
validation_settings = {
@@ -291,7 +321,7 @@ def validate(ctx,
291321
"enable_profile_inheritance": not disable_profile_inheritance,
292322
"rocrate_uri": rocrate_uri,
293323
"abort_on_first": fail_fast,
294-
"skip_checks": skip_checks
324+
"skip_checks": skip_checks_list
295325
}
296326

297327
# Print the application header

tests/test_cli.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import re
16+
from unittest.mock import patch
1617

1718
from click.testing import CliRunner
1819
from pytest import fixture
@@ -66,3 +67,45 @@ def test_validate_subcmd_invalid_local_archive_rocrate(cli_runner: CliRunner):
6667
'--skip-checks', SKIP_LOCAL_DATA_ENTITY_EXISTENCE_CHECK_IDENTIFIER])
6768
assert result.exit_code == 0
6869
assert re.search(r'RO-Crate.*is a valid', result.output)
70+
71+
72+
def test_validate_skip_checks_option(cli_runner: CliRunner):
73+
# Patch the validation service to capture the skip_checks argument
74+
called_args = {}
75+
76+
def mock_validate(*args, **kwargs):
77+
nonlocal called_args # noqa: F824
78+
79+
for arg in args:
80+
if isinstance(arg, dict):
81+
called_args.update(arg)
82+
83+
called_args.update(kwargs)
84+
logger.debug(f"Args: {args}")
85+
logger.debug(f"Kwargs: {kwargs}")
86+
logger.debug(f"Called args: {called_args}")
87+
88+
with patch('rocrate_validator.cli.commands.validate.services.validate') as mock_validate_rocrate:
89+
mock_validate_rocrate.return_value = None
90+
mock_validate_rocrate.side_effect = mock_validate
91+
92+
skip_checks_1 = ("a", "b", "c")
93+
skip_checks_2 = ("d", "e", "f")
94+
result = cli_runner.invoke(
95+
cli, [
96+
'--no-interactive',
97+
'validate', str(ValidROC().sort_and_change_remote),
98+
'--skip-checks', ','.join(skip_checks_1),
99+
'--skip-checks', ','.join(skip_checks_2),
100+
'--no-paging'
101+
]
102+
)
103+
104+
# Check the exit code which should be 2
105+
# because the validation service is mocked and does not return a valid result
106+
assert result.exit_code == 2
107+
# Check if 'skip_checks' is in the called arguments
108+
assert 'skip_checks' in called_args
109+
logger.debug(f"Called args: {called_args}")
110+
# Check if the skip_checks value matches the expected value
111+
assert list(skip_checks_1 + skip_checks_2) == called_args['skip_checks']

0 commit comments

Comments
 (0)