()
| 551 | |
| 552 | |
| 553 | def test_assert_message() -> None: |
| 554 | # the message does not need to list all parameters to RaisesGroup, nor all exceptions |
| 555 | # in the exception group, as those are both visible in the traceback. |
| 556 | # first fails to match |
| 557 | with ( |
| 558 | fails_raises_group("`TypeError()` is not an instance of `ValueError`"), |
| 559 | RaisesGroup(ValueError), |
| 560 | ): |
| 561 | raise ExceptionGroup("a", [TypeError()]) |
| 562 | with ( |
| 563 | fails_raises_group( |
| 564 | "Raised exception group did not match: \n" |
| 565 | "The following expected exceptions did not find a match:\n" |
| 566 | " RaisesGroup(ValueError)\n" |
| 567 | " RaisesGroup(ValueError, match='a')\n" |
| 568 | "The following raised exceptions did not find a match\n" |
| 569 | " ExceptionGroup('', [RuntimeError()]):\n" |
| 570 | " RaisesGroup(ValueError): `RuntimeError()` is not an instance of `ValueError`\n" |
| 571 | " RaisesGroup(ValueError, match='a'): Regex pattern did not match the `ExceptionGroup()`.\n" |
| 572 | " Expected regex: 'a'\n" |
| 573 | " Actual message: ''\n" |
| 574 | " RuntimeError():\n" |
| 575 | " RaisesGroup(ValueError): `RuntimeError()` is not an exception group\n" |
| 576 | " RaisesGroup(ValueError, match='a'): `RuntimeError()` is not an exception group", |
| 577 | add_prefix=False, # to see the full structure |
| 578 | ), |
| 579 | RaisesGroup(RaisesGroup(ValueError), RaisesGroup(ValueError, match="a")), |
| 580 | ): |
| 581 | raise ExceptionGroup( |
| 582 | "", |
| 583 | [ExceptionGroup("", [RuntimeError()]), RuntimeError()], |
| 584 | ) |
| 585 | |
| 586 | with ( |
| 587 | fails_raises_group( |
| 588 | "Raised exception group did not match: \n" |
| 589 | "2 matched exceptions. \n" |
| 590 | "The following expected exceptions did not find a match:\n" |
| 591 | " RaisesGroup(RuntimeError)\n" |
| 592 | " RaisesGroup(ValueError)\n" |
| 593 | "The following raised exceptions did not find a match\n" |
| 594 | " RuntimeError():\n" |
| 595 | " RaisesGroup(RuntimeError): `RuntimeError()` is not an exception group, but would match with `allow_unwrapped=True`\n" |
| 596 | " RaisesGroup(ValueError): `RuntimeError()` is not an exception group\n" |
| 597 | " ValueError('bar'):\n" |
| 598 | " It matches `ValueError` which was paired with `ValueError('foo')`\n" |
| 599 | " RaisesGroup(RuntimeError): `ValueError()` is not an exception group\n" |
| 600 | " RaisesGroup(ValueError): `ValueError()` is not an exception group, but would match with `allow_unwrapped=True`", |
| 601 | add_prefix=False, # to see the full structure |
| 602 | ), |
| 603 | RaisesGroup( |
| 604 | ValueError, |
| 605 | RaisesExc(TypeError), |
| 606 | RaisesGroup(RuntimeError), |
| 607 | RaisesGroup(ValueError), |
| 608 | ), |
| 609 | ): |
| 610 | raise ExceptionGroup( |
nothing calls this directly
no test coverage detected