Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable LYD_VALIDATE_MULTI_ERROR flag #79

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cffi/cdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ LY_ERR lyd_print_all(struct ly_out *, const struct lyd_node *, LYD_FORMAT, uint3
#define LYD_VALIDATE_NO_STATE ...
#define LYD_VALIDATE_PRESENT ...
#define LYD_VALIDATE_OPTS_MASK ...
#define LYD_VALIDATE_MULTI_ERROR ...

LY_ERR lyd_parse_data_mem(const struct ly_ctx *, const char *, LYD_FORMAT, uint32_t, uint32_t, struct lyd_node **);

Expand Down
9 changes: 8 additions & 1 deletion libyang/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ def parse_data(
ordered: bool = False,
strict: bool = False,
validate_present: bool = False,
validate_multi_error: bool = False,
) -> Optional[DNode]:
if self.cdata is None:
raise RuntimeError("context already destroyed")
Expand All @@ -338,7 +339,9 @@ def parse_data(
strict=strict,
)
validation_flgs = validation_flags(
no_state=no_state, validate_present=validate_present
no_state=no_state,
validate_present=validate_present,
validate_multi_error=validate_multi_error,
)
fmt = data_format(fmt)
encode = True
Expand Down Expand Up @@ -390,6 +393,7 @@ def parse_data_mem(
ordered: bool = False,
strict: bool = False,
validate_present: bool = False,
validate_multi_error: bool = False,
) -> Optional[DNode]:
return self.parse_data(
fmt,
Expand All @@ -403,6 +407,7 @@ def parse_data_mem(
ordered=ordered,
strict=strict,
validate_present=validate_present,
validate_multi_error=validate_multi_error
)

def parse_data_file(
Expand All @@ -417,6 +422,7 @@ def parse_data_file(
ordered: bool = False,
strict: bool = False,
validate_present: bool = False,
validate_multi_error: bool = False,
) -> Optional[DNode]:
return self.parse_data(
fmt,
Expand All @@ -430,6 +436,7 @@ def parse_data_file(
ordered=ordered,
strict=strict,
validate_present=validate_present,
validate_multi_error=validate_multi_error,
)

def __iter__(self) -> Iterator[Module]:
Expand Down
3 changes: 3 additions & 0 deletions libyang/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,15 @@ def data_type(dtype):
def validation_flags(
no_state: bool = False,
validate_present: bool = False,
validate_multi_error: bool = False,
) -> int:
flags = 0
if no_state:
flags |= lib.LYD_VALIDATE_NO_STATE
if validate_present:
flags |= lib.LYD_VALIDATE_PRESENT
if validate_multi_error:
flags |= lib.LYD_VALIDATE_MULTI_ERROR
return flags


Expand Down
3 changes: 2 additions & 1 deletion tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ def test_data_parse_state_json(self):
"""

def test_data_parse_config_xml(self):
dnode = self.ctx.parse_data_mem(self.XML_CONFIG, "xml", validate_present=True)
dnode = self.ctx.parse_data_mem(self.XML_CONFIG, "xml", validate_present=True,
validate_multi_error=True)
self.assertIsInstance(dnode, DContainer)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a specific unit test for your new option instead, that would verify that we get those multiple errors?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samuel-gauthier I got it, I'll add the test, thanks

try:
xml = dnode.print_mem("xml", with_siblings=True, trim_default_values=True)
Expand Down
Loading