:type tmpdir: py._path.local.LocalPath
(tmpdir)
| 449 | |
| 450 | |
| 451 | def 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 | |
| 481 | def test_lastid_after_open(tmpdir): |
nothing calls this directly
no test coverage detected
searching dependent graphs…