MCPcopy
hub / github.com/msiemens/tinydb / test_read_once

Function test_read_once

tests/test_storages.py:158–192  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

156
157
158def test_read_once():
159 count = 0
160
161 # noinspection PyAbstractClass
162 class MyStorage(Storage):
163 def __init__(self):
164 self.memory = None
165
166 def read(self):
167 nonlocal count
168 count += 1
169
170 return self.memory
171
172 def write(self, data):
173 self.memory = data
174
175 with TinyDB(storage=MyStorage) as db:
176 assert count == 0
177
178 db.table(db.default_table_name)
179
180 assert count == 0
181
182 db.all()
183
184 assert count == 1
185
186 db.insert({'foo': 'bar'})
187
188 assert count == 3 # One for getting the next ID, one for the insert
189
190 db.all()
191
192 assert count == 4
193
194
195def test_custom_with_exception():

Callers

nothing calls this directly

Calls 4

TinyDBClass · 0.90
tableMethod · 0.80
insertMethod · 0.80
allMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…