|
1 | | -import os |
2 | | -import shutil |
3 | 1 | import pytest |
4 | 2 | import objectbox |
5 | 3 | from tests.model import TestEntity |
6 | | - |
7 | | -db_name = 'testdata' |
8 | | - |
9 | | - |
10 | | -def remove_test_db(): |
11 | | - if os.path.exists(db_name): |
12 | | - shutil.rmtree(db_name) |
13 | | - |
14 | | -# cleanup before and after each testcase |
15 | | -@pytest.fixture(autouse=True) |
16 | | -def run_around_tests(): |
17 | | - remove_test_db() |
18 | | - yield # run the test function |
19 | | - remove_test_db() |
| 4 | +from tests.common import load_empty_test_objectbox, assert_equal |
20 | 5 |
|
21 | 6 |
|
22 | 7 | def test_version(): |
23 | 8 | info = objectbox.version_info() |
24 | 9 | assert len(info) > 10 |
25 | 10 |
|
26 | 11 |
|
27 | | -def load_empty_test_objectbox() -> objectbox.ObjectBox: |
28 | | - remove_test_db() |
29 | | - |
30 | | - model = objectbox.Model() |
31 | | - from objectbox.model import IdUid |
32 | | - model.entity(TestEntity, last_property_id=IdUid(6, 1006)) |
33 | | - model.last_entity_id = IdUid(1, 1) |
34 | | - |
35 | | - return objectbox.Builder().model(model).directory(db_name).build() |
36 | | - |
37 | | - |
38 | 12 | def test_open(): |
39 | 13 | load_empty_test_objectbox() |
40 | 14 |
|
41 | 15 |
|
42 | | -def assert_equal(actual, expected): |
43 | | - """Check that two TestEntity objects have the same property data""" |
44 | | - assert actual.id == expected.id |
45 | | - assert isinstance(expected.bool, objectbox.model.Property) or actual.bool == expected.bool |
46 | | - assert isinstance(expected.int, objectbox.model.Property) or actual.int == expected.int |
47 | | - assert isinstance(expected.str, objectbox.model.Property) or actual.str == expected.str |
48 | | - assert isinstance(expected.float, objectbox.model.Property) or actual.float == expected.float |
49 | | - assert isinstance(expected.bytes, objectbox.model.Property) or actual.bytes == expected.bytes |
50 | | - |
51 | | - |
52 | 16 | def test_box_basics(): |
53 | 17 | ob = load_empty_test_objectbox() |
54 | 18 | box = objectbox.Box(ob, TestEntity) |
|
0 commit comments