Skip to content

Commit

Permalink
don't wipe out the failures. gosh there were a ton of these
Browse files Browse the repository at this point in the history
This commit was sponsored by Steven S., and my other patrons.  If you
want to join them, you can support my work at
https://glyph.im/patrons/.
  • Loading branch information
glyph committed Mar 18, 2024
1 parent 4be1032 commit 76765a6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
32 changes: 14 additions & 18 deletions src/dbxs/_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,24 +146,19 @@ def schedule(
@dataclass
class DeferredCompletionTester:
failer: Callable[[str], None]
deferred: Deferred[object]
succeeded: list[object]
failed: list[Failure]

def assertNoResult(self) -> None:
succeeded: list[object] = []
failed: list[Failure] = []
self.deferred.addCallbacks(succeeded.append, failed.append)
if failed:
failed[0].raiseException()
if succeeded:
self.failer(f"unexpected result {succeeded[0]}")
if self.failed:
self.failed[0].raiseException()
if self.succeeded:
self.failer(f"unexpected result {self.succeeded[0]}")

def assertSuccessResult(self) -> None:
succeeded: list[object] = []
failed: list[Failure] = []
self.deferred.addCallbacks(succeeded.append, failed.append)
if failed:
failed[0].raiseException()
if not succeeded:
if self.failed:
self.failed[0].raiseException()
if not self.succeeded:
self.failer("no result")


Expand All @@ -173,10 +168,11 @@ def schedule(
failer: Callable[[str], None],
coroutine: Coroutine[Any, Any, Any],
) -> CompletionTester:
return DeferredCompletionTester(
failer,
Deferred.fromCoroutine(coroutine),
)
succeeded: list[object] = []
failed: list[Failure] = []
deferred = Deferred.fromCoroutine(coroutine)
deferred.addCallbacks(succeeded.append, failed.append)
return DeferredCompletionTester(failer, succeeded, failed)


def immediateTest(
Expand Down
16 changes: 15 additions & 1 deletion src/dbxs/test/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def method(self: TestFailing, pool: MemoryPool) -> None:

def test_failsBeforeBlocking(self) -> None:
"""
If an @immediateTest raises an exception, taht exception is re-raised.
If an @immediateTest raises an exception, that exception is re-raised.
"""

@immediateTest()
Expand All @@ -47,3 +47,17 @@ async def method(self: TestFailing, pool: MemoryPool) -> None:

with self.assertRaises(ZeroDivisionError):
method(self)

def test_failsAfterBlocking(self) -> None:
"""
If an @immediateTest raises an exception after blocking, that exception
is re-raised as well.
"""

@immediateTest()
async def method(self: TestFailing, pool: MemoryPool) -> None:
await pool.connectable.connect()
1 / 0

with self.assertRaises(ZeroDivisionError):
method(self)

0 comments on commit 76765a6

Please sign in to comment.