MCPcopy
hub / github.com/pydata/xarray / test_write_persistence_modes

Method test_write_persistence_modes

xarray/tests/test_backends.py:3090–3138  ·  view source on GitHub ↗
(self, group)

Source from the content-addressed store, hash-verified

3088
3089 @pytest.mark.parametrize("group", [None, "group1"])
3090 def test_write_persistence_modes(self, group) -> None:
3091 original = create_test_data()
3092
3093 # overwrite mode
3094 with self.roundtrip(
3095 original,
3096 save_kwargs={"mode": "w", "group": group},
3097 open_kwargs={"group": group},
3098 ) as actual:
3099 assert_identical(original, actual)
3100
3101 # don't overwrite mode
3102 with self.roundtrip(
3103 original,
3104 save_kwargs={"mode": "w-", "group": group},
3105 open_kwargs={"group": group},
3106 ) as actual:
3107 assert_identical(original, actual)
3108
3109 # make sure overwriting works as expected
3110 with self.create_zarr_target() as store:
3111 self.save(original, store)
3112 # should overwrite with no error
3113 self.save(original, store, mode="w", group=group)
3114 with self.open(store, group=group) as actual:
3115 assert_identical(original, actual)
3116 with pytest.raises((ValueError, FileExistsError)):
3117 self.save(original, store, mode="w-")
3118
3119 # check append mode for normal write
3120 with self.roundtrip(
3121 original,
3122 save_kwargs={"mode": "a", "group": group},
3123 open_kwargs={"group": group},
3124 ) as actual:
3125 assert_identical(original, actual)
3126
3127 # check append mode for append write
3128 ds, ds_to_append, _ = create_append_test_data()
3129 with self.create_zarr_target() as store_target:
3130 ds.to_zarr(store_target, mode="w", group=group, **self.version_kwargs)
3131 ds_to_append.to_zarr(
3132 store_target, append_dim="time", group=group, **self.version_kwargs
3133 )
3134 original = xr.concat([ds, ds_to_append], dim="time")
3135 actual = xr.open_dataset(
3136 store_target, group=group, engine="zarr", **self.version_kwargs
3137 )
3138 assert_identical(original, actual)
3139
3140 def test_compressor_encoding(self) -> None:
3141 # specify a custom compressor

Callers

nothing calls this directly

Calls 10

roundtripMethod · 0.95
create_zarr_targetMethod · 0.95
saveMethod · 0.95
openMethod · 0.95
assert_identicalFunction · 0.90
create_append_test_dataFunction · 0.90
create_test_dataFunction · 0.85
to_zarrMethod · 0.45
concatMethod · 0.45
open_datasetMethod · 0.45

Tested by

no test coverage detected