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

project: ensure yaml load returns a dictionary #2517

Merged
merged 2 commits into from
Mar 27, 2019

Conversation

cmatsuoka
Copy link
Contributor

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

  • Have you followed the guidelines for contributing?
  • Have you signed the CLA?
  • Have you successfully run ./runtests.sh static?
  • Have you successfully run ./runtests.sh tests/unit?

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:
Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unit test added.

Copy link
Collaborator

@sergiusens sergiusens left a 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-io
Copy link

codecov-io commented Mar 27, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@d998225). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #2517   +/-   ##
=========================================
  Coverage          ?   90.03%           
=========================================
  Files             ?      198           
  Lines             ?    13388           
  Branches          ?     2024           
=========================================
  Hits              ?    12054           
  Misses            ?      908           
  Partials          ?      426
Impacted Files Coverage Δ
snapcraft/project/_project_info.py 93.33% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d998225...824d7db. Read the comment docs.

@sergiusens sergiusens merged commit a574d39 into canonical:master Mar 27, 2019
@cmatsuoka cmatsuoka deleted the ensure-yaml-is-dict branch June 27, 2019 10:35
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.

3 participants