-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathtest_index_stats_meilisearch.py
More file actions
57 lines (45 loc) · 2.18 KB
/
Copy pathtest_index_stats_meilisearch.py
File metadata and controls
57 lines (45 loc) · 2.18 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
import re
from meilisearch.models.index import IndexStats, SizeFormat
HUMAN_SIZE_PATTERN = re.compile(r"^\d+(\.\d+)?\s+(B|KiB|MiB|GiB|TiB)$")
def test_get_stats(empty_index):
"""Tests getting stats of an index."""
response = empty_index().get_stats()
assert isinstance(response, IndexStats)
assert response.number_of_documents == 0
def test_get_stats_default(index_with_documents):
"""Tests getting stats of a non-empty index."""
response = index_with_documents().get_stats()
assert isinstance(response, IndexStats)
assert response.number_of_documents == 31
assert hasattr(response.field_distribution, "genre")
assert response.field_distribution.genre == 11
def test_get_stats_with_internal_database_sizes(index_with_documents):
"""Tests getting stats with showInternalDatabaseSizes parameter."""
response = index_with_documents().get_stats(show_internal_database_sizes=True)
assert isinstance(response, IndexStats)
assert response.internal_database_sizes is not None
assert isinstance(response.internal_database_sizes, dict)
assert len(response.internal_database_sizes) > 0
assert all(isinstance(value, int) for value in response.internal_database_sizes.values())
def test_get_stats_with_size_format(index_with_documents):
"""Tests getting stats with sizeFormat parameter."""
response = index_with_documents().get_stats(
show_internal_database_sizes=True,
size_format=SizeFormat.HUMAN,
)
assert isinstance(response, IndexStats)
assert response.internal_database_sizes is not None
assert all(
isinstance(value, str) and HUMAN_SIZE_PATTERN.match(value)
for value in response.internal_database_sizes.values()
)
def test_get_stats_with_all_params(index_with_documents):
"""Tests getting stats with both query parameters."""
response = index_with_documents().get_stats(
show_internal_database_sizes=True,
size_format="human",
)
assert isinstance(response, IndexStats)
assert response.number_of_documents == 31
assert response.internal_database_sizes is not None
assert all(isinstance(value, str) for value in response.internal_database_sizes.values())