| 1 | import pytest |
| 2 | |
| 3 | from cyclopts import ValidationError |
| 4 | from cyclopts.types import URL, Email |
| 5 | |
| 6 | |
| 7 | def test_types_web_email(convert): |
| 8 | convert(Email, "[email protected]") |
| 9 | |
| 10 | |
| 11 | def test_types_web_email_invalid(convert): |
| 12 | with pytest.raises(ValidationError): |
| 13 | convert(Email, "foo") |
| 14 | |
| 15 | |
| 16 | @pytest.mark.parametrize( |
| 17 | "url", |
| 18 | [ |
| 19 | "google.com", |
| 20 | "www.google.com", |
| 21 | "http://www.google.com", |
| 22 | "https://www.google.com", |
| 23 | "https://www.google.com:443", |
| 24 | "https://www.google.com/foo/bar", |
| 25 | ], |
| 26 | ) |
| 27 | def test_types_url(convert, url): |
| 28 | convert(URL, url) |
| 29 | |
| 30 | |
| 31 | @pytest.mark.parametrize( |
| 32 | "url", |
| 33 | [ |
| 34 | "foo", |
| 35 | "bar.", |
| 36 | "foo bar.com", |
| 37 | ], |
| 38 | ) |
| 39 | def test_types_url_invalid(convert, url): |
| 40 | with pytest.raises(ValidationError): |
| 41 | convert(URL, url) |