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

build(deps): bump craft-grammar to 2.0.1 #5051

Merged
merged 3 commits into from
Sep 20, 2024
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
4 changes: 2 additions & 2 deletions requirements-devel.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ coverage==7.6.1
craft-application==4.2.3
craft-archives==2.0.0
craft-cli==2.7.0
craft-grammar==2.0.0
craft-grammar==2.0.1
craft-parts==2.1.1
craft-platforms==0.1.1
craft-providers==2.0.1
craft-store==3.0.0
craft-store==3.0.1
cryptography==43.0.1
cssutils==2.11.1
dict2css==0.3.0.post1
Expand Down
4 changes: 2 additions & 2 deletions requirements-docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ colorama==0.4.6
craft-application==4.2.3
craft-archives==2.0.0
craft-cli==2.7.0
craft-grammar==2.0.0
craft-grammar==2.0.1
craft-parts==2.1.1
craft-platforms==0.1.1
craft-providers==2.0.1
craft-store==3.0.0
craft-store==3.0.1
cryptography==43.0.1
cssutils==2.11.1
dict2css==0.3.0.post1
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ click==8.1.7
craft-application==4.2.3
craft-archives==2.0.0
craft-cli==2.7.0
craft-grammar==2.0.0
craft-grammar==2.0.1
craft-parts==2.1.1
craft-platforms==0.1.1
craft-providers==2.0.1
craft-store==3.0.0
craft-store==3.0.1
cryptography==43.0.1
distro==1.9.0
docutils==0.19
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ def recursive_data_files(directory, install_directory):
"craft-application~=4.1",
"craft-archives~=2.0",
"craft-cli~=2.6",
"craft-grammar~=2.0",
"craft-grammar>=2.0.1,<3.0.0",
"craft-parts~=2.1",
"craft-platforms~=0.1",
"craft-providers~=2.0",
"craft-store~=3.0",
"craft-store>=3.0.1,<4.0.0",
"docutils<0.20", # Frozen until we can update sphinx dependencies.
"gnupg",
"jsonschema==2.5.1",
Expand Down
61 changes: 60 additions & 1 deletion tests/unit/models/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,44 @@ def _socket_yaml_data(**kwargs) -> Dict[str, Any]:
yield _socket_yaml_data


@pytest.fixture
def fake_project_with_numbers(project_yaml_data):
"""Returns a fake project with numbers in string fields.

This includes numbers in fields that are validated by snapcraft and fields
validated by craft-parts.
"""
return project_yaml_data(
# string
version=1.0,
# string
icon=2,
# list[str]
website=[3.0, 4],
# dict[str, str]
environment={
"float": 5.0,
"int": 6,
},
parts={
"p1": {
"plugin": "nil",
# string
"source-type": 7,
# string
"source-commit": 8.0,
# list[str]
"build-snaps": [9, 10.0],
# dict[str, str]
"build-environment": [
{"float": 11.0},
{"int": 12},
],
}
},
)


class TestProjectDefaults:
"""Ensure unspecified items have the correct default value."""

Expand Down Expand Up @@ -701,6 +739,23 @@ def test_links_list(self, project_yaml_data):
"https://github.com/NickvisionApps/Denaro",
]

def test_coerce_numbers(self, fake_project_with_numbers):
"""Coerce numbers into strings."""
project = Project.unmarshal(fake_project_with_numbers)

assert project.version == "1.0"
assert project.icon == "2"
assert project.website == ["3.0", "4"]
assert project.environment == {"float": "5.0", "int": "6"}
# parts remain a dictionary with original types
assert project.parts["p1"]["source-type"] == 7
assert project.parts["p1"]["source-commit"] == 8.0
assert project.parts["p1"]["build-snaps"] == [9, 10.0]
assert project.parts["p1"]["build-environment"] == [
{"float": 11.0},
{"int": 12},
]


class TestHookValidation:
"""Validate hooks."""
Expand Down Expand Up @@ -1504,6 +1559,10 @@ def test_grammar_try(self, project_yaml_data):
with pytest.raises(errors.ProjectValidationError, match=error):
GrammarAwareProject.validate_grammar(data)

def test_grammar_number_coercion(self, fake_project_with_numbers):
"""Ensure that grammar validation does not fail when coercing numbers into strings."""
GrammarAwareProject.validate_grammar(fake_project_with_numbers)

def test_grammar_type_error(self, project_yaml_data):
data = project_yaml_data(
parts={
Expand All @@ -1516,7 +1575,7 @@ def test_grammar_type_error(self, project_yaml_data):
}
)

error = r"value must be a str: \[25\]"
error = r"Input should be a valid string \(in field 'parts\.p1\.source\[0\]'\)"
with pytest.raises(errors.ProjectValidationError, match=error):
GrammarAwareProject.validate_grammar(data)

Expand Down
Loading