MCPcopy
hub / github.com/caronc/apprise / test_persistent_storage_disk_prune

Function test_persistent_storage_disk_prune

tests/test_persistent_store.py:1377–1588  ·  view source on GitHub ↗

General testing of a Persistent Store prune calls.

(tmpdir)

Source from the content-addressed store, hash-verified

1375 sys.platform == "win32", reason="Unreliable results to be determined"
1376)
1377def test_persistent_storage_disk_prune(tmpdir):
1378 """General testing of a Persistent Store prune calls."""
1379
1380 # Persistent Storage Initialization
1381 pc = PersistentStore(
1382 path=str(tmpdir), namespace="t01", mode=PersistentStoreMode.FLUSH
1383 )
1384 # Store some data
1385 assert pc.write(b"data-t01") is True
1386 assert pc.set("key-t01", "value")
1387
1388 pc = PersistentStore(
1389 path=str(tmpdir), namespace="t02", mode=PersistentStoreMode.FLUSH
1390 )
1391 # Store some data
1392 assert pc.write(b"data-t02") is True
1393 assert pc.set("key-t02", "value")
1394
1395 # purne anything older then 30s
1396 results = PersistentStore.disk_prune(path=str(tmpdir), expires=30)
1397 # Nothing is older then 30s right now
1398 assert isinstance(results, dict)
1399 assert "t01" in results
1400 assert "t02" in results
1401 assert len(results["t01"]) == 0
1402 assert len(results["t02"]) == 0
1403
1404 pc = PersistentStore(
1405 path=str(tmpdir), namespace="t01", mode=PersistentStoreMode.FLUSH
1406 )
1407
1408 # Nothing is pruned
1409 assert pc.get("key-t01") == "value"
1410 assert pc.read() == b"data-t01"
1411
1412 # An expiry of zero gets everything
1413 # Note: This test randomly fails in Microsoft Windows for unknown reasons
1414 # When this is determined, this test can be opened back up
1415 results = PersistentStore.disk_prune(path=str(tmpdir), expires=0)
1416 # We match everything now
1417 assert isinstance(results, dict)
1418 assert "t01" in results
1419 assert "t02" in results
1420 assert len(results["t01"]) == 2
1421 assert len(results["t02"]) == 2
1422
1423 # Content is still not removed however because no action was put in place
1424 pc = PersistentStore(
1425 path=str(tmpdir), namespace="t02", mode=PersistentStoreMode.FLUSH
1426 )
1427 # Nothing is pruned
1428 assert pc.get("key-t02") == "value"
1429 assert pc.read() == b"data-t02"
1430 pc = PersistentStore(
1431 path=str(tmpdir), namespace="t01", mode=PersistentStoreMode.FLUSH
1432 )
1433 # Nothing is pruned
1434 assert pc.get("key-t01") == "value"

Callers

nothing calls this directly

Calls 7

writeMethod · 0.95
setMethod · 0.95
getMethod · 0.95
readMethod · 0.95
PersistentStoreClass · 0.90
disk_pruneMethod · 0.80
disk_scanMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…