-
Notifications
You must be signed in to change notification settings - Fork 448
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
project: ensure yaml load returns a dictionary #2517
Conversation
PyYAML yaml loading and parsing can return None if given an empty file or empty string. When validating its yaml file, Snapcraft expects the result to be subscriptable, so return an empty dictionary instead of None. Fixes SNAPCRAFT-JQ Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
@@ -86,4 +86,7 @@ def _load_yaml(*, yaml_file_path: str) -> OrderedDict: | |||
except yaml.YAMLError as e: | |||
raise errors.YamlValidationError(str(e), yaml_file_path) from e | |||
|
|||
if yaml_contents is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a unit test for this, one that of an empty file and validate that the instantiation of a ProjectInfo returns the correct YamlValidationError?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unit test added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, a unit test would be nice though
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
Codecov Report
@@ Coverage Diff @@
## master #2517 +/- ##
=========================================
Coverage ? 90.03%
=========================================
Files ? 198
Lines ? 13388
Branches ? 2024
=========================================
Hits ? 12054
Misses ? 908
Partials ? 426
Continue to review full report at Codecov.
|
PyYAML yaml loading and parsing can return None if given an empty file
or empty string. When validating its yaml file, Snapcraft expects the
result to be subscriptable, so return an empty dictionary instead of None.
Fixes SNAPCRAFT-JQ
Signed-off-by: Claudio Matsuoka claudio.matsuoka@canonical.com
./runtests.sh static
?./runtests.sh tests/unit
?