Tim Peters | a814db5 | 2001-05-14 07:05:58 +0000 | [diff] [blame^] | 1 | from test_support import verify |
| 2 | import pprint |
| 3 | |
| 4 | # Verify that .isrecursive() and .isreadable() work. |
| 5 | |
| 6 | a = range(100) |
| 7 | b = range(200) |
| 8 | a[-12] = b |
| 9 | |
| 10 | for safe in 2, 2.0, 2j, "abc", [3], (2,2), {3: 3}, u"yaddayadda", a, b: |
| 11 | verify(pprint.isrecursive(safe) == 0, "expected isrecursive == 0") |
| 12 | verify(pprint.isreadable(safe) == 1, "expected isreadable == 1") |
| 13 | |
| 14 | # Tie a knot. |
| 15 | b[67] = a |
| 16 | # Messy dict. |
| 17 | d = {} |
| 18 | d[0] = d[1] = d[2] = d |
| 19 | |
| 20 | for icky in a, b, d, (d, d): |
| 21 | verify(pprint.isrecursive(icky) == 1, "expected isrecursive == 1") |
| 22 | verify(pprint.isreadable(icky) == 0, "expected isreadable == 0") |
| 23 | |
| 24 | # Break the cycles. |
| 25 | d.clear() |
| 26 | del a[:] |
| 27 | del b[:] |
| 28 | |
| 29 | for safe in a, b, d, (d, d): |
| 30 | verify(pprint.isrecursive(safe) == 0, "expected isrecursive == 0") |
| 31 | verify(pprint.isreadable(safe) == 1, "expected isreadable == 1") |
| 32 | |
| 33 | # Not recursive but not readable anyway. |
| 34 | for unreadable in type(3), pprint, pprint.isrecursive: |
| 35 | verify(pprint.isrecursive(unreadable) == 0, "expected isrecursive == 0") |
| 36 | verify(pprint.isreadable(unreadable) ==0, "expected isreadable == 0") |