-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add compatibility for Python 3.13 #473
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,19 +5,28 @@ | |
import inspect | ||
import socket | ||
import ssl | ||
import sys | ||
import warnings | ||
from contextlib import suppress | ||
from functools import wraps | ||
from pathlib import Path | ||
from smtplib import SMTP as SMTPClient | ||
from typing import Any, Callable, Generator, NamedTuple, Optional, Type, TypeVar | ||
|
||
import pytest | ||
from pkg_resources import resource_filename | ||
rominf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
from pytest_mock import MockFixture | ||
|
||
from aiosmtpd.controller import Controller | ||
from aiosmtpd.handlers import Sink | ||
|
||
# `importlib.resources.files` was added in Python 3.9: | ||
# https://docs.python.org/3/library/importlib.resources.html#importlib.resources.files | ||
# Use backport https://github.com/python/importlib_resources on Python 3.8. | ||
if sys.version_info[:2] == (3, 8): | ||
import importlib_resources | ||
else: | ||
import importlib.resources as importlib_resources | ||
|
||
try: | ||
from asyncio.proactor_events import _ProactorBasePipeTransport | ||
|
||
|
@@ -32,8 +41,6 @@ | |
"handler_data", | ||
"Global", | ||
"AUTOSTOP_DELAY", | ||
"SERVER_CRT", | ||
"SERVER_KEY", | ||
] | ||
|
||
|
||
|
@@ -73,8 +80,6 @@ def set_addr_from(cls, contr: Controller): | |
# If less than 1.0, might cause intermittent error if test system | ||
# is too busy/overloaded. | ||
AUTOSTOP_DELAY = 1.5 | ||
SERVER_CRT = resource_filename("aiosmtpd.tests.certs", "server.crt") | ||
SERVER_KEY = resource_filename("aiosmtpd.tests.certs", "server.key") | ||
|
||
# endregion | ||
|
||
|
@@ -99,6 +104,22 @@ def cache_fqdn(session_mocker: MockFixture): | |
# region #### Common Fixtures ######################################################### | ||
|
||
|
||
def _server_resource(name: str, /) -> Generator[Path, None, None]: | ||
ref = importlib_resources.files("aiosmtpd.tests.certs") / name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Weird this is shipped in wheels.. I'd go for a relative path myself. OTOH, I recommend integrating https://trustme.rtfd.io like I did in aiohttp and many other places so that the TLS certificates are ephemeral and don't even exist in the repo. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree it is possible, however for me it looks like it is out of scope for this PR. |
||
with importlib_resources.as_file(ref) as path: | ||
yield path | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def server_crt() -> Generator[Path, None, None]: | ||
yield from _server_resource("server.crt") | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def server_key() -> Generator[Path, None, None]: | ||
yield from _server_resource("server.key") | ||
|
||
|
||
@pytest.fixture | ||
def get_controller(request: pytest.FixtureRequest) -> Callable[..., Controller]: | ||
""" | ||
|
@@ -315,25 +336,25 @@ def client(request: pytest.FixtureRequest) -> Generator[SMTPClient, None, None]: | |
|
||
|
||
@pytest.fixture | ||
def ssl_context_server() -> ssl.SSLContext: | ||
def ssl_context_server(server_crt: Path, server_key: Path) -> ssl.SSLContext: | ||
""" | ||
Provides a server-side SSL Context | ||
""" | ||
context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) | ||
context.check_hostname = False | ||
context.load_cert_chain(SERVER_CRT, SERVER_KEY) | ||
context.load_cert_chain(server_crt, server_key) | ||
# | ||
return context | ||
|
||
|
||
@pytest.fixture | ||
def ssl_context_client() -> ssl.SSLContext: | ||
def ssl_context_client(server_crt: Path) -> ssl.SSLContext: | ||
""" | ||
Provides a client-side SSL Context | ||
""" | ||
context = ssl.create_default_context(ssl.Purpose.SERVER_AUTH) | ||
context.check_hostname = False | ||
context.load_verify_locations(SERVER_CRT) | ||
context.load_verify_locations(server_crt) | ||
# | ||
return context | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
atpublic==5.0 | ||
attrs==24.2.0 | ||
coverage==7.6.1 | ||
importlib_resources;python_version<"3.9" | ||
pytest==8.3.2 | ||
pytest-asyncio==0.24.0 | ||
pytest-cov==5.0.0 | ||
pytest-mock==3.14.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weird to see this and no towncrier config in the repo..