Custom Storage subclasses should work correctly.
()
| 251 | |
| 252 | |
| 253 | async 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 | |
| 286 | async def test_storage_boolean_false_vs_none(): |