MCPcopy
hub / github.com/reflex-dev/reflex / test_mutable_list

Function test_mutable_list

tests/units/test_state.py:2792–2843  ·  view source on GitHub ↗

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

(mutable_state: MutableTestState)

Source from the content-addressed store, hash-verified

2790
2791
2792def 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
2846def test_mutable_dict(mutable_state: MutableTestState):

Callers

nothing calls this directly

Calls 4

assert_array_dirtyFunction · 0.85
removeMethod · 0.80
clearMethod · 0.80
reverseMethod · 0.80

Tested by

no test coverage detected