MCPcopy Index your code
hub / github.com/pyscript/pyscript / test_custom_storage_class

Function test_custom_storage_class

core/tests/python/tests/test_storage.py:253–283  ·  view source on GitHub ↗

Custom Storage subclasses should work correctly.

()

Source from the content-addressed store, hash-verified

251
252
253async def test_custom_storage_class():
254 """
255 Custom Storage subclasses should work correctly.
256 """
257 calls = []
258
259 class TrackingStorage(Storage):
260 def __setitem__(self, key, value):
261 calls.append(("set", key, value))
262 super().__setitem__(key, value)
263
264 def __delitem__(self, key):
265 calls.append(("del", key))
266 super().__delitem__(key)
267
268 custom_store = await storage("custom_test", storage_class=TrackingStorage)
269 custom_store.clear()
270 calls.clear()
271
272 # Test setitem tracking.
273 custom_store["test"] = 123
274 assert ("set", "test", 123) in calls
275 assert custom_store["test"] == 123
276
277 # Test delitem tracking.
278 del custom_store["test"]
279 assert ("del", "test") in calls
280
281 # Clean up.
282 custom_store.clear()
283 await custom_store.sync()
284
285
286async def test_storage_boolean_false_vs_none():

Callers

nothing calls this directly

Calls 3

storageFunction · 0.90
syncMethod · 0.80
clearMethod · 0.45

Tested by

no test coverage detected