Add type hints to test.test_proxymanager
MODIFY
noxfile.py
noxfile.py
@@ -171,6 +171,7 @@ def mypy(session: nox.Session) -> None:
"test/port_helpers.py",
"test/test_exceptions.py",
"test/test_fields.py",
+ "test/test_proxymanager.py",
"test/test_retry.py",
"test/test_wait.py",
"test/tz_stub.py",

MODIFY
test/test_proxymanager.py
test/test_proxymanager.py
@@ -10,7 +10,7 @@ from .port_helpers import find_unused_port
class TestProxyManager:
@pytest.mark.parametrize("proxy_scheme", ["http", "https"])
- def test_proxy_headers(self, proxy_scheme):
+ def test_proxy_headers(self, proxy_scheme: str) -> None:
url = "http://pypi.org/project/urllib3/"
proxy_url = f"{proxy_scheme}://something:1234"
with ProxyManager(proxy_url) as p:
@@ -39,19 +39,21 @@ class TestProxyManager:
assert headers == expected_headers
- def test_default_port(self):
+ def test_default_port(self) -> None:
with ProxyManager("http://something") as p:
+ assert p.proxy is not None
assert p.proxy.port == 80
with ProxyManager("https://something") as p:
+ assert p.proxy is not None
assert p.proxy.port == 443
- def test_invalid_scheme(self):
+ def test_invalid_scheme(self) -> None:
with pytest.raises(AssertionError):
ProxyManager("invalid://host/p")
with pytest.raises(ValueError):
ProxyManager("invalid://host/p")
- def test_proxy_tunnel(self):
+ def test_proxy_tunnel(self) -> None:
http_url = parse_url("http://example.com")
https_url = parse_url("https://example.com")
with ProxyManager("http://proxy:8080") as p:
@@ -66,7 +68,7 @@ class TestProxyManager:
assert p._proxy_requires_url_absolute_form(http_url)
assert p._proxy_requires_url_absolute_form(https_url)
- def test_proxy_connect_retry(self):
+ def test_proxy_connect_retry(self) -> None:
retry = Retry(total=None, connect=False)
port = find_unused_port()
with ProxyManager(f"http://localhost:{port}") as p:
@@ -76,6 +78,8 @@ class TestProxyManager:
retry = Retry(total=None, connect=2)
with ProxyManager(f"http://localhost:{port}") as p:
- with pytest.raises(MaxRetryError) as ei:
+ with pytest.raises(MaxRetryError) as ei1:
p.urlopen("HEAD", url="http://localhost/", retries=retry)
- assert isinstance(ei.value.reason.original_error, NewConnectionError)
+ assert ei1.value.reason is not None
+ assert isinstance(ei1.value.reason, ProxyError)
+ assert isinstance(ei1.value.reason.original_error, NewConnectionError)

Add type hints to test.test_proxymanager