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

Add tests for yaml_wrapper #107

Merged
merged 6 commits into from
Mar 5, 2024
Merged

Add tests for yaml_wrapper #107

merged 6 commits into from
Mar 5, 2024

Conversation

Deedone
Copy link
Contributor

@Deedone Deedone commented Mar 4, 2024

Add tests that ensure that YamlValue and YamlDefaultValue provide the same API, and that the API is working. Fix the bugs that came up during testing.

@Deedone Deedone force-pushed the fix_list branch 3 times, most recently from 7723966 to e97c5fe Compare March 4, 2024 11:38
@Deedone Deedone changed the title Add is_list property to _YamlDefaultValue class Add list support to _YamlDefaultValue class Mar 4, 2024
@Deedone Deedone changed the title Add list support to _YamlDefaultValue class Add tests for yaml_wrapper Mar 5, 2024
Copy link
Collaborator

@lorc lorc left a comment

Choose a reason for hiding this comment

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

Well done!

I have one comment: could you please add tests for dict/mapping as well? So we can cover the YamlWrapper functionality once and for all.

Copy link
Collaborator

@lorc lorc left a comment

Choose a reason for hiding this comment

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

Reviewed-by: Volodymyr Babchuk <[email protected]>

Currently moulin crashes when it tries to check if the default value
is a list. Add support for storing lists to the _YamlDefaultValue.

Signed-off-by: Mykyta Poturai <[email protected]>
Reviewed-by: Volodymyr Babchuk <[email protected]>
as_float func was checking for int type, probably due to copy-paste
error. This patch fixes the type check to float.

Signed-off-by: Mykyta Poturai <[email protected]>
Reviewed-by: Volodymyr Babchuk <[email protected]>
The error messages for the _YamlDefaultValue class are not consistent
with the YamlValue class. Make them more similar where possible.

Signed-off-by: Mykyta Poturai <[email protected]>
Reviewed-by: Volodymyr Babchuk <[email protected]>
Writing unit tests uncovered two bugs in the setitem method of the
YamlValue class.
1. The method was raising exceptions with valid inputs.
2. Due to caching in yaml module, the new value was not being set.

This commit fixes both issues by:
1. Hiding the exception raising code behind an else statement.
2. Replace the whole node, instead of trying to update it.

replace_value method was removed, as it was no longer needed.
Private _represent_value method was added to unify scalar node creation.

Signed-off-by: Mykyta Poturai <[email protected]>
Reviewed-by: Volodymyr Babchuk <[email protected]>
Adding dict support to _YamlDefaultValue class will fully unify it with
the YamlValue class. This will allow to safely use default nodes in
place of the real ones.

Signed-off-by: Mykyta Poturai <[email protected]>
Reviewed-by: Volodymyr Babchuk <[email protected]>
This patch adds tests for Yaml wrapper. It tests the following
methods in YamlValue and _YamlDefaultValue classes:
- as_str
- as_int
- as_float
- as_bool
- is_list
- keys
- items
- get
- __getitem__
- __setitem__
- __len__
- __iter__

Signed-off-by: Mykyta Poturai <[email protected]>
Reviewed-by: Volodymyr Babchuk <[email protected]>
@lorc lorc merged commit 916bbb2 into xen-troops:main Mar 5, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants