()
| 479 | |
| 480 | |
| 481 | def test_message() -> None: |
| 482 | def check_message( |
| 483 | message: str, |
| 484 | body: RaisesGroup[BaseException], |
| 485 | ) -> None: |
| 486 | with ( |
| 487 | pytest.raises( |
| 488 | Failed, |
| 489 | match=f"^DID NOT RAISE any exception, expected `{re.escape(message)}`$", |
| 490 | ), |
| 491 | body, |
| 492 | ): |
| 493 | ... |
| 494 | |
| 495 | # basic |
| 496 | check_message("ExceptionGroup(ValueError)", RaisesGroup(ValueError)) |
| 497 | # multiple exceptions |
| 498 | check_message( |
| 499 | "ExceptionGroup(ValueError, ValueError)", |
| 500 | RaisesGroup(ValueError, ValueError), |
| 501 | ) |
| 502 | # nested |
| 503 | check_message( |
| 504 | "ExceptionGroup(ExceptionGroup(ValueError))", |
| 505 | RaisesGroup(RaisesGroup(ValueError)), |
| 506 | ) |
| 507 | |
| 508 | # RaisesExc |
| 509 | check_message( |
| 510 | "ExceptionGroup(RaisesExc(ValueError, match='my_str'))", |
| 511 | RaisesGroup(RaisesExc(ValueError, match="my_str")), |
| 512 | ) |
| 513 | check_message( |
| 514 | "ExceptionGroup(RaisesExc(match='my_str'))", |
| 515 | RaisesGroup(RaisesExc(match="my_str")), |
| 516 | ) |
| 517 | # one-size tuple is printed as not being a tuple |
| 518 | check_message( |
| 519 | "ExceptionGroup(RaisesExc(ValueError))", |
| 520 | RaisesGroup(RaisesExc((ValueError,))), |
| 521 | ) |
| 522 | check_message( |
| 523 | "ExceptionGroup(RaisesExc((ValueError, IndexError)))", |
| 524 | RaisesGroup(RaisesExc((ValueError, IndexError))), |
| 525 | ) |
| 526 | |
| 527 | # BaseExceptionGroup |
| 528 | check_message( |
| 529 | "BaseExceptionGroup(KeyboardInterrupt)", |
| 530 | RaisesGroup(KeyboardInterrupt), |
| 531 | ) |
| 532 | # BaseExceptionGroup with type inside RaisesExc |
| 533 | check_message( |
| 534 | "BaseExceptionGroup(RaisesExc(KeyboardInterrupt))", |
| 535 | RaisesGroup(RaisesExc(KeyboardInterrupt)), |
| 536 | ) |
| 537 | check_message( |
| 538 | "BaseExceptionGroup(RaisesExc((ValueError, KeyboardInterrupt)))", |
nothing calls this directly
no test coverage detected