Test that mutable sets are tracked correctly. Args: mutable_state: A test state.
(mutable_state: MutableTestState)
| 2919 | |
| 2920 | |
| 2921 | def test_mutable_set(mutable_state: MutableTestState): |
| 2922 | """Test that mutable sets are tracked correctly. |
| 2923 | |
| 2924 | Args: |
| 2925 | mutable_state: A test state. |
| 2926 | """ |
| 2927 | assert not mutable_state.dirty_vars |
| 2928 | |
| 2929 | def assert_set_dirty(): |
| 2930 | assert mutable_state.dirty_vars == {"test_set"} |
| 2931 | mutable_state._clean() |
| 2932 | assert not mutable_state.dirty_vars |
| 2933 | |
| 2934 | # Test all set operations |
| 2935 | mutable_state.test_set.add(42) |
| 2936 | assert_set_dirty() |
| 2937 | mutable_state.test_set.update([1, 2, 3]) |
| 2938 | assert_set_dirty() |
| 2939 | mutable_state.test_set.remove(42) |
| 2940 | assert_set_dirty() |
| 2941 | mutable_state.test_set.discard(3) |
| 2942 | assert_set_dirty() |
| 2943 | mutable_state.test_set.pop() |
| 2944 | assert_set_dirty() |
| 2945 | mutable_state.test_set.intersection_update([1, 2, 3]) |
| 2946 | assert_set_dirty() |
| 2947 | mutable_state.test_set.difference_update([99]) |
| 2948 | assert_set_dirty() |
| 2949 | mutable_state.test_set.symmetric_difference_update([102, 99]) |
| 2950 | assert_set_dirty() |
| 2951 | mutable_state.test_set |= {1, 2, 3} |
| 2952 | assert_set_dirty() |
| 2953 | mutable_state.test_set &= {2, 3, 4} |
| 2954 | assert_set_dirty() |
| 2955 | mutable_state.test_set -= {2} |
| 2956 | assert_set_dirty() |
| 2957 | mutable_state.test_set ^= {42} |
| 2958 | assert_set_dirty() |
| 2959 | mutable_state.test_set.clear() |
| 2960 | assert_set_dirty() |
| 2961 | |
| 2962 | |
| 2963 | def test_mutable_custom(mutable_state: MutableTestState): |
nothing calls this directly
no test coverage detected