Skip to content

Commit 7918875

Browse files
authored
Merge pull request #3 from d-chris/develop
changed error message
2 parents aadbddf + ab91808 commit 7918875

File tree

7 files changed

+66
-7
lines changed

7 files changed

+66
-7
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ repos:
5252
rev: 7.1.2
5353
hooks:
5454
- id: flake8
55-
args: ["--max-line-length", "88", "--ignore=E501"]
55+
args: ["--max-line-length", "88"]
5656
language_version: python3.8
5757
- repo: https://github.com/asottile/pyupgrade
5858
rev: v3.19.1

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ $ main.py fu.bar.com
117117
Usage: main.py [OPTIONS] EMAIL
118118
Try 'main.py --help' for help.
119119
120-
Error: Invalid value for 'EMAIL': Invalid email='fu.bar.com'.
120+
Error: Invalid value for 'EMAIL': 'fu.bar.com'.
121121
```
122122

123123
## Dependencies

clicktypes/decorator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def __init__(self, **kwargs):
1414

1515
def convert(self, value, param, ctx):
1616
if self._func(value) is not True:
17-
self.fail(f"Invalid {self.name}='{value}'.", param, ctx)
17+
self.fail(repr(value), param, ctx)
1818
return value
1919

2020
return type(

templates/README.md.jinja2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ $ main.py fu.bar.com
7070
Usage: main.py [OPTIONS] EMAIL
7171
Try 'main.py --help' for help.
7272

73-
Error: Invalid value for 'EMAIL': Invalid email='fu.bar.com'.
73+
Error: Invalid value for 'EMAIL': 'fu.bar.com'.
7474
```
7575

7676
## Dependencies

tests/test_envvar.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import click
2+
import pytest
3+
from click.testing import CliRunner
4+
5+
import clicktypes
6+
7+
8+
@click.command(name="email", help="email validator")
9+
@click.option(
10+
"--email",
11+
type=clicktypes.email(),
12+
envvar="EMAIL",
13+
multiple=True,
14+
)
15+
def cli(email):
16+
click.echo(f"valid {email=}")
17+
18+
19+
@pytest.mark.parametrize(
20+
"emails,exit_code",
21+
[
22+
("foo@bar.com", 0),
23+
("foo.bar.com", 2),
24+
("foo@bar.com bar@foo.com", 0),
25+
("foo@bar.com bar.foo.com", 2),
26+
],
27+
)
28+
def test_envvar(emails, exit_code):
29+
30+
runner = CliRunner()
31+
result = runner.invoke(cli, env={"EMAIL": emails})
32+
assert result.exit_code == exit_code
33+
34+
35+
if __name__ == "__main__":
36+
cli()

tests/test_validator.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
from click.testing import CliRunner
44

55
import clicktypes
6-
7-
from . import validator_data
6+
from tests import validator_data
87

98

109
def cli(validator: str, **kwargs):

tox.ini

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,35 @@ env_list =
88
py310
99
py39
1010
py38
11+
cov
1112

1213
[testenv]
14+
skip_install = true
1315
deps =
1416
poetry==1.8.5
17+
set_env =
18+
COVERAGE_FILE = {toxworkdir}/.coverage.{envname}
1519
commands_pre =
16-
poetry install --all-extras
20+
poetry install --only main,test --extras eth
1721
commands =
1822
poetry run pytest
23+
24+
[testenv:cov]
25+
deps =
26+
coverage
27+
parallel_show_output = true
28+
set_env =
29+
COVERAGE_FILE = {toxworkdir}/.coverage
30+
commands_pre =
31+
coverage combine {toxworkdir}
32+
commands =
33+
coverage html -d {toxworkdir}/htmlcov
34+
commands_post =
35+
coverage report --show-missing --skip-covered
36+
depends =
37+
py313
38+
py312
39+
py311
40+
py310
41+
py39
42+
py38

0 commit comments

Comments
 (0)