@@ -20,3 +20,42 @@ def test_asdict() -> None:
2020 )
2121 result = attrs .asdict ()
2222 assert result == {"a" : 1 , "b" : 2 }
23+
24+
25+ def test_update_attributes_preserves_existing () -> None :
26+ """
27+ Test that `update_attributes` only updates the specified attributes
28+ and preserves existing ones.
29+ """
30+ store = zarr .storage .MemoryStore ()
31+ z = zarr .create (10 , store = store , overwrite = True )
32+ z .attrs ["a" ] = []
33+ z .attrs ["b" ] = 3
34+ assert dict (z .attrs ) == {"a" : [], "b" : 3 }
35+
36+ z .update_attributes ({"a" : [3 , 4 ], "c" : 4 })
37+ assert dict (z .attrs ) == {"a" : [3 , 4 ], "b" : 3 , "c" : 4 }
38+
39+
40+ def test_update_empty_attributes () -> None :
41+ """
42+ Ensure updating when initial attributes are empty works.
43+ """
44+ store = zarr .storage .MemoryStore ()
45+ z = zarr .create (10 , store = store , overwrite = True )
46+ assert dict (z .attrs ) == {}
47+ z .update_attributes ({"a" : [3 , 4 ], "c" : 4 })
48+ assert dict (z .attrs ) == {"a" : [3 , 4 ], "c" : 4 }
49+
50+
51+ def test_update_no_changes () -> None :
52+ """
53+ Ensure updating when no new or modified attributes does not alter existing ones.
54+ """
55+ store = zarr .storage .MemoryStore ()
56+ z = zarr .create (10 , store = store , overwrite = True )
57+ z .attrs ["a" ] = []
58+ z .attrs ["b" ] = 3
59+
60+ z .update_attributes ({})
61+ assert dict (z .attrs ) == {"a" : [], "b" : 3 }
0 commit comments