MCPcopy Create free account
hub / github.com/dot-agent/nextpy / test_mutable_list

Function test_mutable_list

tests/test_state.py:1935–1986  ·  view source on GitHub ↗

Test that mutable lists are tracked correctly. Args: mutable_state: A test state.

(mutable_state)

Source from the content-addressed store, hash-verified

1933
1934
1935def test_mutable_list(mutable_state):
1936 """Test that mutable lists are tracked correctly.
1937
1938 Args:
1939 mutable_state: A test state.
1940 """
1941 assert not mutable_state.dirty_vars
1942
1943 def assert_array_dirty():
1944 assert mutable_state.dirty_vars == {"array"}
1945 mutable_state._clean()
1946 assert not mutable_state.dirty_vars
1947
1948 # Test all list operations
1949 mutable_state.array.append(42)
1950 assert_array_dirty()
1951 mutable_state.array.extend([1, 2, 3])
1952 assert_array_dirty()
1953 mutable_state.array.insert(0, 0)
1954 assert_array_dirty()
1955 mutable_state.array.pop()
1956 assert_array_dirty()
1957 mutable_state.array.remove(42)
1958 assert_array_dirty()
1959 mutable_state.array.clear()
1960 assert_array_dirty()
1961 mutable_state.array += [1, 2, 3]
1962 assert_array_dirty()
1963 mutable_state.array.reverse()
1964 assert_array_dirty()
1965 mutable_state.array.sort()
1966 assert_array_dirty()
1967 mutable_state.array[0] = 666
1968 assert_array_dirty()
1969 del mutable_state.array[0]
1970 assert_array_dirty()
1971
1972 # Test nested list operations
1973 mutable_state.array[0] = [1, 2, 3]
1974 assert_array_dirty()
1975 mutable_state.array[0].append(4)
1976 assert_array_dirty()
1977 assert isinstance(mutable_state.array[0], MutableProxy)
1978
1979 # Test proxy returned from __iter__
1980 mutable_state.array = [{}]
1981 assert_array_dirty()
1982 assert isinstance(mutable_state.array[0], MutableProxy)
1983 for item in mutable_state.array:
1984 assert isinstance(item, MutableProxy)
1985 item["foo"] = "bar"
1986 assert_array_dirty()
1987
1988
1989def test_mutable_dict(mutable_state):

Callers

nothing calls this directly

Calls 7

assert_array_dirtyFunction · 0.85
extendMethod · 0.80
removeMethod · 0.80
reverseMethod · 0.80
appendMethod · 0.45
popMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected