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
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions snapcraft/project/_project_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

yaml_contents = OrderedDict()

return yaml_contents
16 changes: 16 additions & 0 deletions tests/unit/project/test_project_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ def test_properties(self):
self.assertThat(info.description, Equals("baz"))
self.assertThat(info.confinement, Equals("strict"))

def test_empty_yaml(self):
snapcraft_yaml_file_path = self.make_snapcraft_yaml("")

raised = self.assertRaises(
errors.YamlValidationError,
ProjectInfo,
snapcraft_yaml_file_path=snapcraft_yaml_file_path,
)

self.assertThat(
raised.message,
Equals(
"'name' is a required property in {!r}".format(snapcraft_yaml_file_path)
),
)

def test_minimal_load_with_name_only(self):
snapcraft_yaml_file_path = self.make_snapcraft_yaml(
dedent(
Expand Down