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

Function test_unique_ids

tests/test_tinydb.py:451–478  ·  view source on GitHub ↗

:type tmpdir: py._path.local.LocalPath

(tmpdir)

Source from the content-addressed store, hash-verified

449
450
451def test_unique_ids(tmpdir):
452 """
453 :type tmpdir: py._path.local.LocalPath
454 """
455 path = str(tmpdir.join('db.json'))
456
457 # Verify ids are unique when reopening the DB and inserting
458 with TinyDB(path) as _db:
459 _db.insert({'x': 1})
460
461 with TinyDB(path) as _db:
462 _db.insert({'x': 1})
463
464 with TinyDB(path) as _db:
465 data = _db.all()
466
467 assert data[0].doc_id != data[1].doc_id
468
469 # Verify ids stay unique when inserting/removing
470 with TinyDB(path) as _db:
471 _db.drop_tables()
472 _db.insert_multiple({'x': i} for i in range(5))
473 _db.remove(where('x') == 2)
474
475 assert len(_db) == 4
476
477 ids = [e.doc_id for e in _db.all()]
478 assert len(ids) == len(set(ids))
479
480
481def test_lastid_after_open(tmpdir):

Callers

nothing calls this directly

Calls 8

TinyDBClass · 0.90
whereFunction · 0.90
setFunction · 0.85
insertMethod · 0.80
drop_tablesMethod · 0.80
insert_multipleMethod · 0.80
removeMethod · 0.80
allMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…