MCPcopy
hub / github.com/pallets/click / TestContext

Class TestContext

tests/test_context.py:539–563  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

537
538def test_with_resource_exception() -> None:
539 class TestContext(AbstractContextManager[list[int]]):
540 _handle_exception: bool
541 _base_val: int
542 val: list[int]
543
544 def __init__(self, base_val: int = 1, *, handle_exception: bool = True) -> None:
545 self._handle_exception = handle_exception
546 self._base_val = base_val
547
548 def __enter__(self) -> list[int]:
549 self.val = [self._base_val]
550 return self.val
551
552 def __exit__(
553 self,
554 exc_type: type[BaseException] | None,
555 exc_value: BaseException | None,
556 traceback: TracebackType | None,
557 ) -> bool | None:
558 if not exc_type:
559 self.val[0] = self._base_val - 1
560 return None
561
562 self.val[0] = self._base_val + 1
563 return self._handle_exception
564
565 class TestException(Exception):
566 pass

Calls

no outgoing calls

Tested by 2