| 1 | import friendly_traceback as ft |
| 2 | |
| 3 | |
| 4 | def test_size_changed_during_iteration(): |
| 5 | squares = {1:1, 2:4, 3:9} |
| 6 | try: |
| 7 | for square in squares: |
| 8 | squares.pop(square) |
| 9 | except RuntimeError as e: |
| 10 | ft.explain_traceback(redirect="capture") |
| 11 | result = ft.get_output() |
| 12 | assert "RuntimeError" in result |
| 13 | if ft.get_lang() == "en": |
| 14 | assert "While you were iterating over the items of `squares` (a dictionary (`dict`))" in result |
| 15 | |
| 16 | numbers = {1, 2, 3} |
| 17 | try: |
| 18 | for n in numbers: |
| 19 | numbers.remove(n) |
| 20 | except RuntimeError as e: |
| 21 | message = str(e) |
| 22 | ft.explain_traceback(redirect="capture") |
| 23 | result = ft.get_output() |
| 24 | assert "RuntimeError" in result |
| 25 | if ft.get_lang() == "en": |
| 26 | assert "While you were iterating over the items of `numbers` (a `set`)" in result |
| 27 | if ft._writing_docs: |
| 28 | return result, message |