Skip to content

Commit b9a4f2c

Browse files
committed
fix tests
1 parent cbf7e97 commit b9a4f2c

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

tests/unit/test_layer.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,18 @@ def test_add_route(self, openai_encoder):
157157

158158
# Initially, the routes list should be empty
159159
assert route_layer.routes == []
160+
160161
# Add route1 and check
161162
route_layer.add(route=route1)
162163
assert route_layer.routes == [route1]
163-
# TODO add length check
164+
assert route_layer.index is not None
165+
# Use the describe method to get the number of vectors
166+
assert route_layer.index.describe()["vectors"] == 2
167+
164168
# Add route2 and check
165169
route_layer.add(route=route2)
166170
assert route_layer.routes == [route1, route2]
167-
# TODO add length check
171+
assert route_layer.index.describe()["vectors"] == 4
168172

169173
def test_list_route_names(self, openai_encoder, routes):
170174
route_layer = RouteLayer(encoder=openai_encoder, routes=routes)
@@ -202,7 +206,7 @@ def test_add_multiple_routes(self, openai_encoder, routes):
202206
route_layer = RouteLayer(encoder=openai_encoder)
203207
route_layer._add_routes(routes=routes)
204208
assert route_layer.index is not None
205-
# TODO add length check
209+
assert route_layer.index.describe()["vectors"] == 5
206210

207211
def test_query_and_classification(self, openai_encoder, routes):
208212
route_layer = RouteLayer(encoder=openai_encoder, routes=routes)
@@ -211,7 +215,8 @@ def test_query_and_classification(self, openai_encoder, routes):
211215

212216
def test_query_with_no_index(self, openai_encoder):
213217
route_layer = RouteLayer(encoder=openai_encoder)
214-
assert route_layer(text="Anything").name is None
218+
with pytest.raises(ValueError):
219+
assert route_layer(text="Anything").name is None
215220

216221
def test_query_with_vector(self, openai_encoder, routes):
217222
route_layer = RouteLayer(encoder=openai_encoder, routes=routes)
@@ -296,7 +301,7 @@ def test_config(self, openai_encoder, routes):
296301
assert layer_config.routes == routes
297302
# now load from config and confirm it's the same
298303
route_layer_from_config = RouteLayer.from_config(layer_config)
299-
assert route_layer_from_config.index == route_layer.index
304+
assert (route_layer_from_config.index.index == route_layer.index.index).all()
300305
assert route_layer_from_config._get_route_names() == route_layer._get_route_names()
301306
assert route_layer_from_config.score_threshold == route_layer.score_threshold
302307

0 commit comments

Comments
 (0)