-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: port entry points to click cli; add tests (#483)
* chore: add click to install dependencies Note, black uses click, so gets installed with lint deps (pip install -e .[lint], but not without. * feat: use click for fill and other pytest-based commands * docs: update docs for new click --help flag Now fill only shows EEST-specific help when --help is provided. * refactor: rename entry_points folder to cli * refactor: port pyspelling and markdownlint to click * refactor: port order_fixtures to click * chore: fix import in docstring * feat: return pytest exit code from click command * fix: return 0 from fill help command, as pytest does * tests(fw): add tests for fill/pytest click cli * tests: add tests for order fixtures * chore: add typehints * feat: port hasher to click * feat: port evm_bytes_to_python to click * docs: update changelog
- Loading branch information
1 parent
392c7fe
commit c6a2d33
Showing
20 changed files
with
413 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
""" | ||
CLI entry points for the main pytest-based commands provided by | ||
execution-spec-tests. | ||
These can be directly accessed in a prompt if the user has directly installed | ||
the package via: | ||
``` | ||
python -m venv venv | ||
source venv/bin/activate | ||
pip install -e . | ||
# or | ||
pip install -e .[doc,lint,test] | ||
``` | ||
Then, the entry points can be executed via: | ||
``` | ||
fill --help | ||
# for example, or | ||
fill --collect-only | ||
``` | ||
They can also be executed (and debugged) directly in an interactive python | ||
shell: | ||
``` | ||
from src.cli.pytest_commands import fill | ||
from click.testing import CliRunner | ||
runner = CliRunner() | ||
result = runner.invoke(fill, ["--help"]) | ||
print(result.output) | ||
``` | ||
""" | ||
|
||
import sys | ||
from typing import Any, Callable, List | ||
|
||
import click | ||
import pytest | ||
|
||
# Define a custom type for decorators, which are functions that return functions. | ||
Decorator = Callable[[Callable[..., Any]], Callable[..., Any]] | ||
|
||
|
||
@click.command(context_settings=dict(ignore_unknown_options=True)) | ||
def tf() -> None: | ||
""" | ||
The `tf` command, deprecated as of 2023-06. | ||
""" | ||
print( | ||
"The `tf` command-line tool has been superseded by `fill`. Try:\n\n" | ||
"fill --help\n\n" | ||
"or see the online docs:\n" | ||
"https://ethereum.github.io/execution-spec-tests/getting_started/executing_tests_command_line/" # noqa: E501 | ||
) | ||
sys.exit(1) | ||
|
||
|
||
def common_click_options(func: Callable[..., Any]) -> Decorator: | ||
""" | ||
Define common click options for fill and other pytest-based commands. | ||
Note that we don't verify any other options here, rather pass them | ||
directly to the pytest command for processing. | ||
""" | ||
func = click.option( | ||
"-h", | ||
"--help", | ||
"help_flag", | ||
is_flag=True, | ||
default=False, | ||
expose_value=True, | ||
help="Show help message.", | ||
)(func) | ||
|
||
func = click.option( | ||
"--pytest-help", | ||
"pytest_help_flag", | ||
is_flag=True, | ||
default=False, | ||
expose_value=True, | ||
help="Show pytest's help message.", | ||
)(func) | ||
|
||
return click.argument("pytest_args", nargs=-1, type=click.UNPROCESSED)(func) | ||
|
||
|
||
def handle_help_flags( | ||
pytest_args: List[str], help_flag: bool, pytest_help_flag: bool | ||
) -> List[str]: | ||
""" | ||
Modify the arguments passed to the click CLI command before forwarding to | ||
the pytest command. | ||
This is to make `--help` more useful because `pytest --help` is extremely | ||
verbose and lists all flags from pytest and pytest plugins. | ||
""" | ||
if help_flag: | ||
return ["--test-help"] | ||
elif pytest_help_flag: | ||
return ["--help"] | ||
else: | ||
return list(pytest_args) | ||
|
||
|
||
@click.command(context_settings=dict(ignore_unknown_options=True)) | ||
@common_click_options | ||
def fill(pytest_args: List[str], help_flag: bool, pytest_help_flag: bool) -> None: | ||
""" | ||
Entry point for the fill command. | ||
""" | ||
args = handle_help_flags(pytest_args, help_flag, pytest_help_flag) | ||
result = pytest.main(args) | ||
sys.exit(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
""" | ||
Tests for scripts and apps in `cli` . | ||
""" |
2 changes: 1 addition & 1 deletion
2
..._points/tests/test_evm_bytes_to_python.py → src/cli/tests/test_evm_bytes_to_python.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.