Test that mutable lists are tracked correctly. Args: mutable_state: A test state.
(mutable_state: MutableTestState)
| 2790 | |
| 2791 | |
| 2792 | def test_mutable_list(mutable_state: MutableTestState): |
| 2793 | """Test that mutable lists are tracked correctly. |
| 2794 | |
| 2795 | Args: |
| 2796 | mutable_state: A test state. |
| 2797 | """ |
| 2798 | assert not mutable_state.dirty_vars |
| 2799 | |
| 2800 | def assert_array_dirty(): |
| 2801 | assert mutable_state.dirty_vars == {"array"} |
| 2802 | mutable_state._clean() |
| 2803 | assert not mutable_state.dirty_vars |
| 2804 | |
| 2805 | # Test all list operations |
| 2806 | mutable_state.array.append(42) |
| 2807 | assert_array_dirty() |
| 2808 | mutable_state.array.extend([1, 2, 3]) |
| 2809 | assert_array_dirty() |
| 2810 | mutable_state.array.insert(0, 0) |
| 2811 | assert_array_dirty() |
| 2812 | mutable_state.array.pop() |
| 2813 | assert_array_dirty() |
| 2814 | mutable_state.array.remove(42) |
| 2815 | assert_array_dirty() |
| 2816 | mutable_state.array.clear() |
| 2817 | assert_array_dirty() |
| 2818 | mutable_state.array += [1, 2, 3] |
| 2819 | assert_array_dirty() |
| 2820 | mutable_state.array.reverse() |
| 2821 | assert_array_dirty() |
| 2822 | mutable_state.array.sort() # pyright: ignore[reportCallIssue] |
| 2823 | assert_array_dirty() |
| 2824 | mutable_state.array[0] = 666 |
| 2825 | assert_array_dirty() |
| 2826 | del mutable_state.array[0] |
| 2827 | assert_array_dirty() |
| 2828 | |
| 2829 | # Test nested list operations |
| 2830 | mutable_state.array[0] = [1, 2, 3] |
| 2831 | assert_array_dirty() |
| 2832 | mutable_state.array[0].append(4) |
| 2833 | assert_array_dirty() |
| 2834 | assert isinstance(mutable_state.array[0], MutableProxy) |
| 2835 | |
| 2836 | # Test proxy returned from __iter__ |
| 2837 | mutable_state.array = [{}] |
| 2838 | assert_array_dirty() |
| 2839 | assert isinstance(mutable_state.array[0], MutableProxy) |
| 2840 | for item in mutable_state.array: |
| 2841 | assert isinstance(item, MutableProxy) |
| 2842 | item["foo"] = "bar" # pyright: ignore[reportArgumentType, reportCallIssue] |
| 2843 | assert_array_dirty() |
| 2844 | |
| 2845 | |
| 2846 | def test_mutable_dict(mutable_state: MutableTestState): |
nothing calls this directly
no test coverage detected