Add type hints to test.contrib.test_pyopenssl
MODIFY
noxfile.py
noxfile.py
@@ -176,6 +176,7 @@ def mypy(session: nox.Session) -> None:
"test/with_dummyserver/test_socketlevel.py",
"test/conftest.py",
"test/contrib/test_pyopenssl_dependencies.py",
+ "test/contrib/test_pyopenssl.py",
"test/contrib/test_socks.py",
"test/port_helpers.py",
"test/test_collections.py",

MODIFY
test/contrib/test_pyopenssl.py
test/contrib/test_pyopenssl.py
@@ -5,14 +5,14 @@ import pytest
try:
from cryptography import x509
- from OpenSSL.crypto import FILETYPE_PEM, load_certificate
+ from OpenSSL.crypto import FILETYPE_PEM, load_certificate # type: ignore[import]
from urllib3.contrib.pyopenssl import _dnsname_to_stdlib, get_subj_alt_name
except ImportError:
pass
-def setup_module():
+def setup_module() -> None:
try:
from urllib3.contrib.pyopenssl import inject_into_urllib3
@@ -21,7 +21,7 @@ def setup_module():
pytest.skip(f"Could not import PyOpenSSL: {e!r}")
-def teardown_module():
+def teardown_module() -> None:
try:
from urllib3.contrib.pyopenssl import extract_from_urllib3
@@ -55,7 +55,7 @@ class TestPyOpenSSLHelpers:
Tests for PyOpenSSL helper functions.
"""
- def test_dnsname_to_stdlib_simple(self):
+ def test_dnsname_to_stdlib_simple(self) -> None:
"""
We can convert a dnsname to a native string when the domain is simple.
"""
@@ -64,7 +64,7 @@ class TestPyOpenSSLHelpers:
assert _dnsname_to_stdlib(name) == expected_result
- def test_dnsname_to_stdlib_leading_period(self):
+ def test_dnsname_to_stdlib_leading_period(self) -> None:
"""
If there is a . in front of the domain name we correctly encode it.
"""
@@ -73,7 +73,7 @@ class TestPyOpenSSLHelpers:
assert _dnsname_to_stdlib(name) == expected_result
- def test_dnsname_to_stdlib_leading_splat(self):
+ def test_dnsname_to_stdlib_leading_splat(self) -> None:
"""
If there's a wildcard character in the front of the string we handle it
appropriately.
@@ -84,7 +84,7 @@ class TestPyOpenSSLHelpers:
assert _dnsname_to_stdlib(name) == expected_result
@mock.patch("urllib3.contrib.pyopenssl.log.warning")
- def test_get_subj_alt_name(self, mock_warning):
+ def test_get_subj_alt_name(self, mock_warning: mock.MagicMock) -> None:
"""
If a certificate has two subject alternative names, cryptography raises
an x509.DuplicateExtension exception.

Add type hints to test.contrib.test_pyopenssl