88from  shiny .reactive ._core  import  ReactiveWarning 
99from  shiny ._decorators  import  * 
1010from  shiny .reactive  import  * 
11- from  shiny .types  import  MISSING 
1211from  shiny ._validation  import  SilentException , req 
1312
1413from  .mocktime  import  MockTime 
@@ -96,7 +95,7 @@ def o():
9695# ====================================================================== 
9796@pytest .mark .asyncio  
9897async  def  test_reactive_value_unset ():
99-     v  =  Value [int ](MISSING )
98+     v  =  Value [int ]()
10099
101100    with  isolate ():
102101        assert  v .is_set () is  False 
@@ -118,36 +117,60 @@ def o():
118117    await  flush ()
119118    assert  o ._exec_count  ==  2 
120119    assert  val  ==  1 
120+     with  isolate ():
121+         assert  v .is_set () is  True 
121122
122123    v .unset ()
123124    await  flush ()
124125    assert  o ._exec_count  ==  3 
125126    assert  val  ==  1 
126- 
127127    with  isolate ():
128128        assert  v .is_set () is  False 
129129        with  pytest .raises (SilentException ):
130130            v ()
131131
132-     # Check that dependency is taken when is_set() is called. 
133-     v  =  Value [int ](MISSING )
134-     val2 : Union [bool , None ] =  None 
132+ 
133+ # ====================================================================== 
134+ # reactive.Value.is_set() invalidates dependents only when set state changes 
135+ # ====================================================================== 
136+ @pytest .mark .asyncio  
137+ async  def  test_reactive_value_is_set ():
138+     v  =  Value [int ]()
139+     v_is_set : bool  =  False 
135140
136141    @Effect () 
137-     def  o2 ():
138-         nonlocal  val2 
139-         val2  =  v .is_set ()
142+     def  o ():
143+         nonlocal  v_is_set 
144+         v_is_set  =  v .is_set ()
140145
141146    await  flush ()
142-     assert  val2  is  False 
147+     assert  o ._exec_count  ==  1 
148+     assert  v_is_set  is  False 
143149
144150    v .set (1 )
145151    await  flush ()
146-     assert  val2  is  True 
152+     assert  o ._exec_count  ==  2 
153+     assert  v_is_set  is  True 
154+ 
155+     v .set (2 )
156+     await  flush ()
157+     assert  o ._exec_count  ==  2 
158+     assert  v_is_set  is  True 
147159
148160    v .unset ()
149161    await  flush ()
150-     assert  val2  is  False 
162+     assert  o ._exec_count  ==  3 
163+     assert  v_is_set  is  False 
164+ 
165+     v .unset ()
166+     await  flush ()
167+     assert  o ._exec_count  ==  3 
168+     assert  v_is_set  is  False 
169+ 
170+     v .set (1 )
171+     await  flush ()
172+     assert  o ._exec_count  ==  4 
173+     assert  v_is_set  is  True 
151174
152175
153176# ====================================================================== 
0 commit comments