Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 18, 2024
1 parent 427d0b4 commit fa0f362
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions tests/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def test_contextmanager_exception(self, context, event_loop):
assert exc.value is exception

@pytest.mark.anyio
@pytest.mark.parametrize('anyio_backend', ['asyncio'])
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
async def test_async_contextmanager_exception(self, event_loop, context):
"""Test that "async with context:" calls close() with the exception raised in the block."""
close_future = event_loop.create_future()
Expand Down Expand Up @@ -416,15 +416,15 @@ def factory(ctx: Context) -> Optional[str]: # noqa: UP007
assert context.require_resource(str) == "foo"

@pytest.mark.anyio
@pytest.mark.parametrize('anyio_backend', ['asyncio'])
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
async def test_getattr_attribute_error(self, context: Context) -> None:
async with context, Context() as child_context:
pytest.raises(AttributeError, getattr, child_context, "foo").match(
"no such context variable: foo"
)

@pytest.mark.anyio
@pytest.mark.parametrize('anyio_backend', ['asyncio'])
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
async def test_getattr_parent(self, context: Context) -> None:
"""
Test that accessing a nonexistent attribute on a context retrieves the value from parent.
Expand All @@ -435,7 +435,7 @@ async def test_getattr_parent(self, context: Context) -> None:
assert child_context.a == 2

@pytest.mark.anyio
@pytest.mark.parametrize('anyio_backend', ['asyncio'])
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
async def test_get_resources(self, context: Context) -> None:
context.add_resource(9, "foo")
context.add_resource_factory(lambda ctx: len(ctx.context_chain), int, "bar")
Expand All @@ -445,7 +445,7 @@ async def test_get_resources(self, context: Context) -> None:
assert subctx.get_resources(int) == {1, 4}

@pytest.mark.anyio
@pytest.mark.parametrize('anyio_backend', ['asyncio'])
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
async def test_require_resource(self, context: Context) -> None:
context.add_resource(1)
assert context.require_resource(int) == 1
Expand Down Expand Up @@ -476,7 +476,7 @@ async def add_resource():
assert resource == 6

@pytest.mark.anyio
@pytest.mark.parametrize('anyio_backend', ['asyncio'])
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
async def test_request_resource_factory_context_attr(self, context: Context) -> None:
"""Test that requesting a factory-generated resource also sets the context variable."""
with pytest.deprecated_call():
Expand All @@ -486,7 +486,7 @@ async def test_request_resource_factory_context_attr(self, context: Context) ->
assert context.__dict__["foo"] == 6

@pytest.mark.anyio
@pytest.mark.parametrize('anyio_backend', ['asyncio'])
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
async def test_call_async_plain(self, context: Context) -> None:
def runs_in_event_loop(worker_thread: Thread, x: int, y: int) -> int:
assert current_thread() is not worker_thread
Expand All @@ -499,7 +499,7 @@ def runs_in_worker_thread() -> int:
assert await context.call_in_executor(runs_in_worker_thread) == 3

@pytest.mark.anyio
@pytest.mark.parametrize('anyio_backend', ['asyncio'])
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
async def test_call_async_coroutine(self, context: Context) -> None:
async def runs_in_event_loop(worker_thread, x, y):
assert current_thread() is not worker_thread
Expand All @@ -513,7 +513,7 @@ def runs_in_worker_thread() -> int:
assert await context.call_in_executor(runs_in_worker_thread) == 3

@pytest.mark.anyio
@pytest.mark.parametrize('anyio_backend', ['asyncio'])
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
async def test_call_async_exception(self, context: Context) -> None:
def runs_in_event_loop() -> NoReturn:
raise ValueError("foo")
Expand All @@ -524,15 +524,15 @@ def runs_in_event_loop() -> NoReturn:
assert exc.match("foo")

@pytest.mark.anyio
@pytest.mark.parametrize('anyio_backend', ['asyncio'])
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
async def test_call_in_executor(self, context: Context) -> None:
"""Test that call_in_executor actually runs the target in a worker thread."""
worker_thread = await context.call_in_executor(current_thread)
assert worker_thread is not current_thread()

@pytest.mark.parametrize("use_resource_name", [True, False], ids=["direct", "resource"])
@pytest.mark.anyio
@pytest.mark.parametrize('anyio_backend', ['asyncio'])
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
async def test_call_in_executor_explicit(self, context, use_resource_name):
executor = ThreadPoolExecutor(1)
context.add_resource(executor, types=[Executor])
Expand All @@ -542,7 +542,7 @@ async def test_call_in_executor_explicit(self, context, use_resource_name):
assert worker_thread is not current_thread()

@pytest.mark.anyio
@pytest.mark.parametrize('anyio_backend', ['asyncio'])
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
async def test_call_in_executor_context_preserved(self, context: Context) -> None:
"""
Test that call_in_executor runs the callable in a copy of the current (PEP 567)
Expand All @@ -553,14 +553,14 @@ async def test_call_in_executor_context_preserved(self, context: Context) -> Non
assert await context.call_in_executor(current_context) is ctx

@pytest.mark.anyio
@pytest.mark.parametrize('anyio_backend', ['asyncio'])
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
async def test_threadpool(self, context: Context) -> None:
event_loop_thread = current_thread()
async with context.threadpool():
assert current_thread() is not event_loop_thread

@pytest.mark.anyio
@pytest.mark.parametrize('anyio_backend', ['asyncio'])
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
async def test_threadpool_named_executor(
self, context: Context, special_executor: Executor
) -> None:
Expand All @@ -571,7 +571,7 @@ async def test_threadpool_named_executor(

class TestExecutor:
@pytest.mark.anyio
@pytest.mark.parametrize('anyio_backend', ['asyncio'])
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
async def test_no_arguments(self, context: Context) -> None:
@executor
def runs_in_default_worker() -> None:
Expand All @@ -583,7 +583,7 @@ def runs_in_default_worker() -> None:
await runs_in_default_worker()

@pytest.mark.anyio
@pytest.mark.parametrize('anyio_backend', ['asyncio'])
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
async def test_named_executor(self, context: Context, special_executor: Executor) -> None:
@executor("special")
def runs_in_default_worker(ctx: Context) -> None:
Expand All @@ -595,7 +595,7 @@ def runs_in_default_worker(ctx: Context) -> None:
await runs_in_default_worker(context)

@pytest.mark.anyio
@pytest.mark.parametrize('anyio_backend', ['asyncio'])
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
async def test_executor_missing_context(self, context: Context):
@executor("special")
def runs_in_default_worker() -> None:
Expand Down Expand Up @@ -725,7 +725,7 @@ async def start(ctx: Context) -> None:
],
)
@pytest.mark.anyio
@pytest.mark.parametrize('anyio_backend', ['asyncio'])
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
async def test_get_resource_at_teardown(self, resource_func) -> None:
resource = ""

Expand All @@ -750,7 +750,7 @@ async def teardown_callback() -> None:
],
)
@pytest.mark.anyio
@pytest.mark.parametrize('anyio_backend', ['asyncio'])
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
async def test_generate_resource_at_teardown(self, resource_func) -> None:
resource = ""

Expand Down Expand Up @@ -793,7 +793,7 @@ async def start(ctx: Context) -> AsyncIterator[None]:


@pytest.mark.anyio
@pytest.mark.parametrize('anyio_backend', ['asyncio'])
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
async def test_current_context() -> None:
pytest.raises(NoCurrentContext, current_context)

Expand All @@ -808,7 +808,7 @@ async def test_current_context() -> None:


@pytest.mark.anyio
@pytest.mark.parametrize('anyio_backend', ['asyncio'])
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
async def test_get_resource() -> None:
async with Context() as ctx:
ctx.add_resource("foo")
Expand All @@ -817,7 +817,7 @@ async def test_get_resource() -> None:


@pytest.mark.anyio
@pytest.mark.parametrize('anyio_backend', ['asyncio'])
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
async def test_require_resource() -> None:
async with Context() as ctx:
ctx.add_resource("foo")
Expand Down

0 comments on commit fa0f362

Please sign in to comment.