nucypher/tests/test_db.py

31 lines
491 B
Python
Raw Normal View History

2017-09-05 22:43:16 +00:00
from nkms.db import DB
2017-09-05 23:02:25 +00:00
import pytest
2017-09-05 22:43:16 +00:00
def test_db():
db = DB()
db[b'x'] = b'y'
assert db[b'x'] == b'y'
db.close()
db2 = DB()
2017-09-05 23:02:25 +00:00
assert b'x' in db2
2017-09-05 22:43:16 +00:00
assert db2[b'x'] == b'y'
2017-09-05 23:02:25 +00:00
del db2[b'x']
2017-09-05 22:43:16 +00:00
db2.close()
2017-09-05 23:02:25 +00:00
db = DB()
with pytest.raises(KeyError):
db[b'x']
assert b'x' not in db
db.close()
2017-09-05 23:02:25 +00:00
2017-09-05 22:43:16 +00:00
assert db.path == db2.path
2017-09-05 23:41:54 +00:00
def test_store_dict():
db = DB()
2017-09-05 23:53:18 +00:00
db[b'x'] = {b'a': 1, b'b': 2}
assert db[b'x'][b'a'] == 1
2017-09-05 23:41:54 +00:00
db.close()