GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: refactor hnswlib test subindex (#1732) · docarray/docarray@24c00cc

This repository was archived by the owner on Sep 9, 2026. It is now read-only.

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • tests/index/hnswlib
    • test_subindex.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎tests/index/hnswlib/test_subindex.py‎

Copy file name to clipboardExpand all lines: tests/index/hnswlib/test_subindex.py
+28-19Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,7 @@ class MyDoc(BaseDoc):
2727

2828

2929
@pytest.fixture(scope='session')
30-
def index():
31-
index = HnswDocumentIndex[MyDoc](work_dir='./tmp')
32-
return index
33-
34-
35-
def test_subindex_init(index):
36-
assert isinstance(index._subindices['docs'], HnswDocumentIndex)
37-
assert isinstance(index._subindices['list_docs'], HnswDocumentIndex)
38-
assert isinstance(
39-
index._subindices['list_docs']._subindices['docs'], HnswDocumentIndex
40-
)
41-
42-
43-
def test_subindex_index(index):
30+
def index_docs():
4431
my_docs = [
4532
MyDoc(
4633
id=f'{i}',
@@ -82,15 +69,31 @@ def test_subindex_index(index):
8269
)
8370
for i in range(5)
8471
]
72+
return my_docs
73+
74+
75+
def test_subindex_init(tmpdir, index_docs):
76+
index = HnswDocumentIndex[MyDoc](work_dir=str(tmpdir))
77+
index.index(index_docs)
78+
assert isinstance(index._subindices['docs'], HnswDocumentIndex)
79+
assert isinstance(index._subindices['list_docs'], HnswDocumentIndex)
80+
assert isinstance(
81+
index._subindices['list_docs']._subindices['docs'], HnswDocumentIndex
82+
)
83+
8584

86-
index.index(my_docs)
85+
def test_subindex_index(tmpdir, index_docs):
86+
index = HnswDocumentIndex[MyDoc](work_dir=str(tmpdir))
87+
index.index(index_docs)
8788
assert index.num_docs() == 5
8889
assert index._subindices['docs'].num_docs() == 25
8990
assert index._subindices['list_docs'].num_docs() == 25
9091
assert index._subindices['list_docs']._subindices['docs'].num_docs() == 125
9192

9293

93-
def test_subindex_get(index):
94+
def test_subindex_get(tmpdir, index_docs):
95+
index = HnswDocumentIndex[MyDoc](work_dir=str(tmpdir))
96+
index.index(index_docs)
9497
doc = index['1']
9598
assert type(doc) == MyDoc
9699
assert doc.id == '1'
@@ -116,7 +119,9 @@ def test_subindex_get(index):
116119
assert np.allclose(doc.my_tens, np.ones(30) * 2)
117120

118121

119-
def test_find_subindex(index):
122+
def test_find_subindex(tmpdir, index_docs):
123+
index = HnswDocumentIndex[MyDoc](work_dir=str(tmpdir))
124+
index.index(index_docs)
120125
# root level
121126
query = np.ones((30,))
122127
with pytest.raises(ValueError):
@@ -148,15 +153,19 @@ def test_find_subindex(index):
148153
assert root_doc.id == f'{doc.id.split("-")[2]}'
149154

150155

151-
def test_subindex_del(index):
156+
def test_subindex_del(tmpdir, index_docs):
157+
index = HnswDocumentIndex[MyDoc](work_dir=str(tmpdir))
158+
index.index(index_docs)
152159
del index['0']
153160
assert index.num_docs() == 4
154161
assert index._subindices['docs'].num_docs() == 20
155162
assert index._subindices['list_docs'].num_docs() == 20
156163
assert index._subindices['list_docs']._subindices['docs'].num_docs() == 100
157164

158165

159-
def test_subindex_contain(index):
166+
def test_subindex_contain(tmpdir, index_docs):
167+
index = HnswDocumentIndex[MyDoc](work_dir=str(tmpdir))
168+
index.index(index_docs)
160169
# Checks for individual simple_docs within list_docs
161170
for i in range(4):
162171
doc = index[f'{i + 1}']

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.