Skip to content

Commit e9fd6c4

Browse files
bors[bot]sanders41
andauthored
Merge #227
227: Refactored isinstance asserts to check specific types r=eskombro a=sanders41 Closes #225 I also updated the doc string in one case where the new tests found an issue. Co-authored-by: Paul Sanders <[email protected]>
2 parents b95f206 + 2ad9987 commit e9fd6c4

15 files changed

+58
-58
lines changed

meilisearch/index.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,8 @@ def get_distinct_attribute(self):
631631
632632
Returns
633633
-------
634-
settings: str
635-
String containing the distinct attribute of the index.
634+
settings: str | None
635+
String containing the distinct attribute of the index. If no distinct attribute None is returned.
636636
637637
Raises
638638
------

meilisearch/tests/client/test_client_stats_meilisearch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
def test_get_all_stats(client):
55
"""Tests getting all stats."""
66
response = client.get_all_stats()
7-
assert isinstance(response, object)
7+
assert isinstance(response, dict)
88
assert 'databaseSize' in response
99
assert isinstance(response['databaseSize'], int)
1010
assert 'lastUpdate' in response

meilisearch/tests/errors/test_communication_error_meilisearch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from meilisearch.errors import MeiliSearchCommunicationError
66
from meilisearch.tests import MASTER_KEY
77

8+
89
def test_meilisearch_communication_error_host():
910
client = meilisearch.Client("http://wrongurl:1234", MASTER_KEY)
1011
with pytest.raises(MeiliSearchCommunicationError):

meilisearch/tests/index/test_index_document_meilisearch.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def test_add_documents(empty_index, small_movies):
1212
"""Tests adding new documents to a clean index."""
1313
index = empty_index()
1414
response = index.add_documents(small_movies)
15-
assert isinstance(response, object)
15+
assert isinstance(response, dict)
1616
assert 'updateId' in response
1717
update = index.wait_for_pending_update(response['updateId'])
1818
assert index.get_primary_key() == 'id'
@@ -21,7 +21,7 @@ def test_add_documents(empty_index, small_movies):
2121
def test_get_document(index_with_documents):
2222
"""Tests getting one document from a populated index."""
2323
response = index_with_documents().get_document('500682')
24-
assert isinstance(response, object)
24+
assert isinstance(response, dict)
2525
assert 'title' in response
2626
assert response['title'] == 'The Highwaymen'
2727

@@ -56,7 +56,7 @@ def test_update_documents(index_with_documents, small_movies):
5656
response = index.get_documents()
5757
response[0]['title'] = 'Some title'
5858
update = index.update_documents([response[0]])
59-
assert isinstance(update, object)
59+
assert isinstance(update, dict)
6060
assert 'updateId' in update
6161
index.wait_for_pending_update(update['updateId'])
6262
response = index.get_documents()
@@ -70,7 +70,7 @@ def test_delete_document(index_with_documents):
7070
"""Tests deleting a single document."""
7171
index = index_with_documents()
7272
response = index.delete_document('500682')
73-
assert isinstance(response, object)
73+
assert isinstance(response, dict)
7474
assert 'updateId' in response
7575
index.wait_for_pending_update(response['updateId'])
7676
with pytest.raises(Exception):
@@ -81,7 +81,7 @@ def test_delete_documents(index_with_documents):
8181
to_delete = ['522681', '450465', '329996']
8282
index = index_with_documents()
8383
response = index.delete_documents(to_delete)
84-
assert isinstance(response, object)
84+
assert isinstance(response, dict)
8585
assert 'updateId' in response
8686
index.wait_for_pending_update(response['updateId'])
8787
for document in to_delete:
@@ -92,7 +92,7 @@ def test_delete_all_documents(index_with_documents):
9292
"""Tests deleting all the documents in the index."""
9393
index = index_with_documents()
9494
response = index.delete_all_documents()
95-
assert isinstance(response, object)
95+
assert isinstance(response, dict)
9696
assert 'updateId' in response
9797
index.wait_for_pending_update(response['updateId'])
9898
response = index.get_documents()

meilisearch/tests/index/test_index_search_meilisearch.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@
33
def test_basic_search(index_with_documents):
44
"""Tests search with an simple query."""
55
response = index_with_documents().search('How to Train Your Dragon')
6-
assert isinstance(response, object)
6+
assert isinstance(response, dict)
77
assert response['hits'][0]['id'] == '166428'
88

99
def test_basic_search_with_empty_params(index_with_documents):
1010
"""Tests search with a simple query and empty params."""
1111
response = index_with_documents().search('How to Train Your Dragon', {})
12-
assert isinstance(response, object)
12+
assert isinstance(response, dict)
1313
assert response['hits'][0]['id'] == '166428'
1414
assert '_formatted' not in response['hits'][0]
1515

1616
def test_basic_search_with_empty_query(index_with_documents):
1717
"""Tests search with an empty query and empty params."""
1818
response = index_with_documents().search('')
19-
assert isinstance(response, object)
19+
assert isinstance(response, dict)
2020
assert len(response['hits']) == 20
2121
assert response['query'] == ''
2222

2323
def test_basic_search_with_no_query(index_with_documents):
2424
"""Tests search with no query [None] and empty params."""
2525
response = index_with_documents().search(None, {})
26-
assert isinstance(response, object)
26+
assert isinstance(response, dict)
2727
assert len(response['hits']) == 20
2828

2929
def test_custom_search(index_with_documents):
@@ -34,7 +34,7 @@ def test_custom_search(index_with_documents):
3434
'attributesToHighlight': ['title']
3535
}
3636
)
37-
assert isinstance(response, object)
37+
assert isinstance(response, dict)
3838
assert response['hits'][0]['id'] == '166428'
3939
assert '_formatted' in response['hits'][0]
4040
assert 'dragon' in response['hits'][0]['_formatted']['title'].lower()
@@ -47,7 +47,7 @@ def test_custom_search_with_empty_query(index_with_documents):
4747
'attributesToHighlight': ['title']
4848
}
4949
)
50-
assert isinstance(response, object)
50+
assert isinstance(response, dict)
5151
assert len(response['hits']) == 20
5252
assert response['query'] == ''
5353

@@ -59,7 +59,7 @@ def test_custom_search_with_no_query(index_with_documents):
5959
'limit': 5
6060
}
6161
)
62-
assert isinstance(response, object)
62+
assert isinstance(response, dict)
6363
assert len(response['hits']) == 5
6464

6565
def test_custom_search_params_with_wildcard(index_with_documents):
@@ -73,7 +73,7 @@ def test_custom_search_params_with_wildcard(index_with_documents):
7373
'attributesToCrop': ['*'],
7474
}
7575
)
76-
assert isinstance(response, object)
76+
assert isinstance(response, dict)
7777
assert len(response['hits']) == 5
7878
assert '_formatted' in response['hits'][0]
7979
assert "title" in response['hits'][0]['_formatted']
@@ -89,7 +89,7 @@ def test_custom_search_params_with_simple_string(index_with_documents):
8989
'attributesToCrop': ['title'],
9090
}
9191
)
92-
assert isinstance(response, object)
92+
assert isinstance(response, dict)
9393
assert len(response['hits']) == 5
9494
assert '_formatted' in response['hits'][0]
9595
assert 'title' in response['hits'][0]['_formatted']
@@ -105,7 +105,7 @@ def test_custom_search_params_with_string_list(index_with_documents):
105105
'attributesToHighlight': ['title'],
106106
}
107107
)
108-
assert isinstance(response, object)
108+
assert isinstance(response, dict)
109109
assert len(response['hits']) == 5
110110
assert 'title' in response['hits'][0]
111111
assert 'overview' in response['hits'][0]
@@ -123,7 +123,7 @@ def test_custom_search_params_with_facets_distribution(index_with_documents):
123123
'facetsDistribution': ['genre']
124124
}
125125
)
126-
assert isinstance(response, object)
126+
assert isinstance(response, dict)
127127
assert len(response['hits']) == 12
128128
assert 'facetsDistribution' in response
129129
assert 'exhaustiveFacetsCount' in response
@@ -143,7 +143,7 @@ def test_custom_search_params_with_facet_filters(index_with_documents):
143143
'facetFilters': [['genre:action']]
144144
}
145145
)
146-
assert isinstance(response, object)
146+
assert isinstance(response, dict)
147147
assert len(response['hits']) == 3
148148
assert 'facetsDistribution' not in response
149149
assert 'exhaustiveFacetsCount' not in response
@@ -158,7 +158,7 @@ def test_custom_search_params_with_multiple_facet_filters(index_with_documents):
158158
'facetFilters': ['genre:action', ['genre:action', 'genre:action']]
159159
}
160160
)
161-
assert isinstance(response, object)
161+
assert isinstance(response, dict)
162162
assert len(response['hits']) == 3
163163
assert 'facetsDistribution' not in response
164164
assert 'exhaustiveFacetsCount' not in response
@@ -174,7 +174,7 @@ def test_custom_search_params_with_many_params(index_with_documents):
174174
'attributesToRetrieve': ['title', 'poster']
175175
}
176176
)
177-
assert isinstance(response, object)
177+
assert isinstance(response, dict)
178178
assert len(response['hits']) == 3
179179
assert 'facetsDistribution' not in response
180180
assert 'exhaustiveFacetsCount' not in response

meilisearch/tests/index/test_index_stats_meilisearch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
def test_get_stats(empty_index):
44
"""Tests getting stats of an index."""
55
response = empty_index().get_stats()
6-
assert isinstance(response, object)
6+
assert isinstance(response, dict)
77
assert 'numberOfDocuments' in response
88
assert response['numberOfDocuments'] == 0
99
assert 'isIndexing' in response

meilisearch/tests/index/test_index_wait_for_pending_update.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def test_wait_for_pending_update_default(index_with_documents):
1010
response = index.add_documents([{'id': 1, 'title': 'Le Petit Prince'}])
1111
assert 'updateId' in response
1212
update = index.wait_for_pending_update(response['updateId'])
13-
assert isinstance(update, object)
13+
assert isinstance(update, dict)
1414
assert 'status' in update
1515
assert update['status'] != 'enqueued'
1616

@@ -31,7 +31,7 @@ def test_wait_for_pending_update_interval_custom(index_with_documents, small_mov
3131
timeout_in_ms=6000
3232
)
3333
time_delta = datetime.now() - start_time
34-
assert isinstance(wait_update, object)
34+
assert isinstance(wait_update, dict)
3535
assert 'status' in wait_update
3636
assert wait_update['status'] != 'enqueued'
3737
assert time_delta.seconds >= 1
@@ -46,6 +46,6 @@ def test_wait_for_pending_update_interval_zero(index_with_documents, small_movie
4646
interval_in_ms=0,
4747
timeout_in_ms=6000
4848
)
49-
assert isinstance(wait_update, object)
49+
assert isinstance(wait_update, dict)
5050
assert 'status' in wait_update
5151
assert wait_update['status'] != 'enqueued'

meilisearch/tests/settings/test_settings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
def test_get_settings_default(empty_index):
1717
"""Tests getting all settings by default."""
1818
response = empty_index().get_settings()
19-
assert isinstance(response, object)
19+
assert isinstance(response, dict)
2020
for rule in DEFAULT_RANKING_RULES:
2121
assert rule in response['rankingRules']
2222
assert response['distinctAttribute'] is None
@@ -29,7 +29,7 @@ def test_update_settings(empty_index):
2929
"""Tests updating some settings."""
3030
index = empty_index()
3131
response = index.update_settings(NEW_SETTINGS)
32-
assert isinstance(response, object)
32+
assert isinstance(response, dict)
3333
assert 'updateId' in response
3434
update = index.wait_for_pending_update(response['updateId'])
3535
assert update['status'] == 'processed'
@@ -62,7 +62,7 @@ def test_reset_settings(empty_index):
6262
assert response['synonyms'] == {}
6363
# Check the reset of the settings
6464
response = index.reset_settings()
65-
assert isinstance(response, object)
65+
assert isinstance(response, dict)
6666
assert 'updateId' in response
6767
update = index.wait_for_pending_update(response['updateId'])
6868
assert update['status'] == 'processed'

meilisearch/tests/settings/test_settings_attributes_for_faceting_meilisearch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
def test_get_attributes_for_faceting(empty_index):
66
"""Tests getting the attributes for faceting."""
77
response = empty_index().get_attributes_for_faceting()
8-
assert isinstance(response, object)
8+
assert isinstance(response, list)
99
assert response == []
1010

1111
def test_update_attributes_for_faceting(empty_index):
@@ -34,9 +34,9 @@ def test_reset_attributes_for_faceting(empty_index):
3434
assert attribute in get_attributes
3535
# Check the reset of the settings
3636
response = index.reset_attributes_for_faceting()
37-
assert isinstance(response, object)
37+
assert isinstance(response, dict)
3838
assert 'updateId' in response
3939
index.wait_for_pending_update(response['updateId'])
4040
response = index.get_attributes_for_faceting()
41-
assert isinstance(response, object)
41+
assert isinstance(response, list)
4242
assert response == []

meilisearch/tests/settings/test_settings_displayed_attributes_meilisearch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def test_get_displayed_attributes(empty_index, small_movies):
77
"""Tests getting the displayed attributes before and after indexing a dataset."""
88
index = empty_index()
99
response = index.get_displayed_attributes()
10-
assert isinstance(response, object)
10+
assert isinstance(response, list)
1111
assert response == ['*']
1212
response = index.add_documents(small_movies)
1313
index.wait_for_pending_update(response['updateId'])
@@ -38,7 +38,7 @@ def test_reset_displayed_attributes(empty_index):
3838
assert attribute in get_attributes_new
3939
# Check the reset of the settings
4040
response = index.reset_displayed_attributes()
41-
assert isinstance(response, object)
41+
assert isinstance(response, dict)
4242
assert 'updateId' in response
4343
index.wait_for_pending_update(response['updateId'])
4444
get_attributes = index.get_displayed_attributes()

0 commit comments

Comments
 (0)