-
Notifications
You must be signed in to change notification settings - Fork 88
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
Issue 337: Added pkg_key to ensure 'packages' == 'dependencies' #359
base: master
Are you sure you want to change the base?
Conversation
…A_STACK_2. If the user has `auto_stack: 1` or higher and has a stacked environment as indicated by `CONDA_STACK_2 == True`, then the PATH environmental variable might be modified bt prepare. This change ignores the error if `CONDA_STACK_2 == True`. A better resolution would be to control the configuration of the conda environment before running tests.
This test parameterizes "properties" in all tests in test_project.py but only tests the "properties".
API change: to_json(pkg_key) now take this argument.
The general strategy here is to add an attribute The testing strategy is to introduce a The current implementation breaks python 2.7 compatibility (I use f-strings in many places to keep the new code separate from older code) but this is easily changed with The tests which run the |
On my Mac I've rebased your branch against #352 where I have fixed the tests, especially the slow ones. So far only 11 tests fail 👍 🎉 . I'll push a branch you can try for yourself and maybe make a few fixes for these tests. |
Here's my branch: https://github.com/AlbertDeFusco/anaconda-project/tree/adefuco/issue_337 |
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.
Some good stuff here. I'll keep looking at the tests against the soon-to-be-merged PR with corrected tests.
@@ -119,7 +119,7 @@ class ProjectFile(YamlFile): | |||
# Use `anaconda-project add-env-spec` to add environment specs. | |||
# | |||
env_specs: {} | |||
''' | |||
'''.replace('<pkg_key>', YamlFile.pkg_key) |
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'm curious about using replace. Is there a reason not to use format? For example,
"The pkg_key is {pkg_key}".format(pkg_key=YamlFile.pkg_key)
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.
There are places (like line 412 in this file) where the original string contains empty dictionaries {}
. If we use .format()
then we need to also convert all of these to {{}}
etc. I started using .format()
but then felt it was more explicit if we use a replacement of something that would be unlikely to appear in a .yaml
file so that escaping of braces is not needed.
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.
Oh, right. Good call.
yield request.param | ||
|
||
|
||
def _change_default_pkg_key(test_function): |
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.
Very cool. So would this only be needed for tests that don't explicitly write packages/dependencies in the file? For example a test that runs init?
Otherwise a test that does supply the list would only need to parameterize on pkg_key to run both scenarios.
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.
No, it should probably be used for some others too that also use the pkg_key
fixture to ensure that explicitly using both the default value, and the alternative value works in both cases of default value -- 4 cases. In practice, it is hard for me to imagine a situation where a test works with two of the cases, but fails with the other two, but I can't rule this out, so I provide this in case we stumble on one.
Another note. There is an easier way to change the in confest.py import pytest
@pytest.fixture(params=["packages", "dependencies"])
def pkg_key(request, monkeypatch):
"""Ensure equivalence between `dependencies` and `packages`"""
monkeypatch.setattr('anaconda_project.yaml_file.YamlFile.pkg_key', request.param)
return request.param For this case there would likely not be any difference between yield and return. I suppose either one works the same way since there is no other code after the yield. |
Is there a reason to However, I think that this should be done in a separate fixture |
Having them separate and using yield in pkg_key works for me. I would recommend using the oneline monkeypatch directly in the tests that need it rather than as a fixture or decorator. For example, this test would not change the default def test_add_command_specifying_notebook(monkeypatch, capsys, pkg_key):
def check_specifying_notebook(dirname):
args = Args('notebook', 'test', 'file.ipynb', directory=dirname)
res = main(args)
assert res == 0
project = Project(dirname)
command = project.project_file.get_value(['commands', 'test'])
assert command['notebook'] == 'file.ipynb'
assert command['env_spec'] == 'default'
assert len(command.keys()) == 2
with_directory_contents_completing_project_file({DEFAULT_PROJECT_FILENAME: f'{pkg_key}:\n - notebook\n'},
check_specifying_notebook) And a test that does the monkeypatch would have this extra line def test_add_command_generates_env_spec_suggestion(pkg_key):
monkeypatch.setattr('anaconda_project.yaml_file.YamlFile.pkg_key', pkg_key)
def check_add_command(dirname):
project = project_no_dedicated_env(dirname)
assert project.problems == []
... |
I think it might be better to keep both fixtures so it is clear which tests are testing different default values and which are testing different explicit values. I will try to take a stab at this today. There are some cases where I need input: What should happen if a user uses both Another example is My preference would be to migrate everything towards |
I'd like to have dependencies as default. A user may have Yaml aliased dependencies to packages, so a stern warning might be useful. |
Okay, then I suggest reworking things to simply convert |
No description provided.