Skip to content

Commit

Permalink
Remove unused context managers
Browse files Browse the repository at this point in the history
  • Loading branch information
Kostya Leschenko committed Apr 25, 2024
1 parent ae44e67 commit 6429d06
Showing 1 changed file with 0 additions and 23 deletions.
23 changes: 0 additions & 23 deletions tests/test_server.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,15 @@
from __future__ import annotations

import asyncio
import contextlib
import signal
import sys
from typing import Generator

import pytest

from uvicorn.config import Config
from uvicorn.server import Server


# asyncio does NOT allow raising in signal handlers, so to detect
# raised signals raised a mutable `witness` receives the signal
@contextlib.contextmanager
def capture_signal_sync(sig: signal.Signals) -> Generator[list[int], None, None]:
"""Replace `sig` handling with a normal exception via `signal"""
witness: list[int] = []
original_handler = signal.signal(sig, lambda signum, frame: witness.append(signum))
yield witness
signal.signal(sig, original_handler)


@contextlib.contextmanager
def capture_signal_async(sig: signal.Signals) -> Generator[list[int], None, None]: # pragma: py-win32
"""Replace `sig` handling with a normal exception via `asyncio"""
witness: list[int] = []
original_handler = signal.getsignal(sig)
asyncio.get_running_loop().add_signal_handler(sig, witness.append, sig)
yield witness
signal.signal(sig, original_handler)


async def dummy_app(scope, receive, send): # pragma: py-win32
pass

Expand Down

0 comments on commit 6429d06

Please sign in to comment.