Skip to content

Commit 36e80af

Browse files
committed
test(cli): ✅ add unit test
1 parent 513506c commit 36e80af

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

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 skip_checks_1 + skip_checks_2 == called_args['skip_checks']

0 commit comments

Comments
 (0)