Skip to content

Commit

Permalink
fix: invalid integer when using -v flag in ape test (ApeWorX#2291)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Sep 18, 2024
1 parent f787f79 commit a2e2dd4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/ape/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
skip_confirmation_option,
verbosity_option,
)
from ape.cli.paramtype import JSON, Path
from ape.cli.paramtype import JSON, Noop, Path

__all__ = [
"account_option",
Expand All @@ -45,6 +45,7 @@
"network_option",
"NetworkChoice",
"NetworkOption",
"Noop",
"non_existing_alias_argument",
"output_format_choice",
"output_format_option",
Expand Down
3 changes: 2 additions & 1 deletion src/ape/cli/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
output_format_choice,
)
from ape.cli.commands import ConnectedProviderCommand
from ape.cli.paramtype import JSON
from ape.cli.paramtype import JSON, Noop
from ape.exceptions import Abort, ProjectError
from ape.logging import DEFAULT_LOG_LEVEL, ApeLogger, LogLevel, logger
from ape.utils.basemodel import ManagerAccessMixin
Expand Down Expand Up @@ -88,6 +88,7 @@ def set_level(ctx, param, value):
"expose_value": False,
"help": f"One of {names_str}",
"is_eager": True,
"type": Noop(),
}


Expand Down
12 changes: 12 additions & 0 deletions src/ape/cli/paramtype.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
from pathlib import Path as PathLibPath
from typing import Any

import click

Expand Down Expand Up @@ -34,3 +35,14 @@ def convert(self, value, param, ctx):
self.fail(f"Invalid JSON string: {err}", param, ctx)

return value # Good already.


class Noop(click.ParamType):
"""
A param-type for ignoring param-types.
Good to use when the multi-type handling
happens already in a callback or in the command itself.
"""

def convert(self, value: Any, param, ctx) -> Any:
return value
12 changes: 12 additions & 0 deletions tests/integration/cli/test_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,18 @@ def test_test_isolation_disabled(setup_pytester, integ_project, pytester, eth_te
assert "F _function_isolation" not in "\n".join(result.outlines)


@skip_projects_except("test")
def test_verbosity(runner, ape_cli):
"""
Tests again an issue where `ape test -v debug` would fail because of
an invalid type check from click; only appeared in `ape test` command
for some reason.
"""
# NOTE: Only using `--fixtures` flag to avoid running tests (just prints fixtures).
result = runner.invoke(ape_cli, ("test", "--verbosity", "DEBUG", "--fixtures"))
assert result.exit_code == 0, result.output


@skip_projects_except("test", "with-contracts")
def test_fixture_docs(setup_pytester, integ_project, pytester, eth_tester_provider):
_ = eth_tester_provider # Ensure using EthTester for this test.
Expand Down

0 comments on commit a2e2dd4

Please sign in to comment.