Test that mutable sets are tracked correctly. Args: mutable_state: A test state.
(mutable_state)
| 2063 | |
| 2064 | |
| 2065 | def test_mutable_set(mutable_state): |
| 2066 | """Test that mutable sets are tracked correctly. |
| 2067 | |
| 2068 | Args: |
| 2069 | mutable_state: A test state. |
| 2070 | """ |
| 2071 | assert not mutable_state.dirty_vars |
| 2072 | |
| 2073 | def assert_set_dirty(): |
| 2074 | assert mutable_state.dirty_vars == {"test_set"} |
| 2075 | mutable_state._clean() |
| 2076 | assert not mutable_state.dirty_vars |
| 2077 | |
| 2078 | # Test all set operations |
| 2079 | mutable_state.test_set.add(42) |
| 2080 | assert_set_dirty() |
| 2081 | mutable_state.test_set.update([1, 2, 3]) |
| 2082 | assert_set_dirty() |
| 2083 | mutable_state.test_set.remove(42) |
| 2084 | assert_set_dirty() |
| 2085 | mutable_state.test_set.discard(3) |
| 2086 | assert_set_dirty() |
| 2087 | mutable_state.test_set.pop() |
| 2088 | assert_set_dirty() |
| 2089 | mutable_state.test_set.intersection_update([1, 2, 3]) |
| 2090 | assert_set_dirty() |
| 2091 | mutable_state.test_set.difference_update([99]) |
| 2092 | assert_set_dirty() |
| 2093 | mutable_state.test_set.symmetric_difference_update([102, 99]) |
| 2094 | assert_set_dirty() |
| 2095 | mutable_state.test_set |= {1, 2, 3} |
| 2096 | assert_set_dirty() |
| 2097 | mutable_state.test_set &= {2, 3, 4} |
| 2098 | assert_set_dirty() |
| 2099 | mutable_state.test_set -= {2} |
| 2100 | assert_set_dirty() |
| 2101 | mutable_state.test_set ^= {42} |
| 2102 | assert_set_dirty() |
| 2103 | mutable_state.test_set.clear() |
| 2104 | assert_set_dirty() |
| 2105 | |
| 2106 | |
| 2107 | def test_mutable_custom(mutable_state): |