@@ -258,6 +258,17 @@ def test_basic_interface(self):
258
258
md .setlist ("foo" , [1 , 2 ])
259
259
assert md .getlist ("foo" ) == [1 , 2 ]
260
260
261
+ def test_or (self ) -> None :
262
+ a = self .storage_class ({"x" : 1 })
263
+ b = a | {"y" : 2 }
264
+ assert isinstance (b , self .storage_class )
265
+ assert "x" in b and "y" in b
266
+
267
+ def test_ior (self ) -> None :
268
+ a = self .storage_class ({"x" : 1 })
269
+ a |= {"y" : 2 }
270
+ assert "x" in a and "y" in a
271
+
261
272
262
273
class _ImmutableDictTests :
263
274
storage_class : type [dict ]
@@ -305,6 +316,17 @@ def test_dict_is_hashable(self):
305
316
assert immutable in x
306
317
assert immutable2 in x
307
318
319
+ def test_or (self ) -> None :
320
+ a = self .storage_class ({"x" : 1 })
321
+ b = a | {"y" : 2 }
322
+ assert "x" in b and "y" in b
323
+
324
+ def test_ior (self ) -> None :
325
+ a = self .storage_class ({"x" : 1 })
326
+
327
+ with pytest .raises (TypeError ):
328
+ a |= {"y" : 2 }
329
+
308
330
309
331
class TestImmutableTypeConversionDict (_ImmutableDictTests ):
310
332
storage_class = ds .ImmutableTypeConversionDict
@@ -799,6 +821,17 @@ def test_equality(self):
799
821
800
822
assert h1 == h2
801
823
824
+ def test_or (self ) -> None :
825
+ a = ds .Headers ({"x" : 1 })
826
+ b = a | {"y" : 2 }
827
+ assert isinstance (b , ds .Headers )
828
+ assert "x" in b and "y" in b
829
+
830
+ def test_ior (self ) -> None :
831
+ a = ds .Headers ({"x" : 1 })
832
+ a |= {"y" : 2 }
833
+ assert "x" in a and "y" in a
834
+
802
835
803
836
class TestEnvironHeaders :
804
837
storage_class = ds .EnvironHeaders
@@ -840,6 +873,18 @@ def test_return_type_is_str(self):
840
873
assert headers ["Foo" ] == "\xe2 \x9c \x93 "
841
874
assert next (iter (headers )) == ("Foo" , "\xe2 \x9c \x93 " )
842
875
876
+ def test_or (self ) -> None :
877
+ headers = ds .EnvironHeaders ({"x" : "1" })
878
+
879
+ with pytest .raises (TypeError ):
880
+ headers | {"y" : "2" }
881
+
882
+ def test_ior (self ) -> None :
883
+ headers = ds .EnvironHeaders ({})
884
+
885
+ with pytest .raises (TypeError ):
886
+ headers |= {"y" : "2" }
887
+
843
888
844
889
class TestHeaderSet :
845
890
storage_class = ds .HeaderSet
@@ -927,7 +972,7 @@ def test_callback_dict_writes(self):
927
972
assert_calls , func = make_call_asserter ()
928
973
initial = {"a" : "foo" , "b" : "bar" }
929
974
dct = self .storage_class (initial = initial , on_update = func )
930
- with assert_calls (8 , "callback not triggered by write method" ):
975
+ with assert_calls (9 , "callback not triggered by write method" ):
931
976
# always-write methods
932
977
dct ["z" ] = 123
933
978
dct ["z" ] = 123 # must trigger again
@@ -937,6 +982,7 @@ def test_callback_dict_writes(self):
937
982
dct .popitem ()
938
983
dct .update ([])
939
984
dct .clear ()
985
+ dct |= {}
940
986
with assert_calls (0 , "callback triggered by failed del" ):
941
987
pytest .raises (KeyError , lambda : dct .__delitem__ ("x" ))
942
988
with assert_calls (0 , "callback triggered by failed pop" ):
0 commit comments