Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
  • Loading branch information
pietroalbini and AA-Turner committed Sep 14, 2023
1 parent 6412bd5 commit eaee141
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Features added
Bugs fixed
----------

* #11622: Fix ordering inside searchindex.js not being deterministic.
* #11622: Ensure that the order of keys in ``searchindex.js` is deterministic.
Patch by Pietro Albini.

Release 7.2.5 (released Aug 30, 2023)
=====================================
Expand Down
9 changes: 5 additions & 4 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,14 @@ def test_parallel(app):

@pytest.mark.sphinx(testroot='search')
def test_search_index_is_deterministic(app):
LISTS_NOT_TO_SORT = [
lists_not_to_sort = {
# Each element of .titles is related to the element of .docnames in the same position.
# The ordering is deterministic because .docnames is sorted.
'.titles',
# Each element of .filenames is related to the element of .docnames in the same position.
# The ordering is deterministic because .docnames is sorted.
'.filenames',
]
}

# In the search index, titles inside .alltitles are stored as a tuple of
# (document_idx, title_anchor). Tuples are represented as lists in JSON,
Expand All @@ -331,12 +331,13 @@ def assert_is_sorted(item, path):
for key, value in item.items():
assert_is_sorted(value, f'{path}.{key}')
elif isinstance(item, list):
if not is_title_tuple_type(item) and path not in LISTS_NOT_TO_SORT:
if not is_title_tuple_type(item) and path not in lists_not_to_sort:
assert item == sorted(item), f'{err_path} is not sorted'
for i, child in enumerate(item):
assert_is_sorted(child, f'{path}[{i}]')

app.builder.build_all()
index = load_searchindex(app.outdir / 'searchindex.js')
print(f'index contents:\n{json.dumps(index, indent=2)}') # Pretty print the index.
# Pretty print the index. Only shown by pytest on failure.
print(f'searchindex.js contents:\n\n{json.dumps(index, indent=2)}')
assert_is_sorted(index, '')

0 comments on commit eaee141

Please sign in to comment.