Skip to content

Commit e05aa2e

Browse files
committed
Merge branch '33-fix-another-store-opened-and-ci' into 'dev'
Resolve "Fix "Cannot open store: another store is still open using the same path" + fix CI" #33 Closes #33 See merge request objectbox/objectbox-python!21
2 parents 8341076 + 8bfffa5 commit e05aa2e

File tree

9 files changed

+36
-30
lines changed

9 files changed

+36
-30
lines changed

objectbox/c.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,9 @@ def c_array_pointer(py_list: Union[List[Any], np.ndarray], c_type):
440440
# obx_err (OBX_store* store);
441441
obx_store_close = c_fn_rc('obx_store_close', [OBX_store_p])
442442

443+
# obx_err obx_remove_db_files(const const* directory);
444+
obx_remove_db_files = c_fn_rc('obx_remove_db_files', [ctypes.c_char_p]) # TODO provide a python wrapper
445+
443446
# OBX_txn* (OBX_store* store);
444447
obx_txn_write = c_fn('obx_txn_write', OBX_txn_p, [OBX_store_p])
445448

objectbox/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def find_ids(self) -> List[int]:
4646
c_id_array_p = obx_query_find_ids(self._c_query)
4747
try:
4848
c_id_array: OBX_id_array = c_id_array_p.contents
49-
ids = ctypes.cast(c_id_array.ids, ctypes.POINTER(ctypes.c_ulong * c_id_array.count))
49+
ids = ctypes.cast(c_id_array.ids, ctypes.POINTER(obx_id * c_id_array.count))
5050
return list(ids.contents)
5151
finally:
5252
obx_id_array_free(c_id_array_p)

tests/common.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,9 @@
77
from typing import *
88
from tests.model import *
99

10-
1110
test_dir = 'testdata'
1211

1312

14-
def remove_test_dir():
15-
if os.path.exists(test_dir):
16-
shutil.rmtree(test_dir)
17-
18-
19-
# cleanup before and after each testcase
20-
@pytest.fixture(autouse=True)
21-
def autocleanup():
22-
remove_test_dir()
23-
yield # run the test function
24-
remove_test_dir()
25-
26-
2713
def load_empty_test_objectbox(db_name: str = test_dir) -> objectbox.ObjectBox:
2814
model = objectbox.Model()
2915
model.entity(TestEntity, last_property_id=IdUid(27, 1027))
@@ -32,6 +18,7 @@ def load_empty_test_objectbox(db_name: str = test_dir) -> objectbox.ObjectBox:
3218

3319
return objectbox.Builder().model(model).directory(db_name).build()
3420

21+
3522
def load_empty_test_datetime(name: str = "") -> objectbox.ObjectBox:
3623
model = objectbox.Model()
3724
model.entity(TestEntityDatetime, last_property_id=IdUid(4, 2004))
@@ -76,15 +63,18 @@ def assert_equal_prop(actual, expected, default):
7663
assert actual == expected or (isinstance(
7764
expected, objectbox.model.Property) and actual == default)
7865

66+
7967
def assert_equal_prop_vector(actual, expected, default):
8068
assert (actual == np.array(expected)).all() or (isinstance(
8169
expected, objectbox.model.Property) and actual == default)
8270

71+
8372
# compare approx values
8473
def assert_equal_prop_approx(actual, expected, default):
8574
assert pytest.approx(actual) == expected or (isinstance(
8675
expected, objectbox.model.Property) and actual == default)
8776

77+
8878
def assert_equal(actual: TestEntity, expected: TestEntity):
8979
"""Check that two TestEntity objects have the same property data"""
9080
assert actual.id == expected.id

tests/conftest.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import pytest
2+
from objectbox.logger import logger
3+
from common import *
4+
5+
6+
# Fixtures in this file are used by all files in the same directory:
7+
# https://docs.pytest.org/en/7.1.x/reference/fixtures.html#conftest-py-sharing-fixtures-across-multiple-files
8+
9+
10+
def _clear_test_db():
11+
obx_remove_db_files(c_str(test_dir))
12+
13+
14+
@pytest.fixture(autouse=True)
15+
def cleanup_db():
16+
""" Fixture to ensure tests starts fresh and the DB is cleaned up on success/failure. """
17+
_clear_test_db()
18+
try:
19+
yield # Run the test code
20+
finally:
21+
_clear_test_db()

tests/test_box.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import pytest
22
import objectbox
33
from tests.model import TestEntity, TestEntityDatetime, TestEntityFlex
4-
from tests.common import (
5-
autocleanup,
6-
load_empty_test_objectbox,
7-
load_empty_test_datetime,
8-
load_empty_test_flex,
9-
assert_equal,
10-
)
4+
from tests.common import *
115
import numpy as np
126
from datetime import datetime
137
import time

tests/test_index.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
from objectbox.model.properties import IndexType
44
import pytest
55
from tests.model import TestEntity
6-
from tests.common import (
7-
autocleanup,
8-
load_empty_test_objectbox,
9-
)
6+
from tests.common import *
107

118

129
# TODO tests disabled because Python indices API changed, now they actually interact with the C API

tests/test_inmemory.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
import os.path
55
import shutil
66

7+
78
def test_inmemory():
89
# Expect path for persistent store
910
db_name = "testdata_persistent"
10-
ob = load_empty_test_objectbox(db_name)
11+
ob = load_empty_test_objectbox(db_name)
1112
box = objectbox.Box(ob, TestEntity)
1213
object = TestEntity()
1314
id = box.put(object)
@@ -20,7 +21,7 @@ def test_inmemory():
2021

2122
# Expect no path for in-memory store
2223
db_name = "memory:testdata"
23-
ob = load_empty_test_objectbox(db_name)
24+
ob = load_empty_test_objectbox(db_name)
2425
box = objectbox.Box(ob, TestEntity)
2526
object = TestEntity()
2627
id = box.put(object)

tests/test_query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from objectbox.c import *
55
from objectbox.query import *
66
import pytest
7-
from tests.common import (load_empty_test_objectbox, create_test_objectbox, autocleanup)
7+
from tests.common import *
88
from tests.model import *
99

1010

tests/test_transactions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import objectbox
22
from tests.model import TestEntity
3-
from tests.common import autocleanup, load_empty_test_objectbox
3+
from tests.common import *
44

55

66
def test_transactions():

0 commit comments

Comments
 (0)