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
grammar: to statement #1639
grammar: to statement #1639
Conversation
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.
Nice job @kalikiana, this looks really good. One small typo, and a few test cases are missing. There also seems to be no integration-level tests.
def _extract_to_clause_selectors(to): | ||
"""Extract the list of selectors within a to clause. | ||
|
||
:param str to: The 'to <selector' part of the 'to' clause. |
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.
Missing a bracket here: 'to <selector>'
], | ||
'target_arch': 'i386', | ||
'expected_packages': {'baz'} | ||
}), |
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.
You're missing a test for ensuring one can still have packages like name:arch
without the grammar rewriting the requested arch. Please add a test with this in both the body and an else.
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.
I just realized I didn't actually respond here: I added two new cases, with "arch specified" in the tag, for that. Good call!
For the record, CI failed with
|
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.
I've tested this with:
to <host arch>: [hello]
and hello was fetchedto <other arch>: [hello]
and hello was not fetchedto <other arch>: [hello]
with--target-arch=<other arch>
andhello:<other arch>
was fetched
These seem to be the expected results. I'm going to give this a +1, although I'm not a huge fan of altering other tests' snaps to suit the integration tests here.
@@ -105,3 +108,59 @@ def test_global_build_package_on_other_arch_else(self): | |||
self.run_snapcraft(['pull'], 'build-package-grammar-global') | |||
|
|||
self.assertTrue(self._hello_is_installed()) | |||
|
|||
@contextlib.contextmanager | |||
def modified_yaml(self, |
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.
I'd like to get @ElOpio's input on this. I'm not sure how I feel about it. I know we have a lot of test snaps, but warping other snaps to suit this test seems hard to follow. Maybe I'm just used to having YAML to refer to, but I prefer new test snaps.
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.
I don't like either.
I would like a function that makes a yaml, and it takes a string with the contents. This string is optional, if not present it will create the most simple and small valid snapcraft.yaml. This function also takes keyword arguments, for each of the keys of the yaml, so we can modify the basic default yaml.
We have some tests that do something like this, but nothing is consistent. Until we have that, I would prefer to either write the full yaml, or save it to snapcraft/tests/snaps. I don't like this modifier very much.
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.
Thanks for your feedback! It's true we have little consistency, which is why I proposed this.
In an effort to alleviate discussion I went ahead and added a function to construct the YAML from scratch, accepting keyword arguments for toplevel keys with defaults, based on @ElOpio's suggestion above. Although I wasn't entirely sure about the exact details regarding strings.
We should have a hangout to flesh this out.
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.
For the record: @ElOpio and I discussed this and decided to consolidate on extending the fixture to take arguments for parts and build packages like the function proposed here. We don't want a contextmanager, and rather dictionaries than strings. And sharing the fixture across the test suite including unit tests will be easier than making a function available everywhere.
For the record:
Not sure how this is happening. Locally it's fine and I didn't modify the test setup... |
For your error the only thing I can think of is that there is some sort of dictionary collision/squatting somewhere along the way |
def test_to_statement_grammar(self, platform_machine_mock, | ||
platform_architecture_mock): | ||
platform_machine_mock.return_value = 'x86_64' | ||
platform_architecture_mock.return_value = ('64bit', 'ELF') |
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.
Why are we setting this, here? to
doesn't care about the build host, right? Just the target arch, which we're setting here. Don't we actually want to make sure this runs on other architectures?
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.
Still not a fan of the tests, but if @ElOpio is happy, I'm happy.
@@ -196,6 +197,25 @@ def copy_project_to_cwd(self, project_dir: str) -> None: | |||
os.path.join(self.snaps_dir, project_dir), self.path, | |||
preserve_symlinks=True) | |||
|
|||
def construct_yaml(self, name='test', version='0.1', |
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.
This is better than it was before, but I feel like this is introducing yet another inconsistency in how we're doing this. I'd still rather see snaps in integration/snaps/ that we can test standalone as well, like the other grammar tests. However, I've already made that argument, so I won't block on it.
./runtests.sh static
?./runtests.sh unit
?This is the implementation of the "to" statement as discussed in the forum. This PR implements the bold items.
Items 7 and 8 are implemented in the follow-up PR #1800 to allow for quicker review (although I can also add them here if that's preferred, whichever is clearer).