-
Notifications
You must be signed in to change notification settings - Fork 237
Expand file tree
/
Copy pathtest_construct.py
More file actions
158 lines (139 loc) · 5.16 KB
/
test_construct.py
File metadata and controls
158 lines (139 loc) · 5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import pytest
from docarray import Document
from docarray.array.memory import DocumentArrayInMemory
from docarray.array.elastic import DocumentArrayElastic, ElasticConfig
from docarray.array.opensearch import DocumentArrayOpenSearch
from docarray.array.qdrant import DocumentArrayQdrant
from docarray.array.sqlite import DocumentArraySqlite
from docarray.array.annlite import DocumentArrayAnnlite, AnnliteConfig
from docarray.array.storage.opensearch import OpenSearchConfig
from docarray.array.storage.qdrant import QdrantConfig
from docarray.array.weaviate import DocumentArrayWeaviate, WeaviateConfig
from docarray.array.elastic import DocumentArrayElastic, ElasticConfig
from docarray.array.redis import DocumentArrayRedis, RedisConfig
from docarray.array.milvus import DocumentArrayMilvus, MilvusConfig
@pytest.mark.parametrize(
'da_cls,config',
[
(DocumentArrayInMemory, None),
(DocumentArraySqlite, None),
(DocumentArrayAnnlite, AnnliteConfig(n_dim=128)),
(DocumentArrayWeaviate, WeaviateConfig(n_dim=128)),
(DocumentArrayQdrant, QdrantConfig(n_dim=128)),
(DocumentArrayElastic, ElasticConfig(n_dim=128)),
(DocumentArrayRedis, RedisConfig(n_dim=128)),
(DocumentArrayMilvus, MilvusConfig(n_dim=128)),
(DocumentArrayOpenSearch, OpenSearchConfig(n_dim=128)),
],
)
def test_construct_docarray(da_cls, config, start_storage):
if config:
da = da_cls(config=config)
assert len(da) == 0
da = da_cls(Document(), config=config)
assert len(da) == 1
da = da_cls([Document(), Document()], config=config)
assert len(da) == 2
da = da_cls((Document(), Document()), config=config)
assert len(da) == 2
da = da_cls((Document() for _ in range(10)), config=config)
assert len(da) == 10
else:
da = da_cls()
assert len(da) == 0
da = da_cls(Document())
assert len(da) == 1
da = da_cls([Document(), Document()])
assert len(da) == 2
da = da_cls((Document(), Document()))
assert len(da) == 2
da = da_cls((Document() for _ in range(10)))
assert len(da) == 10
if da_cls is DocumentArrayInMemory:
da1 = da_cls(da)
assert len(da1) == 10
@pytest.mark.parametrize(
'da_cls,config',
[
(DocumentArrayInMemory, None),
(DocumentArraySqlite, None),
(DocumentArrayAnnlite, AnnliteConfig(n_dim=128)),
(DocumentArrayWeaviate, WeaviateConfig(n_dim=128)),
(DocumentArrayQdrant, QdrantConfig(n_dim=128)),
(DocumentArrayElastic, ElasticConfig(n_dim=128)),
(DocumentArrayRedis, RedisConfig(n_dim=128)),
(DocumentArrayMilvus, MilvusConfig(n_dim=128)),
(DocumentArrayOpenSearch, OpenSearchConfig(n_dim=128)),
],
)
@pytest.mark.parametrize('is_copy', [True, False])
def test_docarray_copy_singleton(da_cls, config, is_copy, start_storage):
d = Document()
if config:
da = da_cls(d, copy=is_copy, config=config)
else:
da = da_cls(d, copy=is_copy)
d.id = 'hello'
if da_cls == DocumentArrayInMemory:
if is_copy:
assert da[0].id != 'hello'
else:
assert da[0].id == 'hello'
else:
assert da[0].id != 'hello'
@pytest.mark.parametrize(
'da_cls,config',
[
(DocumentArrayInMemory, None),
(DocumentArraySqlite, None),
(DocumentArrayAnnlite, AnnliteConfig(n_dim=128)),
(DocumentArrayWeaviate, WeaviateConfig(n_dim=128)),
(DocumentArrayQdrant, QdrantConfig(n_dim=128)),
(DocumentArrayElastic, ElasticConfig(n_dim=128)),
(DocumentArrayRedis, RedisConfig(n_dim=128)),
(DocumentArrayMilvus, MilvusConfig(n_dim=128)),
(DocumentArrayOpenSearch, OpenSearchConfig(n_dim=128)),
],
)
@pytest.mark.parametrize('is_copy', [True, False])
def test_docarray_copy_da(da_cls, config, is_copy, start_storage):
d1 = Document()
d2 = Document()
if config:
da = da_cls([d1, d2], copy=is_copy, config=config)
else:
da = da_cls([d1, d2], copy=is_copy)
d1.id = 'hello'
if da_cls == DocumentArrayInMemory:
if is_copy:
assert da[0].id != 'hello'
else:
assert da[0].id == 'hello'
else:
assert da[0] != 'hello'
@pytest.mark.parametrize(
'da_cls,config',
[
(DocumentArrayInMemory, None),
(DocumentArraySqlite, None),
(DocumentArrayAnnlite, AnnliteConfig(n_dim=1)),
(DocumentArrayQdrant, QdrantConfig(n_dim=1)),
(DocumentArrayElastic, ElasticConfig(n_dim=128)),
(DocumentArrayRedis, RedisConfig(n_dim=128)),
(DocumentArrayMilvus, MilvusConfig(n_dim=128)),
(DocumentArrayOpenSearch, OpenSearchConfig(n_dim=128)),
],
)
@pytest.mark.parametrize('is_copy', [True, False])
def test_docarray_copy_list(da_cls, config, is_copy, start_storage):
d1 = Document()
d2 = Document()
da = da_cls([d1, d2], copy=is_copy, config=config)
d1.id = 'hello'
if da_cls == DocumentArrayInMemory:
if is_copy:
assert da[0].id != 'hello'
else:
assert da[0].id == 'hello'
else:
assert da[0] != 'hello'