Skip to content

Commit d8f5f96

Browse files
loryrutaivahnenkoAnna
authored andcommitted
Call ob.close() at the end of every test #6
1 parent 3a3d34b commit d8f5f96

File tree

7 files changed

+24
-8
lines changed

7 files changed

+24
-8
lines changed

example/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ class Task:
1313
def get_objectbox_model():
1414
m = Model()
1515
m.entity(Task, last_property_id=IdUid(4, 1004))
16-
m.last_entity_id = IdUid(1, 1)
16+
m.last_entity_id = IdUid(2, 2)
1717
return m

objectbox/objectbox.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,19 @@ class ObjectBox:
2121
def __init__(self, c_store: OBX_store_p):
2222
self._c_store = c_store
2323

24+
self._closed = False
25+
2426
def __del__(self):
25-
obx_store_close(self._c_store)
27+
self.close()
2628

2729
def read_tx(self):
2830
return objectbox.transaction.read(self)
2931

3032
def write_tx(self):
3133
return objectbox.transaction.write(self)
34+
35+
def close(self):
36+
if not self._closed:
37+
obx_store_close(self._c_store)
38+
self._closed = True
39+

tests/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def load_empty_test_datetime(name: str = "") -> objectbox.ObjectBox:
3636
model = objectbox.Model()
3737
from objectbox.model import IdUid
3838
model.entity(TestEntityDatetime, last_property_id=IdUid(3, 1003))
39-
model.last_entity_id = IdUid(1, 1)
39+
model.last_entity_id = IdUid(2, 2)
4040

4141
db_name = test_dir if len(name) == 0 else test_dir + "/" + name
4242

tests/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class TestEntity:
3030
def __init__(self, string: str = ""):
3131
self.str = string
3232

33-
@Entity(id=1, uid=1)
33+
@Entity(id=2, uid=2)
3434
class TestEntityDatetime:
3535
id = Id(id=1, uid=1001)
3636
date = Property(datetime, type=PropertyType.date, id=2, uid=1002)

tests/test_basics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import objectbox
2-
from tests.common import autocleanup, load_empty_test_objectbox, assert_equal
2+
from tests.common import load_empty_test_objectbox
33

44

55
def test_version():

tests/test_box.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import objectbox
33
from tests.model import TestEntity, TestEntityDatetime
44
from tests.common import (
5-
autocleanup,
65
load_empty_test_objectbox,
76
load_empty_test_datetime,
87
assert_equal,
@@ -84,6 +83,8 @@ def test_box_basics():
8483
with pytest.raises(objectbox.NotFoundException):
8584
box.get(1)
8685

86+
ob.close()
87+
8788

8889
def test_box_bulk():
8990
ob = load_empty_test_objectbox()
@@ -117,6 +118,8 @@ def test_box_bulk():
117118
assert removed == 4
118119
assert box.count() == 0
119120

121+
ob.close()
122+
120123

121124
def test_datetime():
122125
ob = load_empty_test_datetime()
@@ -170,6 +173,8 @@ def test_datetime():
170173
with pytest.raises(objectbox.NotFoundException):
171174
box.get(1)
172175

176+
ob.close()
177+
173178

174179
def test_box_bulk_datetime():
175180
ob = load_empty_test_datetime()
@@ -196,3 +201,5 @@ def test_box_bulk_datetime():
196201
removed = box.remove_all()
197202
assert removed == 4
198203
assert box.count() == 0
204+
205+
ob.close()

tests/test_transactions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import pytest
21
import objectbox
32
from tests.model import TestEntity
4-
from tests.common import autocleanup, load_empty_test_objectbox, assert_equal
3+
from tests.common import load_empty_test_objectbox
54

65

76
def test_transactions():
@@ -39,3 +38,5 @@ def test_transactions():
3938
assert 0
4039
except Exception as err:
4140
assert "Cannot start a write transaction inside a read only transaction" in str(err)
41+
finally:
42+
ob.close()

0 commit comments

Comments
 (0)