11import objectbox
22import os
3+ from os import path
34import shutil
45import pytest
5- from tests .model import TestEntity , TestEntityDatetime , TestEntityFlex
66import numpy as np
7+ from typing import *
8+ from tests .model import *
9+
710
811test_dir = 'testdata'
912
@@ -23,15 +26,13 @@ def autocleanup():
2326
2427def load_empty_test_objectbox (db_name : str = test_dir ) -> objectbox .ObjectBox :
2528 model = objectbox .Model ()
26- from objectbox .model import IdUid
2729 model .entity (TestEntity , last_property_id = IdUid (27 , 1027 ))
2830 model .last_entity_id = IdUid (2 , 2 )
2931
3032 return objectbox .Builder ().model (model ).directory (db_name ).build ()
3133
3234def load_empty_test_datetime (name : str = "" ) -> objectbox .ObjectBox :
3335 model = objectbox .Model ()
34- from objectbox .model import IdUid
3536 model .entity (TestEntityDatetime , last_property_id = IdUid (4 , 2004 ))
3637 model .last_entity_id = IdUid (2 , 2 )
3738
@@ -42,7 +43,6 @@ def load_empty_test_datetime(name: str = "") -> objectbox.ObjectBox:
4243
4344def load_empty_test_flex (name : str = "" ) -> objectbox .ObjectBox :
4445 model = objectbox .Model ()
45- from objectbox .model import IdUid
4646 model .entity (TestEntityFlex , last_property_id = IdUid (3 , 3003 ))
4747 model .last_entity_id = IdUid (3 , 3 )
4848
@@ -51,6 +51,26 @@ def load_empty_test_flex(name: str = "") -> objectbox.ObjectBox:
5151 return objectbox .Builder ().model (model ).directory (db_name ).build ()
5252
5353
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+
5474def assert_equal_prop (actual , expected , default ):
5575 assert actual == expected or (isinstance (
5676 expected , objectbox .model .Property ) and actual == default )
0 commit comments