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

Function test_disabled_persistent_storage

tests/test_persistent_store.py:83–130  ·  view source on GitHub ↗

Persistent Storage General Testing.

(tmpdir)

Source from the content-addressed store, hash-verified

81
82
83def test_disabled_persistent_storage(tmpdir):
84 """Persistent Storage General Testing."""
85 # Create ourselves an attachment object set in Memory Mode only
86 pc = PersistentStore(
87 namespace="abc", path=str(tmpdir), mode=PersistentStoreMode.MEMORY
88 )
89 assert pc.read() is None
90 assert pc.read("mykey") is None
91 with pytest.raises(AttributeError):
92 # Invalid key specified
93 pc.read("!invalid")
94 assert pc.write("data") is False
95 assert pc.get("key") is None
96 assert pc.set("key", "value")
97 assert pc.get("key") == "value"
98
99 assert pc.set("key2", "value")
100 pc.clear("key", "key-not-previously-set")
101 assert pc.get("key2") == "value"
102 assert pc.get("key") is None
103
104 # Set it again
105 assert pc.set("key", "another-value")
106 # Clears all
107 pc.clear()
108 assert pc.get("key2") is None
109 assert pc.get("key") is None
110 # A second call to clear on an already empty cache set
111 pc.clear()
112
113 # No dirty flag is set as ther is nothing to write to disk
114 pc.set("not-persistent", "value", persistent=False)
115 del pc["not-persistent"]
116 with pytest.raises(KeyError):
117 # Can't delete it twice
118 del pc["not-persistent"]
119
120 # A Persistent key
121 pc.set("persistent", "value")
122 # Removes it and sets/clears the dirty flag
123 del pc["persistent"]
124
125 # After all of the above, nothing was done to the directory
126 assert len(os.listdir(str(tmpdir))) == 0
127
128 with pytest.raises(AttributeError):
129 # invalid persistent store specified
130 PersistentStore(namespace="abc", path=str(tmpdir), mode="garbage")
131
132
133def test_persistent_storage_init(tmpdir):

Callers

nothing calls this directly

Calls 6

readMethod · 0.95
writeMethod · 0.95
getMethod · 0.95
setMethod · 0.95
clearMethod · 0.95
PersistentStoreClass · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…