Skip to content
Myr

#2447 Split resource exception handling tests in single and nested

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Michele Bianchi · committed by Michele Bianchi · parent 92129c5 · Browse files · 1 file+34 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+34 added−0 removed

  • tests:+34 added−0 removed

1 file+34 added−0 removed

modified:tests/test_context.py+34 added
476 unmodified lines
477 TestContext(base_val=base_val, handle_exception=False)478 )479 raise TestException()480481482def test_with_resource_nested_exception() -> None:483 class TestContext(AbstractContextManager[list[int]]):484 _handle_exception: bool485 _base_val: int486 val: list[int]487488 def __init__(self, base_val: int = 1, *, handle_exception: bool = True) -> None:489 self._handle_exception = handle_exception490 self._base_val = base_val491492 def __enter__(self) -> list[int]:493 self.val = [self._base_val]494 return self.val495496 def __exit__(497 self,498 exc_type: type[BaseException] | None,499 exc_value: BaseException | None,500 traceback: TracebackType | None,501 ) -> bool | None:502 if not exc_type:503 self.val[0] = self._base_val - 1504 return None505506 self.val[0] = self._base_val + 1507 return self._handle_exception508509 class TestException(Exception):510 pass511512 ctx = click.Context(click.Command("test"))513 base_val = 1514 base_val_nested = 11515516 with ctx.scope():517 rv = ctx.with_resource(TestContext(base_val=base_val))518 rv_nested = ctx.with_resource(TestContext(base_val=base_val_nested))519 assert rv[0] == base_val
153 unmodified lines