Skip to content

Commit f3ca65e

Browse files
committed
Tests: check in-memory store #20
1 parent 54505d1 commit f3ca65e

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

tests/common.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,14 @@ def autocleanup():
2121
remove_test_dir()
2222

2323

24-
def load_empty_test_objectbox(name: str = "") -> objectbox.ObjectBox:
24+
def load_empty_test_objectbox(db_name: str = test_dir) -> objectbox.ObjectBox:
2525
model = objectbox.Model()
2626
from objectbox.model import IdUid
2727
model.entity(TestEntity, last_property_id=IdUid(27, 1027))
2828
model.last_entity_id = IdUid(2, 2)
2929

30-
db_name = test_dir if len(name) == 0 else test_dir + "/" + name
31-
3230
return objectbox.Builder().model(model).directory(db_name).build()
3331

34-
3532
def load_empty_test_datetime(name: str = "") -> objectbox.ObjectBox:
3633
model = objectbox.Model()
3734
from objectbox.model import IdUid

tests/test_inmemory.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import objectbox
2+
from tests.common import load_empty_test_objectbox
3+
from tests.model import TestEntity
4+
import os.path
5+
import shutil
6+
7+
def test_inmemory():
8+
# Expect path for persistent store
9+
db_name = "testdata_persistent"
10+
ob = load_empty_test_objectbox(db_name)
11+
box = objectbox.Box(ob, TestEntity)
12+
object = TestEntity()
13+
id = box.put(object)
14+
assert id == 1
15+
assert id == object.id
16+
assert os.path.exists(db_name)
17+
del box
18+
ob.close()
19+
shutil.rmtree(db_name)
20+
21+
# Expect no path for in-memory store
22+
db_name = "memory:testdata"
23+
ob = load_empty_test_objectbox(db_name)
24+
box = objectbox.Box(ob, TestEntity)
25+
object = TestEntity()
26+
id = box.put(object)
27+
assert id == 1
28+
assert id == object.id
29+
assert not os.path.exists(db_name)

0 commit comments

Comments
 (0)