Skip to content

Commit

Permalink
chore: remove email-validator from examples/testing dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
lachaib committed Jul 25, 2024
1 parent 265f271 commit d599489
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 66 deletions.
5 changes: 5 additions & 0 deletions docs/tutorial/parameter-types/pydantic-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ Successfully installed typer rich pydantic
$ pip install pydantic
---> 100%
Successfully installed pydantic

// Or if you want to use EmailStr
$ pip install "pydantic[email]"
---> 100%
Successfully installed pydantic, email-validator
```

</div>
Expand Down
6 changes: 3 additions & 3 deletions docs_src/parameter_types/pydantic_types/tutorial001.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import typer
from pydantic import EmailStr
from pydantic import AnyHttpUrl


def main(email_arg: EmailStr):
typer.echo(f"email_arg: {email_arg}")
def main(url_arg: AnyHttpUrl):
typer.echo(f"url_arg: {url_arg}")


if __name__ == "__main__":
Expand Down
6 changes: 3 additions & 3 deletions docs_src/parameter_types/pydantic_types/tutorial001_an.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import typer
from pydantic import EmailStr
from pydantic import AnyHttpUrl
from typing_extensions import Annotated


def main(email_arg: Annotated[EmailStr, typer.Argument()]):
typer.echo(f"email_arg: {email_arg}")
def main(url_arg: Annotated[AnyHttpUrl, typer.Argument()]):
typer.echo(f"url_arg: {url_arg}")


if __name__ == "__main__":
Expand Down
6 changes: 3 additions & 3 deletions docs_src/parameter_types/pydantic_types/tutorial002.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import typer
from pydantic import EmailStr
from pydantic import AnyHttpUrl


def main(email_opt: EmailStr = typer.Option("tiangolo@gmail.com")):
typer.echo(f"email_opt: {email_opt}")
def main(url_opt: AnyHttpUrl = typer.Option("https://typer.tiangolo.com")):
typer.echo(f"url_opt: {url_opt}")


if __name__ == "__main__":
Expand Down
6 changes: 3 additions & 3 deletions docs_src/parameter_types/pydantic_types/tutorial002_an.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import typer
from pydantic import EmailStr
from pydantic import AnyHttpUrl
from typing_extensions import Annotated


def main(email_opt: Annotated[EmailStr, typer.Option()] = "[email protected]"):
typer.echo(f"email_opt: {email_opt}")
def main(url_opt: Annotated[AnyHttpUrl, typer.Option()] = "[email protected]"):
typer.echo(f"url_opt: {url_opt}")


if __name__ == "__main__":
Expand Down
11 changes: 5 additions & 6 deletions docs_src/parameter_types/pydantic_types/tutorial004.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
from typing import Tuple

import typer
from pydantic import AnyHttpUrl, EmailStr
from pydantic import AnyHttpUrl, IPvAnyAddress


def main(
user: Tuple[str, int, EmailStr, AnyHttpUrl] = typer.Option(
..., help="User name, age, email and social media URL"
server: Tuple[str, IPvAnyAddress, AnyHttpUrl] = typer.Option(
..., help="Server name, IP address and public URL"
),
):
name, age, email, url = user
name, address, url = server
typer.echo(f"name: {name}")
typer.echo(f"age: {age}")
typer.echo(f"email: {email}")
typer.echo(f"address: {address}")
typer.echo(f"url: {url}")


Expand Down
11 changes: 5 additions & 6 deletions docs_src/parameter_types/pydantic_types/tutorial004_an.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
from typing import Tuple

import typer
from pydantic import AnyHttpUrl, EmailStr
from pydantic import AnyHttpUrl, IPvAnyAddress
from typing_extensions import Annotated


def main(
user: Annotated[
Tuple[str, int, EmailStr, AnyHttpUrl],
server: Annotated[
Tuple[str, IPvAnyAddress, AnyHttpUrl],
typer.Option(help="User name, age, email and social media URL"),
],
):
name, age, email, url = user
name, address, url = server
typer.echo(f"name: {name}")
typer.echo(f"age: {age}")
typer.echo(f"email: {email}")
typer.echo(f"address: {address}")
typer.echo(f"url: {url}")


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ homepage = "https://github.com/tiangolo/typer"
standard = [
"shellingham >=1.3.0",
"rich >=10.11.0",
"pydantic[email] >=2.0.0",
"pydantic >=2.0.0",
]

[tool.pdm]
Expand Down
2 changes: 1 addition & 1 deletion requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ ruff ==0.2.0
# Needed explicitly by typer-slim
rich >=10.11.0
shellingham >=1.3.0
pydantic[email] >=2.0.0
pydantic >=2.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ def test_help():
assert result.exit_code == 0


def test_email_arg():
result = runner.invoke(app, ["tiangolo@gmail.com"])
def test_url_arg():
result = runner.invoke(app, ["https://typer.tiangolo.com"])
assert result.exit_code == 0
assert "email_arg: tiangolo@gmail.com" in result.output
assert "url_arg: https://typer.tiangolo.com" in result.output


def test_email_arg_invalid():
def test_url_arg_invalid():
result = runner.invoke(app, ["invalid"])
assert result.exit_code != 0
assert "value is not a valid email address" in result.output
assert "Input should be a valid URL" in result.output


def test_script():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ def test_help():
assert result.exit_code == 0


def test_email_arg():
result = runner.invoke(app, ["tiangolo@gmail.com"])
def test_url_arg():
result = runner.invoke(app, ["https://typer.tiangolo.com"])
assert result.exit_code == 0
assert "email_arg: tiangolo@gmail.com" in result.output
assert "url_arg: https://typer.tiangolo.com" in result.output


def test_email_arg_invalid():
def test_url_arg_invalid():
result = runner.invoke(app, ["invalid"])
assert result.exit_code != 0
assert "value is not a valid email address" in result.output
assert "Input should be a valid URL" in result.output


def test_script():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ def test_help():
assert result.exit_code == 0


def test_email_opt():
result = runner.invoke(app, ["--email-opt", "tiangolo@gmail.com"])
def test_url_opt():
result = runner.invoke(app, ["--url-opt", "https://typer.tiangolo.com"])
assert result.exit_code == 0
assert "email_opt: tiangolo@gmail.com" in result.output
assert "url_opt: https://typer.tiangolo.com" in result.output


def test_email_opt_invalid():
result = runner.invoke(app, ["--email-opt", "invalid"])
def test_url_opt_invalid():
result = runner.invoke(app, ["--url-opt", "invalid"])
assert result.exit_code != 0
assert "value is not a valid email address" in result.output
assert "Input should be a valid URL" in result.output


def test_script():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ def test_help():
assert result.exit_code == 0


def test_email_opt():
result = runner.invoke(app, ["--email-opt", "tiangolo@gmail.com"])
def test_url_opt():
result = runner.invoke(app, ["--url-opt", "https://typer.tiangolo.com"])
assert result.exit_code == 0
assert "email_opt: tiangolo@gmail.com" in result.output
assert "url_opt: https://typer.tiangolo.com" in result.output


def test_email_opt_invalid():
result = runner.invoke(app, ["--email-opt", "invalid"])
def test_url_opt_invalid():
result = runner.invoke(app, ["--url-opt", "invalid"])
assert result.exit_code != 0
assert "value is not a valid email address" in result.output
assert "Input should be a valid URL" in result.output


def test_script():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,25 @@ def test_help():


def test_tuple():
result = runner.invoke(
app, ["--user", "Camila", "23", "[email protected]", "https://example.com"]
)
result = runner.invoke(app, ["--server", "Example", "::1", "https://example.com"])
assert result.exit_code == 0
assert "name: Camila" in result.output
assert "age: 23" in result.output
assert "email: [email protected]" in result.output
assert "name: Example" in result.output
assert "address: ::1" in result.output
assert "url: https://example.com" in result.output


def test_tuple_invalid():
def test_tuple_invalid_ip():
result = runner.invoke(
app, ["--user", "Camila", "23", "invalid", "https://example.com"]
app, ["--server", "Invalid", "invalid", "https://example.com"]
)
assert result.exit_code != 0
assert "value is not a valid email address" in result.output
assert "value is not a valid IPv4 or IPv6 address" in result.output


def test_tuple_invalid_url():
result = runner.invoke(app, ["--server", "Invalid", "::1", "invalid"])
assert result.exit_code != 0
assert "Input should be a valid URL" in result.output


def test_script():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,25 @@ def test_help():


def test_tuple():
result = runner.invoke(
app, ["--user", "Camila", "23", "[email protected]", "https://example.com"]
)
result = runner.invoke(app, ["--server", "Example", "::1", "https://example.com"])
assert result.exit_code == 0
assert "name: Camila" in result.output
assert "age: 23" in result.output
assert "email: [email protected]" in result.output
assert "name: Example" in result.output
assert "address: ::1" in result.output
assert "url: https://example.com" in result.output


def test_tuple_invalid():
def test_tuple_invalid_ip():
result = runner.invoke(
app, ["--user", "Camila", "23", "invalid", "https://example.com"]
app, ["--server", "Invalid", "invalid", "https://example.com"]
)
assert result.exit_code != 0
assert "value is not a valid email address" in result.output
assert "value is not a valid IPv4 or IPv6 address" in result.output


def test_tuple_invalid_url():
result = runner.invoke(app, ["--server", "Invalid", "::1", "invalid"])
assert result.exit_code != 0
assert "Input should be a valid URL" in result.output


def test_script():
Expand Down

0 comments on commit d599489

Please sign in to comment.