@@ -816,9 +816,78 @@ def test_dict_setdefault_on_frozen():
816
816
with pytest .raises (Exception ):
817
817
x .a .b .setdefault ("c" , "this should raise an error" )
818
818
819
+ with pytest .raises (Exception ):
820
+ x .setdefault ("a" , "should not be set" )
821
+
819
822
820
823
def test_dict_setdefault_on_sealed ():
821
824
x = easytree .dict (sealed = True )
822
825
823
826
with pytest .raises (Exception ):
824
827
x .a .b .setdefault ("c" , "this should raise an error" )
828
+
829
+ with pytest .raises (Exception ):
830
+ x .setdefault ("a" , "should not be set" )
831
+
832
+
833
+ def test_frozen_list_append ():
834
+ l = easytree .list ([1 , 2 , 3 ], frozen = True )
835
+
836
+ with pytest .raises (Exception ):
837
+ l .append (1 )
838
+
839
+ with pytest .raises (Exception ):
840
+ l [0 ] = "changed"
841
+
842
+ l = easytree .list ([1 , 2 , 3 ], sealed = True )
843
+
844
+ with pytest .raises (Exception ):
845
+ l .append (1 )
846
+
847
+ with pytest .raises (Exception ):
848
+ l [0 ] = "changed"
849
+
850
+
851
+ def test_list_context_manager ():
852
+ l = easytree .list ()
853
+
854
+ with l as ref :
855
+ assert l == ref
856
+
857
+
858
+ def test_sealed_list_extend ():
859
+ this = easytree .list ([1 , 2 , 3 ], sealed = True )
860
+
861
+ with pytest .raises (Exception ):
862
+ this .extend ([4 , 5 , 6 ])
863
+
864
+
865
+ def test_frozen_list_cannot_reverse ():
866
+ this = easytree .list ([1 , 2 , 3 ], sealed = True )
867
+ this .reverse ()
868
+
869
+ assert this == [3 , 2 , 1 ]
870
+
871
+ this = easytree .list ([1 , 2 , 3 ], frozen = True )
872
+
873
+ with pytest .raises (Exception ):
874
+ this .reverse ()
875
+
876
+
877
+ def test_dict_update_frozen ():
878
+ d = easytree .dict (frozen = True )
879
+
880
+ with pytest .raises (Exception ):
881
+ d .update ({})
882
+
883
+
884
+ def test_dict_update_sealed ():
885
+ d = easytree .dict (sealed = True )
886
+ d .update ({})
887
+
888
+ d = easytree .dict (name = "David" , sealed = True )
889
+ d .update ({"name" : "Celine" })
890
+ assert d ["name" ] == "Celine"
891
+
892
+ with pytest .raises (Exception ):
893
+ d .update ({"age" : 22 })
0 commit comments