Skip to content

Commit

Permalink
Missing coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mauvilsa committed Dec 23, 2024
1 parent e170ee9 commit fd559f3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
8 changes: 4 additions & 4 deletions jsonargparse/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,11 +800,11 @@ def _dump_cleanup_actions(self, cfg, actions, dump_kwargs, prefix=""):
value = cfg.get(action_dest)
if value is not None:
with parser_context(parent_parser=self):
try:
if dump_kwargs.get("skip_validation"):
with suppress(ValueError):
value = action.serialize(value, dump_kwargs=dump_kwargs)
else:
value = action.serialize(value, dump_kwargs=dump_kwargs)
except Exception:
if not dump_kwargs.get("skip_validation"):
raise
cfg.update(value, action_dest)

def _dump_delete_default_entries(self, subcfg, subdefaults):
Expand Down
16 changes: 16 additions & 0 deletions jsonargparse_tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,22 @@ def test_dump_skip_default_nested(parser):
assert parser.dump(parser.parse_args(["--g2.op2=pqr"]), skip_default=True) == "g2:\n op2: pqr\n"


def test_dump_skip_validation(parser):
parser.add_argument("--key", type=int)
cfg = Namespace(key="-")
with pytest.raises(TypeError):
parser.dump(cfg)
dump = parser.dump(cfg, skip_validation=True)
assert "-" in dump


def test_dump_unexpected_kwarg(parser):
parser.add_argument("--key", type=int)
cfg = Namespace(key="-")
with pytest.raises(ValueError, match="Unexpected keyword parameter"):
parser.dump(cfg, unexpected=True)


def test_dump_order(parser, subtests):
args = {}
for num in range(50):
Expand Down
4 changes: 1 addition & 3 deletions jsonargparse_tests/test_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def test_deprecated_skip_check_method(parser):
)


def test_deprecated_skip_check_parameter(parser):
def test_deprecated_dump_skip_check_parameter(parser):
parser.add_argument("--key", type=int)
cfg = Namespace(key="-")
with catch_warnings(record=True) as w:
Expand All @@ -358,8 +358,6 @@ def test_deprecated_skip_check_parameter(parser):
message="skip_check parameter was deprecated",
code="parser.dump(cfg, skip_check=True)",
)
with pytest.raises(ValueError, match="Unexpected keyword parameters"):
parser.dump(cfg, unexpected=True)


def test_ActionPath(tmp_cwd):
Expand Down

0 comments on commit fd559f3

Please sign in to comment.