1+ import  enum 
12import  grpc 
23import  pytest 
4+ from  datetime  import  datetime 
35from  typing_extensions  import  assert_type 
46
57import  tests .types  as  test_types 
@@ -261,31 +263,63 @@ def test___set_string_enum_type___get_value_with_int_enum_default___raises_excep
261263        3.14 , 
262264        True , 
263265        b"robotext" , 
266+     ], 
267+ ) 
268+ def  test___builtin_scalar_type___set_value___gets_same_value (
269+     fake_panel_channel : grpc .Channel ,
270+     value_payload : object ,
271+ ) ->  None :
272+     """Test that set_value() and get_value() work for builtin scalar types.""" 
273+     panel  =  StreamlitPanel ("my_panel" , "path/to/script" , grpc_channel = fake_panel_channel )
274+ 
275+     value_id  =  "test_id" 
276+     panel .set_value (value_id , value_payload )
277+ 
278+     assert  panel .get_value (value_id ) ==  value_payload 
279+ 
280+ 
281+ @pytest .mark .parametrize ( 
282+     "value_payload" , 
283+     [ 
264284        test_types .MyIntFlags .VALUE1  |  test_types .MyIntFlags .VALUE4 , 
285+         test_types .MyIntableFlags .VALUE16  |  test_types .MyIntableFlags .VALUE32 , 
265286        test_types .MyIntEnum .VALUE20 , 
287+         test_types .MyIntableEnum .VALUE200 , 
266288        test_types .MyStrEnum .VALUE3 , 
289+         test_types .MyStringableEnum .VALUE2 , 
267290        test_types .MixinIntEnum .VALUE33 , 
268291        test_types .MixinStrEnum .VALUE11 , 
292+         test_types .MyMixedEnum .VALUE2 , 
269293    ], 
270294) 
271- def  test___builtin_scalar_type___set_value___gets_same_value (
295+ def  test___enum_type___set_value___gets_same_value (
272296    fake_panel_channel : grpc .Channel ,
273-     value_payload : object ,
297+     value_payload : enum . Enum ,
274298) ->  None :
275299    """Test that set_value() and get_value() work for builtin scalar types.""" 
276300    panel  =  StreamlitPanel ("my_panel" , "path/to/script" , grpc_channel = fake_panel_channel )
277301
278302    value_id  =  "test_id" 
279303    panel .set_value (value_id , value_payload )
280304
281-     assert  panel .get_value (value_id ) ==  value_payload 
305+     # without providing a default value, get_value will return the raw value, not the enum 
306+     assert  panel .get_value (value_id ) ==  value_payload .value 
282307
283308
284309@pytest .mark .parametrize ( 
285310    "value_payload" , 
286311    [ 
287-         test_types .MyEnum .VALUE300 , 
288-         test_types .MyFlags .VALUE8  |  test_types .MyFlags .VALUE16 , 
312+         datetime .now (), 
313+         lambda  x : x  +  1 , 
314+         [1 , "string" ], 
315+         ["string" , []], 
316+         (42 , "hello" , 3.14 , b"bytes" ), 
317+         set ([1 , "mixed" , True ]), 
318+         (i  for  i  in  range (5 )), 
319+         { 
320+             "key1" : [1 , 2 , 3 ], 
321+             "key2" : {"nested" : True , "values" : [4.5 , 6.7 ]}, 
322+         }, 
289323    ], 
290324) 
291325def  test___unsupported_type___set_value___raises (
@@ -368,6 +402,22 @@ def test___set_int_enum_value___get_value___returns_int_enum(
368402    assert  retrieved_value .name  ==  enum_value .name 
369403
370404
405+ def  test___set_intable_enum_value___get_value___returns_enum (
406+     fake_panel_channel : grpc .Channel ,
407+ ) ->  None :
408+     panel  =  StreamlitPanel ("my_panel" , "path/to/script" , grpc_channel = fake_panel_channel )
409+     value_id  =  "test_id" 
410+     enum_value  =  test_types .MyIntableEnum .VALUE200 
411+     panel .set_value (value_id , enum_value )
412+ 
413+     retrieved_value  =  panel .get_value (value_id , test_types .MyIntableEnum .VALUE100 )
414+ 
415+     assert_type (retrieved_value , test_types .MyIntableEnum )
416+     assert  retrieved_value  is  test_types .MyIntableEnum .VALUE200 
417+     assert  retrieved_value .value  ==  enum_value .value 
418+     assert  retrieved_value .name  ==  enum_value .name 
419+ 
420+ 
371421def  test___set_string_enum_value___get_value___returns_string_enum (
372422    fake_panel_channel : grpc .Channel ,
373423) ->  None :
@@ -384,6 +434,38 @@ def test___set_string_enum_value___get_value___returns_string_enum(
384434    assert  retrieved_value .name  ==  enum_value .name 
385435
386436
437+ def  test___set_stringable_enum_value___get_value___returns_enum (
438+     fake_panel_channel : grpc .Channel ,
439+ ) ->  None :
440+     panel  =  StreamlitPanel ("my_panel" , "path/to/script" , grpc_channel = fake_panel_channel )
441+     value_id  =  "test_id" 
442+     enum_value  =  test_types .MyStringableEnum .VALUE3 
443+     panel .set_value (value_id , enum_value )
444+ 
445+     retrieved_value  =  panel .get_value (value_id , test_types .MyStringableEnum .VALUE1 )
446+ 
447+     assert_type (retrieved_value , test_types .MyStringableEnum )
448+     assert  retrieved_value  is  test_types .MyStringableEnum .VALUE3 
449+     assert  retrieved_value .value  ==  enum_value .value 
450+     assert  retrieved_value .name  ==  enum_value .name 
451+ 
452+ 
453+ def  test___set_mixed_enum_value___get_value___returns_enum (
454+     fake_panel_channel : grpc .Channel ,
455+ ) ->  None :
456+     panel  =  StreamlitPanel ("my_panel" , "path/to/script" , grpc_channel = fake_panel_channel )
457+     value_id  =  "test_id" 
458+     enum_value  =  test_types .MyMixedEnum .VALUE2 
459+     panel .set_value (value_id , enum_value )
460+ 
461+     retrieved_value  =  panel .get_value (value_id , test_types .MyMixedEnum .VALUE1 )
462+ 
463+     assert_type (retrieved_value , test_types .MyMixedEnum )
464+     assert  retrieved_value  is  test_types .MyMixedEnum .VALUE2 
465+     assert  retrieved_value .value  ==  enum_value .value 
466+     assert  retrieved_value .name  ==  enum_value .name 
467+ 
468+ 
387469def  test___set_int_flags_value___get_value___returns_int_flags (
388470    fake_panel_channel : grpc .Channel ,
389471) ->  None :
@@ -399,6 +481,22 @@ def test___set_int_flags_value___get_value___returns_int_flags(
399481    assert  retrieved_value .value  ==  flags_value .value 
400482
401483
484+ def  test___set_intable_flags_value___get_value___returns_flags (
485+     fake_panel_channel : grpc .Channel ,
486+ ) ->  None :
487+     panel  =  StreamlitPanel ("my_panel" , "path/to/script" , grpc_channel = fake_panel_channel )
488+     value_id  =  "test_id" 
489+     flags_value  =  test_types .MyIntableFlags .VALUE16  |  test_types .MyIntableFlags .VALUE32 
490+     panel .set_value (value_id , flags_value )
491+ 
492+     retrieved_value  =  panel .get_value (value_id , test_types .MyIntableFlags .VALUE8 )
493+ 
494+     assert_type (retrieved_value , test_types .MyIntableFlags )
495+     assert  retrieved_value  is  test_types .MyIntableFlags .VALUE16  |  test_types .MyIntableFlags .VALUE32 
496+     assert  retrieved_value .value  ==  flags_value .value 
497+     assert  retrieved_value .name  ==  flags_value .name 
498+ 
499+ 
402500def  test___panel___panel_is_running_and_in_memory (
403501    fake_panel_channel : grpc .Channel ,
404502) ->  None :
0 commit comments