Draft: Add command behaviour tests#60
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## improve-golden-master-tests #60 +/- ##
================================================================
+ Coverage 83.59% 99.48% +15.89%
================================================================
Files 27 27
Lines 957 977 +20
================================================================
+ Hits 800 972 +172
+ Misses 157 5 -152 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| DEFAULT_VERSION_FILENAME = ".version" | ||
|
|
||
| DEPLOYMENT_SNAPSHOT_FILENAME = "deployment.yaml" | ||
| PREVIOUS_DEPLOYMENT_SNAPSHOT_FILENAME = "previous-deployment.yaml" |
There was a problem hiding this comment.
Dead code (now uses git refs)
|
|
||
| It should be the Module's name and version as /<config_folder>/<name>/<version>.yaml | ||
| """ | ||
| if version_path.is_dir() and version_path.suffix == YAML_FILE_SUFFIX: |
There was a problem hiding this comment.
Dead code as _load_release() already checks if path.is_dir()
e346540 to
5730578
Compare
This covers cases that aren't easily tested with golden master tests.
Tests relating to non-existent output dir use the compare function as otherwise the Typer configuration prevents the exception being raised.
This feature was replaced with the git ref option to the compare command.
5730578 to
df673cc
Compare
|
Is the target branch supposed to be improve-golden-master-tests? |
ptsOSL
left a comment
There was a problem hiding this comment.
I've reviewed it as best I can. I will say there are over 1300 lines of code in this PR and I was losing concentration a bit towards the end. It might have been better to split up some of the tests into their own PRs.
| f"Deployment snapshot not found at git ref:\n{ref}" | ||
| ) from exc | ||
|
|
||
| with io.BytesIO(ref_snapshot.data_stream.read()) as snapshot_f: # type: ignore |
There was a problem hiding this comment.
Why does this need # type: ignore ?
There was a problem hiding this comment.
Although GitPython has type hints, it appears gitdb (a dependency) does not. I'll add a minor edit to remove the type ignore statement.
This is also just an indentation change.
| with repo: | ||
| logger.info("Creating snapshot") | ||
| create_snapshot(deployment, layout) |
There was a problem hiding this comment.
Why is this "with" needed now when it wasnt before? Does it actually do anything here?
There was a problem hiding this comment.
It's used in Python for context managers, and allows us to automatically handle the closing of the object. I'll probably split off the code improvements as it seems there were a few too many in this PR.
There was a problem hiding this comment.
I understand that its to handle context, I just havnt seen it used in a situation like this where the "repo" object has already been initialised earlier and already exists in the outer context.
Is the with section just opening a connection using the already created Repo instance and then after the "with" section, is the connection is closed? I would have expected something more like
with repo.open_connetion() as con
There was a problem hiding this comment.
It is just guaranteeing that repo.close() is called whenever you leave that block. The reason it can't do it the way you're describing is that the initialisation has an if/else block
I've looked at the options, and it seems this is the more common approach. You can, of course, create a function like "init_or_load_existing_repo" but that obviously has its own issues.
There was a problem hiding this comment.
I think the name of this file is perhaps a bit confusing. This isn't the only test file which tests the cli, but its name suggests that its singular purpose is to test the cli. I suppose the difference is that in this file we call it with subprocess, while elsewhere we use the typer interface to call the cli. Maybe it could be renamed to clarify that? Also is there really any difference between using subprocess and the typer interface for the purpose of the tests?
There was a problem hiding this comment.
The difference between subprocess and typer is that typer.testing.CLIRunner doesn't actually spawn a separate process, and uses the typer app directly. Since the error handling logic is in main(), we need to use subprocess to verify the output.
Although many other (but not all) tests consider the cli commands, this file includes the two that are generic across all commands. One checks the version info, and the other that the exceptions are being properly handled.
Do you have a recommendation for an alternative name?
There was a problem hiding this comment.
Maybe something like test_cli_configuration or test_cli_setup. In my mind the version check is just to check that the cli is setup correctly and the exception test is to check that the cli is setup with exception handling. I would also be happy with test_cli_basic just to make it obvious its not the only cli test file.
There was a problem hiding this comment.
I'll rename to test_cli_common.py
| ) | ||
| deprecated_link.parent.mkdir(parents=True, exist_ok=True) | ||
| deprecated_link.touch() | ||
| with pytest.raises(ComparisonError, match="Duplicate modulefiles"): |
There was a problem hiding this comment.
Do these error messages report which modulefiles are duplicated, or does the user just have to figure this out?
There was a problem hiding this comment.
I have changed the tests to check for more of the error message, including e.g. the names of the modulefiles. It makes them a bit more brittle, but that's reasonable.
| ("name-mismatch", "Module name .* does not match path"), | ||
| ("version-mismatch", "Module version .* does not match path"), |
There was a problem hiding this comment.
Is the .* in these messages to account for variables in string names? If so how comes you dont do that elsewhere? I have seen other error messages you check for where you only check for part of the error message. I assumed this was to avoid unresolved variables, but could you use .* in these cases as well? I may be misunderstanding something here.
There was a problem hiding this comment.
This is now done more consistently. .* is now used for e.g. the tmp dirs instead
|
I've swapped it back to draft, I'll try and split this up into at least a couple separate PRs. I'll cover all the comments you raise here first, though |
These test the parts of functionality that are not adequately covered by the golden master tests, such as errors.
Code changes are added for: