Skip to content

Instantly share code, notes, and snippets.

@pietroalbini
Created September 4, 2023 08:59
Show Gist options
  • Save pietroalbini/2d9f83925db243f4014d2ad36c3fef99 to your computer and use it in GitHub Desktop.
Save pietroalbini/2d9f83925db243f4014d2ad36c3fef99 to your computer and use it in GitHub Desktop.
py39: skipped because could not find python interpreter with spec(s): py39
py39: SKIP ⚠ in 0 seconds
.pkg: _optional_hooks> python /home/pietro/.local/pipx/venvs/tox/lib/python3.10/site-packages/pyproject_api/_backend.py True flit_core.buildapi
.pkg: get_requires_for_build_editable> python /home/pietro/.local/pipx/venvs/tox/lib/python3.10/site-packages/pyproject_api/_backend.py True flit_core.buildapi
.pkg: build_editable> python /home/pietro/.local/pipx/venvs/tox/lib/python3.10/site-packages/pyproject_api/_backend.py True flit_core.buildapi
py310: install_package> python -I -m pip install --force-reinstall --no-deps /home/pietro/r/github/sphinx-doc/sphinx/.tox/.tmp/package/48/sphinx-7.2.5-py3-none-any.whl
py310: commands[0]> python -X dev -X warn_default_encoding -m pytest --durations 25 tests/test_search.py
==================================================================================================================================== test session starts =====================================================================================================================================
platform linux -- Python 3.10.12, pytest-7.4.0, pluggy-1.3.0
cachedir: .tox/py310/.pytest_cache
libraries: Sphinx-7.2.5, docutils-0.20.1
base tmp_path: /tmp/pytest-of-pietro/pytest-14
rootdir: /home/pietro/r/github/sphinx-doc/sphinx
configfile: pyproject.toml
collected 13 items
tests/test_search.py ............F [100%]
========================================================================================================================================== FAILURES ==========================================================================================================================================
_____________________________________________________________________________________________________________________________ test_search_index_is_deterministic _____________________________________________________________________________________________________________________________
app = <SphinxTestApp buildername='html'>
@pytest.mark.sphinx(testroot='search')
def test_search_index_is_deterministic(app):
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,
# but their contents must not be sorted. We cannot sort them anyway, as
# document_idx is an int and title_anchor is a str.
def is_title_tuple_type(item):
return len(item) == 2 and isinstance(item[0], int) and isinstance(item[1], str)
def assert_is_sorted(item, path):
err_path = path if path else '<root>'
if isinstance(item, dict):
assert list(item.keys()) == sorted(item.keys()), f'{err_path} is not sorted'
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:
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.
> assert_is_sorted(index, '')
tests/test_search.py:342:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/test_search.py:332: in assert_is_sorted
assert_is_sorted(value, f'{path}.{key}')
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = ['meta keywords', '', 'heading 1'], path = '.titles'
def assert_is_sorted(item, path):
err_path = path if path else '<root>'
if isinstance(item, dict):
assert list(item.keys()) == sorted(item.keys()), f'{err_path} is not sorted'
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:
> assert item == sorted(item), f'{err_path} is not sorted'
E AssertionError: .titles is not sorted
E assert ['meta keywor..., 'heading 1'] == ['', 'heading...eta keywords']
E At index 0 diff: 'meta keywords' != ''
E Use -v to get more diff
tests/test_search.py:335: AssertionError
------------------------------------------------------------------------------------------------------------------------------------ Captured stdout call ------------------------------------------------------------------------------------------------------------------------------------
index contents:
{
"alltitles": {
"Stemmer": [
[
0,
"stemmer"
]
],
"heading 1": [
[
2,
"heading-1"
]
],
"meta keywords": [
[
0,
"meta-keywords"
]
],
"textinheading": [
[
2,
"textinheading"
]
]
},
"docnames": [
"index",
"nosearch",
"tocitem"
],
"envversion": {
"sphinx": 60,
"sphinx.domains.c": 3,
"sphinx.domains.changeset": 1,
"sphinx.domains.citation": 1,
"sphinx.domains.cpp": 9,
"sphinx.domains.index": 1,
"sphinx.domains.javascript": 3,
"sphinx.domains.math": 2,
"sphinx.domains.python": 4,
"sphinx.domains.rst": 2,
"sphinx.domains.std": 2
},
"filenames": [
"index.rst",
"nosearch.rst",
"tocitem.rst"
],
"indexentries": {},
"objects": {},
"objnames": {},
"objtypes": {},
"terms": {
"1": 0,
"bat": [
0,
2
],
"ca": 2,
"cas": [],
"chineset": [],
"chinesetest": 2,
"faq": 2,
"findthiskei": 0,
"findthisstemmedkei": 0,
"findthisstemmedkey": [],
"head": 0,
"heading": [],
"intern": 0,
"international": [],
"ipsum": 2,
"lor": [],
"lorem": 2,
"notgerman": 0,
"onlygerman": [],
"onlytoogerman": [],
"rawword": 0,
"service\u90e8\u5206": 2,
"textinhead": 0,
"textinheading": [],
"thisonetoo": 0,
"thistoo": 0,
"\u53ef\u4ee5chinesetesttwo\u67e5\u770b": 2,
"\u53ef\u4ee5\u67e5\u770b": 2,
"\u6a21\u5757\u4e2d": 2,
"\u90e8\u5206": 2
},
"titles": [
"meta keywords",
"",
"heading 1"
],
"titleterms": {
"1": 2,
"head": 2,
"heading": [],
"keyword": 0,
"meta": 0,
"stemm": [],
"stemmer": 0,
"textinhead": 2,
"textinheading": []
}
}
---------------------------------------------------------------------------------------------------------------------------------- Captured stdout teardown ----------------------------------------------------------------------------------------------------------------------------------
# testroot: root
# builder: html
# srcdir: /tmp/pytest-of-pietro/pytest-14/search
# outdir: /tmp/pytest-of-pietro/pytest-14/search/_build/html
# status:
Running Sphinx v7.2.5
loading pickled environment... done
building [mo]: all of 0 po files
writing output...
building [html]: all source files
updating environment: 0 added, 0 changed, 0 removed
reading sources...
looking for now-outdated files... none found
preparing documents... done
copying assets... copying static files... done
copying extra files... done
done
writing output... [100%] tocitem
generating indices... genindex done
writing additional pages... search done
dumping search index in English (code: en)... done
dumping object inventory... done
# warning:
==================================================================================================================================== slowest 25 durations ====================================================================================================================================
0.36s call tests/test_search.py::test_objects_are_escaped
0.22s call tests/test_search.py::test_parallel
0.14s call tests/test_search.py::test_search_index_gen_zh
0.14s call tests/test_search.py::test_nosearch
0.14s call tests/test_search.py::test_term_in_raw_directive
0.13s call tests/test_search.py::test_meta_keys_are_handled_for_language_de
0.13s call tests/test_search.py::test_meta_keys_are_handled_for_language_en
0.13s setup tests/test_search.py::test_objects_are_escaped
0.13s call tests/test_search.py::test_term_in_heading_and_section
0.13s call tests/test_search.py::test_search_index_is_deterministic
0.12s call tests/test_search.py::test_stemmer
0.12s call tests/test_search.py::test_stemmer_does_not_remove_short_words
0.02s setup tests/test_search.py::test_search_index_is_deterministic
0.02s setup tests/test_search.py::test_term_in_raw_directive
0.02s setup tests/test_search.py::test_term_in_heading_and_section
0.02s setup tests/test_search.py::test_stemmer_does_not_remove_short_words
0.02s setup tests/test_search.py::test_stemmer
0.02s setup tests/test_search.py::test_search_index_gen_zh
0.02s setup tests/test_search.py::test_parallel
0.02s setup tests/test_search.py::test_meta_keys_are_handled_for_language_de
0.01s setup tests/test_search.py::test_meta_keys_are_handled_for_language_en
0.01s setup tests/test_search.py::test_nosearch
(3 durations < 0.005s hidden. Use -vv to show these durations.)
================================================================================================================================== short test summary info ===================================================================================================================================
FAILED tests/test_search.py::test_search_index_is_deterministic - AssertionError: .titles is not sorted
================================================================================================================================ 1 failed, 12 passed in 2.14s ================================================================================================================================
py310: exit 1 (2.58 seconds) /home/pietro/r/github/sphinx-doc/sphinx> python -X dev -X warn_default_encoding -m pytest --durations 25 tests/test_search.py pid=202267
py310: FAIL ✖ in 3.21 seconds
py311: skipped because could not find python interpreter with spec(s): py311
py311: SKIP ⚠ in 0 seconds
py312: skipped because could not find python interpreter with spec(s): py312
py312: SKIP ⚠ in 0 seconds
py313: skipped because could not find python interpreter with spec(s): py313
.pkg: _exit> python /home/pietro/.local/pipx/venvs/tox/lib/python3.10/site-packages/pyproject_api/_backend.py True flit_core.buildapi
py39: SKIP (0.00 seconds)
py310: FAIL code 1 (3.21=setup[0.63]+cmd[2.58] seconds)
py311: SKIP (0.00 seconds)
py312: SKIP (0.00 seconds)
py313: SKIP (0.02 seconds)
evaluation failed :( (3.32 seconds)
py39: skipped because could not find python interpreter with spec(s): py39
py39: SKIP ⚠ in 0 seconds
.pkg: _optional_hooks> python /home/pietro/.local/pipx/venvs/tox/lib/python3.10/site-packages/pyproject_api/_backend.py True flit_core.buildapi
.pkg: get_requires_for_build_editable> python /home/pietro/.local/pipx/venvs/tox/lib/python3.10/site-packages/pyproject_api/_backend.py True flit_core.buildapi
.pkg: build_editable> python /home/pietro/.local/pipx/venvs/tox/lib/python3.10/site-packages/pyproject_api/_backend.py True flit_core.buildapi
py310: install_package> python -I -m pip install --force-reinstall --no-deps /home/pietro/r/github/sphinx-doc/sphinx/.tox/.tmp/package/37/sphinx-7.2.5-py3-none-any.whl
py310: commands[0]> python -X dev -X warn_default_encoding -m pytest --durations 25 tests/test_search.py
==================================================================================================================================================================================================================================================================================== test session starts ====================================================================================================================================================================================================================================================================================
platform linux -- Python 3.10.12, pytest-7.4.0, pluggy-1.3.0
cachedir: .tox/py310/.pytest_cache
libraries: Sphinx-7.2.5, docutils-0.20.1
base tmp_path: /tmp/pytest-of-pietro/pytest-5
rootdir: /home/pietro/r/github/sphinx-doc/sphinx
configfile: pyproject.toml
collected 13 items
tests/test_search.py ............. [100%]
=================================================================================================================================================================================================================================================================================== slowest 25 durations ====================================================================================================================================================================================================================================================================================
0.35s call tests/test_search.py::test_objects_are_escaped
0.17s call tests/test_search.py::test_search_index_gen_zh
0.16s call tests/test_search.py::test_parallel
0.13s call tests/test_search.py::test_nosearch
0.13s call tests/test_search.py::test_meta_keys_are_handled_for_language_de
0.13s call tests/test_search.py::test_meta_keys_are_handled_for_language_en
0.12s setup tests/test_search.py::test_objects_are_escaped
0.12s call tests/test_search.py::test_stemmer_does_not_remove_short_words
0.12s call tests/test_search.py::test_term_in_heading_and_section
0.12s call tests/test_search.py::test_term_in_raw_directive
0.12s call tests/test_search.py::test_search_index_is_deterministic
0.12s call tests/test_search.py::test_stemmer
0.02s setup tests/test_search.py::test_search_index_is_deterministic
0.02s setup tests/test_search.py::test_stemmer
0.02s setup tests/test_search.py::test_term_in_raw_directive
0.02s setup tests/test_search.py::test_term_in_heading_and_section
0.02s setup tests/test_search.py::test_stemmer_does_not_remove_short_words
0.01s setup tests/test_search.py::test_search_index_gen_zh
0.01s setup tests/test_search.py::test_meta_keys_are_handled_for_language_en
0.01s setup tests/test_search.py::test_meta_keys_are_handled_for_language_de
0.01s setup tests/test_search.py::test_parallel
0.01s setup tests/test_search.py::test_nosearch
(3 durations < 0.005s hidden. Use -vv to show these durations.)
==================================================================================================================================================================================================================================================================================== 13 passed in 2.00s =====================================================================================================================================================================================================================================================================================
py310: OK ✔ in 3.03 seconds
py311: skipped because could not find python interpreter with spec(s): py311
py311: SKIP ⚠ in 0 seconds
py312: skipped because could not find python interpreter with spec(s): py312
py312: SKIP ⚠ in 0 seconds
py313: skipped because could not find python interpreter with spec(s): py313
.pkg: _exit> python /home/pietro/.local/pipx/venvs/tox/lib/python3.10/site-packages/pyproject_api/_backend.py True flit_core.buildapi
py39: SKIP (0.00 seconds)
py310: OK (3.03=setup[0.59]+cmd[2.43] seconds)
py311: SKIP (0.00 seconds)
py312: SKIP (0.00 seconds)
py313: SKIP (0.01 seconds)
congratulations :) (3.14 seconds)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment