(it, i=0)
| 87 | def pickletest(self, protocol, it, stop=4, take=1, compare=None): |
| 88 | """Test that an iterator is the same after pickling, also when part-consumed""" |
| 89 | def expand(it, i=0): |
| 90 | # Recursively expand iterables, within sensible bounds |
| 91 | if i > 10: |
| 92 | raise RuntimeError("infinite recursion encountered") |
| 93 | if isinstance(it, str): |
| 94 | return it |
| 95 | try: |
| 96 | l = list(islice(it, stop)) |
| 97 | except TypeError: |
| 98 | return it # can't expand it |
| 99 | return [expand(e, i+1) for e in l] |
| 100 | |
| 101 | # Test the initial copy against the original |
| 102 | dump = pickle.dumps(it, protocol) |
no test coverage detected