-
Notifications
You must be signed in to change notification settings - Fork 238
Expand file tree
/
Copy pathtest_construct.py
More file actions
62 lines (48 loc) · 1.48 KB
/
test_construct.py
File metadata and controls
62 lines (48 loc) · 1.48 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
import pytest
from docarray import Document, DocumentArray
@pytest.mark.parametrize('da_cls', [DocumentArray])
def test_construct_docarray(da_cls):
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
da1 = da_cls(da)
assert len(da1) == 10
@pytest.mark.parametrize('da_cls', [DocumentArray])
@pytest.mark.parametrize('is_copy', [True, False])
def test_docarray_copy_singleton(da_cls, is_copy):
d = Document()
da = da_cls(d, copy=is_copy)
d.id = 'hello'
if is_copy:
assert da[0].id != 'hello'
else:
assert da[0].id == 'hello'
@pytest.mark.parametrize('da_cls', [DocumentArray])
@pytest.mark.parametrize('is_copy', [True, False])
def test_docarray_copy_da(da_cls, is_copy):
d1 = Document()
d2 = Document()
da = da_cls([d1, d2], copy=is_copy)
d1.id = 'hello'
if is_copy:
assert da[0].id != 'hello'
else:
assert da[0].id == 'hello'
@pytest.mark.parametrize('da_cls', [DocumentArray])
@pytest.mark.parametrize('is_copy', [True, False])
def test_docarray_copy_list(da_cls, is_copy):
d1 = Document()
d2 = Document()
da = da_cls([d1, d2], copy=is_copy)
d1.id = 'hello'
if is_copy:
assert da[0].id != 'hello'
else:
assert da[0].id == 'hello'