Explicitly call dump_traceback() function and check its output. Raise an error if the output doesn't match the expected format.
(self, *, filename=None, fd=None)
| 483 | self.assertEqual(output.rstrip(), b"True") |
| 484 | |
| 485 | def check_dump_traceback(self, *, filename=None, fd=None): |
| 486 | """ |
| 487 | Explicitly call dump_traceback() function and check its output. |
| 488 | Raise an error if the output doesn't match the expected format. |
| 489 | """ |
| 490 | code = """ |
| 491 | import faulthandler |
| 492 | |
| 493 | filename = {filename!r} |
| 494 | fd = {fd} |
| 495 | |
| 496 | def funcB(): |
| 497 | if filename: |
| 498 | with open(filename, "wb") as fp: |
| 499 | faulthandler.dump_traceback(fp, all_threads=False) |
| 500 | elif fd is not None: |
| 501 | faulthandler.dump_traceback(fd, |
| 502 | all_threads=False) |
| 503 | else: |
| 504 | faulthandler.dump_traceback(all_threads=False) |
| 505 | |
| 506 | def funcA(): |
| 507 | funcB() |
| 508 | |
| 509 | funcA() |
| 510 | """ |
| 511 | code = code.format( |
| 512 | filename=filename, |
| 513 | fd=fd, |
| 514 | ) |
| 515 | if filename: |
| 516 | lineno = 9 |
| 517 | elif fd is not None: |
| 518 | lineno = 11 |
| 519 | else: |
| 520 | lineno = 14 |
| 521 | expected = [ |
| 522 | f'{STACK_HEADER_STR}', |
| 523 | ' File "<string>", line %s in funcB' % lineno, |
| 524 | ' File "<string>", line 17 in funcA', |
| 525 | ' File "<string>", line 19 in <module>' |
| 526 | ] |
| 527 | trace, exitcode = self.get_output(code, filename, fd) |
| 528 | self.assertEqual(trace, expected) |
| 529 | self.assertEqual(exitcode, 0) |
| 530 | |
| 531 | def test_dump_traceback(self): |
| 532 | self.check_dump_traceback() |
no test coverage detected