|
1 | | -from datetime import timezone |
2 | | - |
3 | | -import objectbox |
4 | | -import os |
5 | 1 | from os import path |
6 | | -import shutil |
7 | 2 | import pytest |
8 | | -import numpy as np |
9 | | -from typing import * |
| 3 | +import objectbox |
| 4 | +from objectbox.logger import logger |
| 5 | +from objectbox.store import Store |
| 6 | +from objectbox.model.sync_model import sync_model |
10 | 7 | from tests.model import * |
| 8 | +import numpy as np |
| 9 | +from datetime import timezone |
11 | 10 |
|
12 | | -test_dir = 'testdata' |
13 | | - |
14 | | - |
15 | | -def create_default_model() -> objectbox.Model: |
| 11 | +def create_default_model(): |
16 | 12 | model = objectbox.Model() |
17 | | - model.entity(TestEntity, last_property_id=IdUid(28, 1028)) |
18 | | - model.last_entity_id = IdUid(2, 2) |
19 | | - model.last_index_id = IdUid(2, 10002) |
| 13 | + model.entity(TestEntity) |
| 14 | + model.entity(TestEntityDatetime) |
| 15 | + model.entity(TestEntityFlex) |
| 16 | + model.entity(VectorEntity) |
| 17 | + sync_model(model) # Assign IDs/UIDs |
20 | 18 | return model |
21 | 19 |
|
22 | 20 |
|
23 | | -def load_empty_test_default_store(db_name: str = test_dir) -> objectbox.Store: |
24 | | - model = create_default_model() |
25 | | - return objectbox.Store(model=model, directory=db_name) |
26 | | - |
27 | | - |
28 | | -def load_empty_test_datetime_store(name: str = "") -> objectbox.Store: |
29 | | - model = objectbox.Model() |
30 | | - model.entity(TestEntityDatetime, last_property_id=IdUid(4, 2004)) |
31 | | - model.last_entity_id = IdUid(2, 2) |
32 | | - |
33 | | - db_name = test_dir if len(name) == 0 else test_dir + "/" + name |
34 | | - |
35 | | - return objectbox.Store(model=model, directory=db_name) |
36 | | - |
37 | | - |
38 | | -def load_empty_test_flex_store(name: str = "") -> objectbox.Store: |
39 | | - model = objectbox.Model() |
40 | | - model.entity(TestEntityFlex, last_property_id=IdUid(2, 3002)) |
41 | | - model.last_entity_id = IdUid(3, 3) |
42 | | - |
43 | | - db_name = test_dir if len(name) == 0 else test_dir + "/" + name |
44 | | - |
45 | | - return objectbox.Store(model=model, directory=db_name) |
46 | | - |
47 | | - |
48 | | -def create_test_store(db_name: Optional[str] = None, clear_db: bool = True) -> objectbox.Store: |
| 21 | +def create_test_store(db_path: str = "testdata", clear_db: bool = True) -> objectbox.Store: |
49 | 22 | """ Creates a Store instance with all entities. """ |
50 | 23 |
|
51 | | - db_path = test_dir if db_name is None else path.join(test_dir, db_name) |
52 | | - print(f"DB path: \"{db_path}\"") |
53 | | - |
54 | | - if clear_db and path.exists(db_path): |
55 | | - shutil.rmtree(db_path) |
56 | | - |
57 | | - model = objectbox.Model() |
58 | | - model.entity(TestEntity, last_property_id=IdUid(28, 1028)) |
59 | | - model.entity(TestEntityDatetime, last_property_id=IdUid(4, 2004)) |
60 | | - model.entity(TestEntityFlex, last_property_id=IdUid(2, 3002)) |
61 | | - model.entity(VectorEntity, last_property_id=IdUid(5, 4005)) |
62 | | - model.last_entity_id = IdUid(4, 4) |
63 | | - model.last_index_id = IdUid(5, 40003) |
| 24 | + is_inmemory = db_path.startswith("memory:") |
| 25 | + logger.info(f"DB path: {db_path} ({'in-memory' if is_inmemory else ''})") |
64 | 26 |
|
65 | | - return objectbox.Store(model=model, directory=db_path) |
| 27 | + if clear_db: |
| 28 | + Store.remove_db_files(db_path) |
| 29 | + return objectbox.Store(model=create_default_model(), directory=db_path) |
66 | 30 |
|
67 | 31 |
|
68 | 32 | def assert_equal_prop(actual, expected, default): |
|
0 commit comments