Skip to content

Commit 52aa13d

Browse files
feat(consume): update --input and fix --help (#745)
* fix: mypy tox issue. * feat(consume): update --input & fix --help. * fix(cli): add one-liner help strings for `consume --help` Specify the help attribute when registering the command; it's too late if the help/__doc__ attribute is set after registration. * feat(cli): enable `consume -h` flag * chore: fix missing sys import. * chore: small review comment changes. --------- Co-authored-by: danceratopz <[email protected]>
1 parent 59379a8 commit 52aa13d

File tree

11 files changed

+140
-141
lines changed

11 files changed

+140
-141
lines changed

.vscode/launch.recommended.json

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,7 @@
7272
"-v"
7373
],
7474
"cwd": "${workspaceFolder}"
75-
},
76-
{
77-
// To help debugging the --test-help command.
78-
"name": "Launch fill --test-help",
79-
"type": "python",
80-
"request": "launch",
81-
"module": "pytest",
82-
"args": [
83-
"-c",
84-
"pytest.ini",
85-
"--test-help"
86-
],
87-
"cwd": "/home/dtopz/code/github/danceratopz/execution-spec-tests"
88-
},
75+
}
8976
],
9077
"inputs": [
9178
{

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Test fixtures for use by clients are available for each release on the [Github r
3636
- ✨ Added a new flag `--solc-version` to the `fill` command, which allows the user to specify the version of the Solidity compiler to use when compiling Yul source code; this version will now be automatically downloaded by `fill` via [`solc-select`](https://github.com/crytic/solc-select) ([#772](https://github.com/ethereum/execution-spec-tests/pull/772)).
3737
- 🐞 Fix usage of multiple `@pytest.mark.with_all*` markers which shared parameters, such as `with_all_call_opcodes` and `with_all_create_opcodes` which shared `evm_code_type`, and now only parametrize compatible values ([#762](https://github.com/ethereum/execution-spec-tests/pull/762)).
3838
- ✨ Added `selector` and `marks` fields to all `@pytest.mark.with_all*` markers, which allows passing lambda functions to select or mark specific parametrized values (see [documentation](https://ethereum.github.io/execution-spec-tests/main/writing_tests/test_markers/#covariant-marker-keyword-arguments) for more information) ([#762](https://github.com/ethereum/execution-spec-tests/pull/762)).
39+
- ✨ Improves consume input flags for develop and stable fixture releases, fixes `--help` flag for consume ([#745](https://github.com/ethereum/execution-spec-tests/pull/745)).
3940

4041
### 🔧 EVM Tools
4142

docs/getting_started/executing_tests_command_line.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,10 @@ usage: fill [-h] [--strict-alloc] [--ca-start CA_START] [--ca-incr CA_INCR]
119119
[--solc-version SOLC_VERSION] [--evm-bin EVM_BIN] [--traces]
120120
[--verify-fixtures] [--verify-fixtures-bin VERIFY_FIXTURES_BIN]
121121
[--filler-path FILLER_PATH] [--output OUTPUT] [--flat-output]
122-
[--single-fixture-per-file] [--no-html] [--build-name BUILD_NAME]
123-
[--index] [--evm-dump-dir EVM_DUMP_DIR] [--forks] [--fork FORK]
124-
[--from FROM] [--until UNTIL] [--test-help]
122+
[--single-fixture-per-file] [--no-html] [--strict-alloc]
123+
[--ca-start CA_START] [--ca-incr CA_INCR] [--build-name BUILD_NAME]
124+
[--evm-dump-dir EVM_DUMP_DIR] [--forks] [--fork FORK] [--from FROM]
125+
[--until UNTIL]
125126
126127
options:
127128
-h, --help show this help message and exit
@@ -191,9 +192,5 @@ Specify the fork range to generate fixtures for:
191192
--from FROM Fill tests from and including the specified fork.
192193
--until UNTIL Fill tests until and including the specified fork.
193194
194-
Arguments related to running execution-spec-tests:
195-
--test-help Only show help options specific to a specific execution-
196-
spec-tests command and exit.
197-
198195
Exit: After displaying help.
199196
```

src/cli/pytest_commands/common.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ def common_click_options(func: Callable[..., Any]) -> Decorator:
3838
return click.argument("pytest_args", nargs=-1, type=click.UNPROCESSED)(func)
3939

4040

41-
def handle_help_flags(
42-
pytest_args: List[str], help_flag: bool, pytest_help_flag: bool
43-
) -> List[str]:
41+
def handle_help_flags(pytest_args: List[str], pytest_type: str) -> List[str]:
4442
"""
4543
Modifies the help arguments passed to the click CLI command before forwarding to
4644
the pytest command.
4745
4846
This is to make `--help` more useful because `pytest --help` is extremely
4947
verbose and lists all flags from pytest and pytest plugins.
5048
"""
51-
if help_flag:
52-
return ["--test-help"]
53-
elif pytest_help_flag:
49+
ctx = click.get_current_context()
50+
51+
if ctx.params.get("help_flag"):
52+
return [f"--{pytest_type}-help"] if pytest_type in {"consume", "fill"} else pytest_args
53+
elif ctx.params.get("pytest_help_flag"):
5454
return ["--help"]
55-
else:
56-
return list(pytest_args)
55+
56+
return pytest_args

src/cli/pytest_commands/consume.py

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,18 @@ def handle_hive_env_flags(args: List[str]) -> List[str]:
3535
return args
3636

3737

38-
def handle_consume_command_flags(
39-
consume_args: List[str],
40-
help_flag: bool,
41-
pytest_help_flag: bool,
42-
is_hive: bool,
43-
) -> List[str]:
38+
def handle_consume_command_flags(consume_args: List[str], is_hive: bool) -> List[str]:
4439
"""
4540
Handle all consume CLI flag pre-processing.
4641
"""
47-
args = handle_help_flags(consume_args, help_flag, pytest_help_flag)
42+
args = list(handle_help_flags(consume_args, pytest_type="consume"))
4843
args += ["-c", "pytest-consume.ini"]
4944
if is_hive:
50-
args = handle_hive_env_flags(args)
45+
args += handle_hive_env_flags(args)
5146
args += ["-p", "pytest_plugins.pytest_hive.pytest_hive"]
52-
# Pipe input using stdin if no --input is provided and stdin is not a terminal.
53-
if not any(arg.startswith("--input") for arg in args) and not sys.stdin.isatty():
54-
args.extend(["-s", "--input=stdin"])
55-
# Ensure stdout is captured when timing data is enabled.
56-
if "--timing-data" in args and "-s" not in args:
57-
args.append("-s")
47+
# Ensure stdout is captured when timing data is enabled.
48+
if "--timing-data" in args and "-s" not in args:
49+
args.append("-s")
5850
return args
5951

6052

@@ -81,23 +73,25 @@ def consume_command(is_hive: bool = False) -> Callable[[Callable[..., Any]], cli
8173
"""
8274

8375
def create_command(
84-
func: Callable[..., Any], command_name: str, command_paths: List[Path], is_hive: bool
76+
func: Callable[..., Any],
77+
command_name: str,
78+
command_help: str | None,
79+
command_paths: List[Path],
80+
is_hive: bool,
8581
) -> click.Command:
8682
"""
8783
Create the command function to be decorated.
8884
"""
8985

90-
@consume.command(name=command_name, context_settings=dict(ignore_unknown_options=True))
86+
@consume.command(
87+
name=command_name,
88+
help=command_help,
89+
context_settings=dict(ignore_unknown_options=True),
90+
)
9191
@common_click_options
92-
def command(pytest_args: List[str], help_flag: bool, pytest_help_flag: bool) -> None:
93-
args = handle_consume_command_flags(
94-
pytest_args,
95-
help_flag,
96-
pytest_help_flag,
97-
is_hive,
98-
)
92+
def command(pytest_args: List[str], **kwargs) -> None:
93+
args = handle_consume_command_flags(pytest_args, is_hive)
9994
args += [str(p) for p in command_paths]
100-
10195
if is_hive and not any(arg.startswith("--hive-session-temp-folder") for arg in args):
10296
with TemporaryDirectory() as temp_dir:
10397
args.extend(["--hive-session-temp-folder", temp_dir])
@@ -106,21 +100,21 @@ def command(pytest_args: List[str], help_flag: bool, pytest_help_flag: bool) ->
106100
result = pytest.main(args)
107101
sys.exit(result)
108102

109-
command.__doc__ = func.__doc__
110103
return command
111104

112105
def decorator(func: Callable[..., Any]) -> click.Command:
113106
command_name = func.__name__
107+
command_help = func.__doc__
114108
command_paths = get_command_paths(command_name, is_hive)
115-
return create_command(func, command_name, command_paths, is_hive)
109+
return create_command(func, command_name, command_help, command_paths, is_hive)
116110

117111
return decorator
118112

119113

120-
@click.group()
114+
@click.group(context_settings=dict(help_option_names=["-h", "--help"]))
121115
def consume() -> None:
122116
"""
123-
Entry point group to aid client consumption of test fixtures.
117+
Consume command to aid client consumption of test fixtures.
124118
"""
125119
pass
126120

src/cli/pytest_commands/fill.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,33 +45,25 @@ def handle_stdout_flags(args: List[str]) -> List[str]:
4545
return args
4646

4747

48-
def handle_fill_command_flags(
49-
fill_args: List[str], help_flag: bool, pytest_help_flag: bool
50-
) -> List[str]:
48+
def handle_fill_command_flags(fill_args: List[str]) -> List[str]:
5149
"""
5250
Handles all fill CLI flag pre-processing.
5351
"""
54-
args = handle_help_flags(fill_args, help_flag, pytest_help_flag)
52+
args = handle_help_flags(fill_args, pytest_type="fill")
5553
args = handle_stdout_flags(args)
5654
return args
5755

5856

5957
@click.command(context_settings=dict(ignore_unknown_options=True))
6058
@common_click_options
61-
def fill(
62-
pytest_args: List[str],
63-
help_flag: bool,
64-
pytest_help_flag: bool,
65-
) -> None:
59+
def fill(pytest_args: List[str], **kwargs) -> None:
6660
"""
6761
Entry point for the fill command.
6862
"""
6963
with TemporaryDirectory() as temp_dir:
7064
result = pytest.main(
7165
handle_fill_command_flags(
7266
[f"--session-temp-folder={temp_dir}", "--index", *pytest_args],
73-
help_flag,
74-
pytest_help_flag,
7567
),
7668
)
7769
sys.exit(result)

src/pytest_plugins/consume/consume.py

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,10 @@ def pytest_addoption(parser): # noqa: D103
8383
dest="fixture_source",
8484
default=default_input_directory(),
8585
help=(
86-
"A URL or local directory specifying the JSON test fixtures. Default: "
87-
f"'{default_input_directory()}'."
88-
),
89-
)
90-
consume_group.addoption(
91-
"--latest",
92-
action="store_true",
93-
dest="latest_source",
94-
default=False,
95-
help=(
96-
"The latest EEST development JSON test fixtures. Cannot be used alongside `--input`."
86+
"Specify the JSON test fixtures source. Can be a local directory, a URL pointing to a "
87+
" fixtures.tar.gz archive, or one of the special keywords: 'stdin', "
88+
"'latest-stable', 'latest-develop'. "
89+
f"Defaults to the following local directory: '{default_input_directory()}'."
9790
),
9891
)
9992
consume_group.addoption(
@@ -103,13 +96,6 @@ def pytest_addoption(parser): # noqa: D103
10396
default=None,
10497
help="Only consume tests for the specified fork.",
10598
)
106-
consume_group.addoption(
107-
"--timing-data",
108-
action="store_true",
109-
dest="timing_data",
110-
default=False,
111-
help="Log the timing data for each test case execution.",
112-
)
11399
consume_group.addoption(
114100
"--no-html",
115101
action="store_true",
@@ -133,20 +119,17 @@ def pytest_configure(config): # noqa: D103
133119
it uses the modified `htmlpath` option.
134120
"""
135121
input_flag = any(arg.startswith("--input") for arg in config.invocation_params.args)
136-
latest_flag = config.getoption("latest_source")
137-
138-
if input_flag and latest_flag:
139-
pytest.exit("Cannot use both `--input` and `--latest`, please select one input flag.")
140-
141122
input_source = config.getoption("fixture_source")
142123

143124
if input_flag and input_source == "stdin":
144125
config.test_cases = TestCases.from_stream(sys.stdin)
145126
return
146127

147-
if latest_flag:
148-
release_base_url = "https://github.com/ethereum/execution-spec-tests/releases"
149-
input_source = f"{release_base_url}/latest/download/fixtures_develop.tar.gz"
128+
latest_base_url = "https://github.com/ethereum/execution-spec-tests/releases/latest/download"
129+
if input_source == "latest-stable-release" or input_source == "latest-stable":
130+
input_source = f"{latest_base_url}/fixtures_stable.tar.gz"
131+
if input_source == "latest-develop-release" or input_source == "latest-develop":
132+
input_source = f"{latest_base_url}/fixtures_develop.tar.gz"
150133

151134
if is_url(input_source):
152135
cached_downloads_directory.mkdir(parents=True, exist_ok=True)
@@ -162,6 +145,7 @@ def pytest_configure(config): # noqa: D103
162145
)
163146

164147
index_file = input_source / ".meta" / "index.json"
148+
index_file.parent.mkdir(parents=True, exist_ok=True)
165149
if not index_file.exists():
166150
rich.print(f"Generating index file [bold cyan]{index_file}[/]...")
167151
generate_fixtures_index(

src/pytest_plugins/consume/hive_simulators/conftest.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@
2020
from .timing import TimingData
2121

2222

23+
def pytest_addoption(parser):
24+
"""
25+
Hive simulator specific consume command line options.
26+
"""
27+
consume_group = parser.getgroup(
28+
"consume", "Arguments related to consuming fixtures via a client"
29+
)
30+
consume_group.addoption(
31+
"--timing-data",
32+
action="store_true",
33+
dest="timing_data",
34+
default=False,
35+
help="Log the timing data for each test case execution.",
36+
)
37+
38+
2339
@pytest.fixture(scope="function")
2440
def eth_rpc(client: Client) -> EthRPC:
2541
"""
@@ -55,7 +71,10 @@ def eest_consume_commands(
5571
Commands to run the test within EEST using a hive dev back-end.
5672
"""
5773
hive_dev = f"./hive --dev --client-file configs/develop.yaml --client {client_type.name}"
58-
consume = f'consume {test_suite_name.split("-")[-1]} -v --latest -k "{test_case.id}"'
74+
consume = (
75+
f'consume {test_suite_name.split("-")[-1]} -v --input latest-develop-release -k '
76+
f'"{test_case.id}"'
77+
)
5978
return [hive_dev, consume]
6079

6180

0 commit comments

Comments
 (0)