Skip to content

Commit c37a9ab

Browse files
seidnerjpgjones
authored andcommitted
fixed all tests
1 parent 9400eb9 commit c37a9ab

File tree

10 files changed

+38
-14
lines changed

10 files changed

+38
-14
lines changed

tests/assets/config_ssl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
access_log_format = "bob"
44
bind = ["127.0.0.1:5555"]
5-
certfile = "assets/cert.pem"
5+
certfile = "tests/assets/cert.pem"
66
ciphers = "ECDHE+AESGCM"
77
h11_max_incomplete_size = 4
8-
keyfile = "assets/key.pem"
8+
keyfile = "tests/assets/key.pem"

tests/asyncio/test_keep_alive.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ async def slow_framework(
4545
@pytest_asyncio.fixture(name="server", scope="function") # type: ignore[misc]
4646
async def _server() -> AsyncGenerator[TCPServer, None]:
4747
event_loop: asyncio.AbstractEventLoop = asyncio.get_running_loop()
48+
4849
config = Config()
4950
config.keep_alive_timeout = KEEP_ALIVE_TIMEOUT
5051
server = TCPServer(

tests/asyncio/test_lifespan.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ async def no_lifespan_app(scope: Scope, receive: Callable, send: Callable) -> No
2222
@pytest.mark.asyncio
2323
async def test_ensure_no_race_condition() -> None:
2424
event_loop: asyncio.AbstractEventLoop = asyncio.get_running_loop()
25+
2526
config = Config()
2627
config.startup_timeout = 0.2
2728
lifespan = Lifespan(ASGIWrapper(no_lifespan_app), config, event_loop)
@@ -33,6 +34,7 @@ async def test_ensure_no_race_condition() -> None:
3334
@pytest.mark.asyncio
3435
async def test_startup_timeout_error() -> None:
3536
event_loop: asyncio.AbstractEventLoop = asyncio.get_running_loop()
37+
3638
config = Config()
3739
config.startup_timeout = 0.01
3840
lifespan = Lifespan(ASGIWrapper(SlowLifespanFramework(0.02, asyncio.sleep)), config, event_loop)
@@ -46,6 +48,7 @@ async def test_startup_timeout_error() -> None:
4648
@pytest.mark.asyncio
4749
async def test_startup_failure() -> None:
4850
event_loop: asyncio.AbstractEventLoop = asyncio.get_running_loop()
51+
4952
lifespan = Lifespan(ASGIWrapper(lifespan_failure), Config(), event_loop)
5053
lifespan_task = event_loop.create_task(lifespan.handle_lifespan())
5154
await lifespan.wait_for_startup()
@@ -62,6 +65,7 @@ async def return_app(scope: Scope, receive: Callable, send: Callable) -> None:
6265
@pytest.mark.asyncio
6366
async def test_lifespan_return() -> None:
6467
event_loop: asyncio.AbstractEventLoop = asyncio.get_running_loop()
68+
6569
lifespan = Lifespan(ASGIWrapper(return_app), Config(), event_loop)
6670
lifespan_task = event_loop.create_task(lifespan.handle_lifespan())
6771
await lifespan.wait_for_startup()

tests/asyncio/test_sanity.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
@pytest.mark.asyncio
1919
async def test_http1_request() -> None:
2020
event_loop: asyncio.AbstractEventLoop = asyncio.get_running_loop()
21+
2122
server = TCPServer(
2223
ASGIWrapper(sanity_framework),
2324
event_loop,
@@ -76,6 +77,7 @@ async def test_http1_request() -> None:
7677
@pytest.mark.asyncio
7778
async def test_http1_websocket() -> None:
7879
event_loop: asyncio.AbstractEventLoop = asyncio.get_running_loop()
80+
7981
server = TCPServer(
8082
ASGIWrapper(sanity_framework),
8183
event_loop,
@@ -114,6 +116,7 @@ async def test_http1_websocket() -> None:
114116
@pytest.mark.asyncio
115117
async def test_http2_request() -> None:
116118
event_loop: asyncio.AbstractEventLoop = asyncio.get_running_loop()
119+
117120
server = TCPServer(
118121
ASGIWrapper(sanity_framework),
119122
event_loop,
@@ -178,6 +181,7 @@ async def test_http2_request() -> None:
178181
@pytest.mark.asyncio
179182
async def test_http2_websocket() -> None:
180183
event_loop: asyncio.AbstractEventLoop = asyncio.get_running_loop()
184+
181185
server = TCPServer(
182186
ASGIWrapper(sanity_framework),
183187
event_loop,

tests/asyncio/test_task_group.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
@pytest.mark.asyncio
1515
async def test_spawn_app(http_scope: HTTPScope) -> None:
1616
event_loop: asyncio.AbstractEventLoop = asyncio.get_running_loop()
17+
1718
async def _echo_app(scope: Scope, receive: Callable, send: Callable) -> None:
1819
while True:
1920
message = await receive()
@@ -32,10 +33,9 @@ async def _echo_app(scope: Scope, receive: Callable, send: Callable) -> None:
3233

3334

3435
@pytest.mark.asyncio
35-
async def test_spawn_app_error(
36-
http_scope: HTTPScope
37-
) -> None:
36+
async def test_spawn_app_error(http_scope: HTTPScope) -> None:
3837
event_loop: asyncio.AbstractEventLoop = asyncio.get_running_loop()
38+
3939
async def _error_app(scope: Scope, receive: Callable, send: Callable) -> None:
4040
raise Exception()
4141

tests/asyncio/test_tcp_server.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
@pytest.mark.asyncio
1616
async def test_completes_on_closed() -> None:
1717
event_loop: asyncio.AbstractEventLoop = asyncio.get_running_loop()
18+
1819
server = TCPServer(
1920
ASGIWrapper(echo_framework),
2021
event_loop,
@@ -32,6 +33,7 @@ async def test_completes_on_closed() -> None:
3233
@pytest.mark.asyncio
3334
async def test_complets_on_half_close() -> None:
3435
event_loop: asyncio.AbstractEventLoop = asyncio.get_running_loop()
36+
3537
server = TCPServer(
3638
ASGIWrapper(echo_framework),
3739
event_loop,

tests/protocol/test_h11.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,9 @@ async def test_protocol_send_stream_closed(
136136

137137

138138
@pytest.mark.asyncio
139-
async def test_protocol_instant_recycle(
140-
protocol: H11Protocol
141-
) -> None:
139+
async def test_protocol_instant_recycle(protocol: H11Protocol) -> None:
142140
event_loop: asyncio.AbstractEventLoop = asyncio.get_running_loop()
141+
143142
# This test task acts as the asgi app, spawned tasks act as the
144143
# server.
145144
data = b"GET / HTTP/1.1\r\nHost: hypercorn\r\n\r\n"

tests/protocol/test_h2.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
@pytest.mark.asyncio
2323
async def test_stream_buffer_push_and_pop() -> None:
2424
event_loop: asyncio.AbstractEventLoop = asyncio.get_running_loop()
25+
2526
stream_buffer = StreamBuffer(EventWrapper)
2627

2728
async def _push_over_limit() -> bool:
@@ -39,6 +40,7 @@ async def _push_over_limit() -> bool:
3940
@pytest.mark.asyncio
4041
async def test_stream_buffer_drain() -> None:
4142
event_loop: asyncio.AbstractEventLoop = asyncio.get_running_loop()
43+
4244
stream_buffer = StreamBuffer(EventWrapper)
4345
await stream_buffer.push(b"a" * 10)
4446

tests/test_config.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,23 @@ def test_create_ssl_context() -> None:
5353
path = os.path.join(os.path.dirname(__file__), "assets/config_ssl.py")
5454
config = Config.from_pyfile(path)
5555
context = config.create_ssl_context()
56-
assert context.options & (
57-
ssl.OP_NO_SSLv2
58-
| ssl.OP_NO_SSLv3
59-
| ssl.OP_NO_TLSv1
60-
| ssl.OP_NO_TLSv1_1
61-
| ssl.OP_NO_COMPRESSION
56+
57+
# NOTE: In earlier versions of python context.options is equal to <Options.OP_NO_COMPRESSION: 0>
58+
# hence the ANDing context.options with the specified ssl options results in
59+
# "<Options.OP_NO_COMPRESSION: 0>", which as a Boolean value, is False.
60+
#
61+
# To overcome this, instead of checking that the result in True, we will check that it is
62+
# equal to "context.options".
63+
assert (
64+
context.options
65+
& (
66+
ssl.OP_NO_SSLv2
67+
| ssl.OP_NO_SSLv3
68+
| ssl.OP_NO_TLSv1
69+
| ssl.OP_NO_TLSv1_1
70+
| ssl.OP_NO_COMPRESSION
71+
)
72+
== context.options
6273
)
6374

6475

tests/trio/test_lifespan.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from __future__ import annotations
2+
23
import sys
34

45
if sys.version_info < (3, 11):

0 commit comments

Comments
 (0)