1
1
import objectbox
2
2
import os
3
+ from os import path
3
4
import shutil
4
5
import pytest
5
- from tests .model import TestEntity , TestEntityDatetime , TestEntityFlex
6
6
import numpy as np
7
+ from typing import *
8
+ from tests .model import *
9
+
7
10
8
11
test_dir = 'testdata'
9
12
@@ -23,15 +26,13 @@ def autocleanup():
23
26
24
27
def load_empty_test_objectbox (db_name : str = test_dir ) -> objectbox .ObjectBox :
25
28
model = objectbox .Model ()
26
- from objectbox .model import IdUid
27
29
model .entity (TestEntity , last_property_id = IdUid (27 , 1027 ))
28
30
model .last_entity_id = IdUid (2 , 2 )
29
31
30
32
return objectbox .Builder ().model (model ).directory (db_name ).build ()
31
33
32
34
def load_empty_test_datetime (name : str = "" ) -> objectbox .ObjectBox :
33
35
model = objectbox .Model ()
34
- from objectbox .model import IdUid
35
36
model .entity (TestEntityDatetime , last_property_id = IdUid (4 , 2004 ))
36
37
model .last_entity_id = IdUid (2 , 2 )
37
38
@@ -42,7 +43,6 @@ def load_empty_test_datetime(name: str = "") -> objectbox.ObjectBox:
42
43
43
44
def load_empty_test_flex (name : str = "" ) -> objectbox .ObjectBox :
44
45
model = objectbox .Model ()
45
- from objectbox .model import IdUid
46
46
model .entity (TestEntityFlex , last_property_id = IdUid (3 , 3003 ))
47
47
model .last_entity_id = IdUid (3 , 3 )
48
48
@@ -51,6 +51,26 @@ def load_empty_test_flex(name: str = "") -> objectbox.ObjectBox:
51
51
return objectbox .Builder ().model (model ).directory (db_name ).build ()
52
52
53
53
54
+ def create_test_objectbox (db_name : Optional [str ] = None , clear_db : bool = True ) -> objectbox .ObjectBox :
55
+ """ Creates an ObjectBox instance with all entities. """
56
+
57
+ db_path = test_dir if db_name is None else path .join (test_dir , db_name )
58
+ print (f"DB path: \" { db_path } \" " )
59
+
60
+ if clear_db and path .exists (db_path ):
61
+ shutil .rmtree (db_path )
62
+
63
+ model = objectbox .Model ()
64
+ model .entity (TestEntity , last_property_id = IdUid (27 , 1027 ))
65
+ model .entity (TestEntityDatetime , last_property_id = IdUid (4 , 2004 ))
66
+ model .entity (TestEntityFlex , last_property_id = IdUid (3 , 3003 ))
67
+ model .entity (VectorEntity , last_property_id = IdUid (3 , 4003 ))
68
+ model .last_entity_id = IdUid (4 , 4 )
69
+ model .last_index_id = IdUid (3 , 40001 )
70
+
71
+ return objectbox .Builder ().model (model ).directory (db_path ).build ()
72
+
73
+
54
74
def assert_equal_prop (actual , expected , default ):
55
75
assert actual == expected or (isinstance (
56
76
expected , objectbox .model .Property ) and actual == default )
0 commit comments