Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add script to generate and deploy click-based completions The herewith added script creates a tab-completion script for the Bash and Zsh shells and puts it in the system folder. The created completion script relies on the used click framework for command line parsing. * Remove completion files for Bash and Zsh When switching to the tab-completion capabilities provided by the click command line parsing framework, the manually created and maintained completion files are not necessary anymore. * Add tab completion for projects The subcommands 'aggregate', 'log', and 'report' now have tab completion support for projects. * Add tab completion for tags The subcommands 'aggregate', 'log', and 'report' now have tab completion support for tags. * Factor out initialisation of watson The line initialising watson read some environment variables and thus was not trivial. Therefore its duplications are against the DRY principle. In order to fix this, the line was moved to a helper function. * Add autocompletion for frame ids For the commands 'edit', 'remove' and 'restart' now the frame id is completed on tab. * StyleFix Do not return generator; yield instead * Add tab-completion for type in `watson rename` * Add tab completion for projects/tags in 'rename' With this commit, Click is able to generate completions for projects and tags in `watson rename`. * Provide completion for projects and tasks in `start` and `add` This commit adds Bash completion capabilities for projects and tasks in the subcommands `watson start` and `watson add`. For this, it imitates parsing of the complete command line, just as the aforementioned subcommands do. * Move autocompletion helper to separate module * Add dummy test for autocompletion module * Add watson fixture using custom frames list A fixture is added which simply loads a custom frames list. This can be used as a starting point for more useful tests. * Factor out TEST_FIXTURE_DIR This object was used twice, so it can live in the test utility module. * Improve docstring of get_frames() * Add and use frames file for autocompletion tests * Add basic test for get_frames() This very basic test to get_frames sets up all the logic that is required to run the autocompletion helpers in test mode. The main problem was that the helpers need to start their own instance of Watson. Therefore, the existing fixtures could not be used. * CleanUp Get rid of old watson fixture The old watson fixture was deleted. The tested functions start their own Watson instance, relying on the environment variable WATSON_DIR. Therefore, the fixture is not needed anymore. * Switch to new test frames file A new frames file for autocompletion tests is deployed. The most prominent benefit is that it is much longer now, giving room for better tests. The one existing user was adapted slightly, albeit the test certainly needs some extra robustness. * Add serious tests for get_frames() Tests for get_frames() are added. Different to the previous ones, the actually test the behaviour of get_frames for three plausible use cases. * Add tests for get_projects() The tests are copies of the tests for get_frames() and adapted to fit the projects. * Add tests for get_rename_type() The tests are copies of the tests for get_projects() and adapted to fit the rename types. * CleanUp Merge tests for distinct returns * CleanUp Merge tests for completion of empty prefix * CleanUp Merge tests for completion of nonexisting prefix * CleanUp Merge tests for completion of existing prefix * Add test for known completion values * Add get_tags() to test suite * Add get_rename_name() to test suite * Add context argument to parameterize This prepares the addition of get_rename_name(). * Add args argument to pytest.parameterize This prepares the addition of another test case for get_project_or_task(). * Change args parameter from None to [] The parameter args is a list of strings, so it is plausible to create it as such. Furthermore, this allows the addition of a test case for get_project_or_task_completion(). * Test project completion in get_project_or_task() * Test tag completion in get_project_or_task() * StyleFix Adapt code formatting using black The format of the code was a bit messed up. It was once reformatted using black in order to improve the readability a bit. * Minor improvements on docstrings * StyleFix Apply black autoformator on autocompletion module * CleanUp Move magic numbers to constants A lot of magic numbers were used to specify how many results were expected. This violates established practice. Therefore, almost all of them were replaced by constants. * CleanUp Turn prepare_sysenv_for_testing() to fixture The aforementioned function is turned to be a fixture and attached to the tests depending on it. This simplifies the tests a bit, as the test function signature and the test body become more lightweight. * Simplify autocompletion tests Previously, when Watson was called for autocompleting, two Watson objects were created: first in "cli.py:cli()" and again in the corresponding "autocomplete.py" method. Changes: - Move TEST_FIXTURE_DIR to "tests/__init.py__" as conftest is more suitable for fixtures (which are automatically available). - Add new watson_df fixture which easily allows to override the configuration path using pytest-datafiles. - Move frame test file into its own folder, avoiding manual renames. - Avoid needing CTXDummy object using SimpleNamespace and watson_df. - Rename get_watson_instance() to create_watson() to avoid implying that it's a singleton. Signed-off-by: Max Görner <[email protected]> * Move script for completion deployment to scripts/ Besides just moving it, it is renamed to reflect what will be the intended purpose after a pending refactoring. * Stop deploying completion receipts. In an effort to adapt the code to the existing documentation, the script is rewritten such that it does not deploy the generated receipts. Instead, it will write them to a file. * Remove redundant check for -h|--help * Integrate create-completion-script.sh in Makefile Unfortunately, generating the completion receipts has exit code 1 for unknown reasons. Thus, a '|| true' is required. * Explain completion receipt generation in documentation * Tighten silencing an expected error Instead of suppressing an expected error in the Makefile, it now is suppressed exactly where it is caused in the create-completion-script.sh. * BugFix Work around Click bug in all functions The commit by David Alfonso improved the code style considerably. Unfortunately it also triggered a bug in Click that does not pass the context object properly. While a workaround was added in some functions, some others have been forgotten. This caused some attempts on autocompletion to fail. The commit at hand applies the workaround everywhere where it is needed. * StyleFix Apply Black auto formatter for proper formatting Reference PR (#276)
- Loading branch information