|
3 | 3 | import unittest |
4 | 4 | import pickle |
5 | 5 | import gc |
| 6 | +import inspect |
6 | 7 |
|
7 | 8 | from stackless import schedule, tasklet, stackless |
8 | 9 |
|
@@ -606,6 +607,50 @@ class TestDictViewPicklingPy(AbstractTestPickledTasklets, DictViewPicklingTestCa |
606 | 607 | class TestDictViewPicklingC(AbstractTestPickledTasklets, DictViewPicklingTestCases, CPickleMixin): |
607 | 608 | pass |
608 | 609 |
|
| 610 | + |
| 611 | +class Traceback_TestCases(object): |
| 612 | + def testTracebackFrameLinkage(self): |
| 613 | + def a(): |
| 614 | + # raise an exception |
| 615 | + 1 // 0 |
| 616 | + |
| 617 | + def b(): |
| 618 | + return a() |
| 619 | + |
| 620 | + def c(): |
| 621 | + return b() |
| 622 | + |
| 623 | + try: |
| 624 | + c() |
| 625 | + except ZeroDivisionError: |
| 626 | + tb = sys.exc_info()[2] |
| 627 | + |
| 628 | + innerframes_orig = inspect.getinnerframes(tb) |
| 629 | + p = self.dumps(tb) |
| 630 | + tb2 = self.loads(p) |
| 631 | + # basics |
| 632 | + self.assertIs(type(tb), type(tb2)) |
| 633 | + self.assertIsNot(tb, tb2) |
| 634 | + innerframes = inspect.getinnerframes(tb2) |
| 635 | + # compare the content |
| 636 | + self.assertListEqual([i[1:] for i in innerframes_orig], [i[1:] for i in innerframes]) |
| 637 | + # check linkage |
| 638 | + all_outerframes_orig = inspect.getouterframes(innerframes_orig[-1][0]) |
| 639 | + all_outerframes = inspect.getouterframes(innerframes[-1][0]) |
| 640 | + l = len(innerframes_orig) |
| 641 | + self.assertGreater(len(all_outerframes_orig), l) |
| 642 | + self.assertGreaterEqual(len(all_outerframes), l) |
| 643 | + # compare the content |
| 644 | + self.assertListEqual([i[1:] for i in all_outerframes_orig[:l - 1]], [i[1:] for i in all_outerframes[:l - 1]]) |
| 645 | + |
| 646 | + |
| 647 | +class TestTracebackPy(StacklessTestCase, Traceback_TestCases, PyPickleMixin): |
| 648 | + pass |
| 649 | + |
| 650 | + |
| 651 | +class TestTracebackC(StacklessTestCase, Traceback_TestCases, CPickleMixin): |
| 652 | + pass |
| 653 | + |
609 | 654 | if __name__ == '__main__': |
610 | 655 | if not sys.argv[1:]: |
611 | 656 | sys.argv.append('-v') |
|
0 commit comments