Skip to content

Commit 26d20b0

Browse files
committed
Swap to nox for testing. Use own run_app to prevent aiohttp cleanup
1 parent 37bd712 commit 26d20b0

File tree

5 files changed

+62
-35
lines changed

5 files changed

+62
-35
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*.log
33
.coverage
44
.mypy_cache
5+
.nox/
56
.pytest_cache
67
.tox/
78
__pycache__/

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ disable=raw-checker-failed,
3333
logging-fstring-interpolation,
3434

3535
[IMPORTS]
36-
ignored-modules=aiohttp,pysasl,pymap,aiosmtpd,pytest,mail_devel
36+
ignored-modules=aiohttp,nox,pysasl,pymap,aiosmtpd,pytest,mail_devel

noxfile.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import nox
2+
3+
4+
@nox.session()
5+
def clean(session):
6+
session.install("coverage")
7+
session.run("coverage", "erase")
8+
9+
10+
@nox.session()
11+
def py3(session):
12+
session.install(
13+
"pytest",
14+
"pytest-asyncio",
15+
"pytest-cov",
16+
"pytest-xdist",
17+
"pytest-timeout",
18+
"coverage",
19+
)
20+
session.install(".")
21+
session.run(
22+
"pytest",
23+
"-n=5",
24+
"--cov-append",
25+
"--cov=src/mail_devel",
26+
"--asyncio-mode=auto",
27+
"--timeout=5",
28+
)
29+
30+
31+
@nox.session()
32+
def report(session):
33+
session.install("coverage")
34+
session.run("coverage", "html")
35+
session.run("coverage", "report", "--fail-under=80")

src/mail_devel/http.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import os
3+
import ssl
34
import uuid
45
from email import header, message_from_bytes, message_from_string, policy
56
from email.errors import MessageDefect
@@ -27,6 +28,29 @@ def flags_to_api(flags: frozenset[Flag]) -> list[str]:
2728
return [f.value.decode().strip("\\").lower() for f in flags]
2829

2930

31+
async def run_app(
32+
api,
33+
host: str | None = None,
34+
port: int | None = None,
35+
ssl_context: ssl.SSLContext | None = None,
36+
) -> web.AppRunner:
37+
app = web.AppRunner(
38+
api,
39+
access_log_format='%a "%r" %s %b "%{Referer}i" "%{User-Agent}i"',
40+
)
41+
await app.setup()
42+
43+
site = web.TCPSite(
44+
app,
45+
host=host,
46+
port=port,
47+
reuse_address=True,
48+
reuse_port=True,
49+
ssl_context=ssl_context,
50+
)
51+
await site.start()
52+
53+
3054
class Frontend:
3155
def __init__(
3256
self,
@@ -90,14 +114,10 @@ async def start(self) -> None:
90114
]
91115
)
92116

93-
return await web._run_app(
117+
return await run_app(
94118
self.api,
95119
host=self.host or None,
96120
port=self.port,
97-
access_log_format='%a "%r" %s %b "%{Referer}i" "%{User-Agent}i"',
98-
reuse_address=True,
99-
reuse_port=True,
100-
print=lambda *x: None,
101121
)
102122

103123
async def _page_index(self, request: Request) -> Response: # pylint: disable=W0613

tox.ini

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)