Skip to content

Commit

Permalink
Add round-trip test via Sphinx InventoryFile
Browse files Browse the repository at this point in the history
Compare sphinx.util.inventory.InventoryFile loads between
(i) objects.inv files generated by Sphinx and
(ii) objects.inv files imported and re-exported by sphobjinv.

This is a much more fundamental round-trip test, and probably
should have been in the test suite from the beginning.

Many inventories currently failing; most appear to be because of
the validity of names containing spaces, per #181.
  • Loading branch information
bskinn committed Feb 4, 2021
1 parent 648f967 commit ca30744
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
27 changes: 19 additions & 8 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
from enum import Enum
from filecmp import cmp
from functools import partial
from io import BytesIO
from pathlib import Path

import jsonschema
import pytest
from sphinx.util.inventory import InventoryFile as IFile

import sphobjinv as soi

Expand Down Expand Up @@ -161,18 +163,27 @@ def bytes_txt(misc_info, res_path):


@pytest.fixture(scope="session")
def sphinx_load_test():
def sphinx_ifile_load():
"""Return helper function to load inventory via Sphinx InventoryFile."""

def func(path):
"""Carry out inventory load via Sphinx InventoryFile."""
return IFile.load(BytesIO(path.read_bytes()), "", osp.join)

return func


@pytest.fixture(scope="session")
def sphinx_load_test(sphinx_ifile_load):
"""Return function to perform 'live' Sphinx inventory load test."""
from sphinx.util.inventory import InventoryFile as IFile

def func(path):
"""Perform the 'live' inventory load test."""
with path.open("rb") as f:
try:
IFile.load(f, "", osp.join)
except Exception as e: # noqa: PIE786
# An exception here is a failing test, not a test error.
pytest.fail(e)
try:
sphinx_ifile_load(path)
except Exception as e: # noqa: PIE786
# An exception here is a failing test, not a test error.
pytest.fail(e)

return func

Expand Down
1 change: 1 addition & 0 deletions requirements-ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ attrs>=17.4
certifi
codecov
coverage
dictdiffer
fuzzywuzzy>=0.3
jsonschema
md-toc
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
attrs>=17.4
certifi
coverage
dictdiffer
fuzzywuzzy>=0.3
jsonschema
md-toc
Expand Down
21 changes: 21 additions & 0 deletions tests/test_api_good.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import warnings
from numbers import Number

import dictdiffer
import pytest

import sphobjinv as soi
Expand Down Expand Up @@ -502,6 +503,26 @@ def test_api_inventory_datafile_gen_and_reimport(
# Ensure sphinx likes the regenerated inventory
sphinx_load_test(scr_fpath)

@pytest.mark.testall
def test_api_inventory_matches_sphinx_ifile(
self, testall_inv_path, scratch_path, misc_info, pytestconfig, sphinx_ifile_load
):
"""Confirm no-op per Sphinx on passing through sphobjinv.Inventory."""
fname = testall_inv_path.name
scr_fpath = scratch_path / fname

# Drop most unless testall
if not pytestconfig.getoption("--testall") and fname != "objects_attrs.inv":
pytest.skip("'--testall' not specified")

original_ifile_data = sphinx_ifile_load(testall_inv_path)

inv = soi.Inventory(testall_inv_path)
soi.writebytes(scr_fpath, soi.compress(inv.data_file()))
soi_ifile_data = sphinx_ifile_load(scr_fpath)

assert list(dictdiffer.diff(soi_ifile_data, original_ifile_data)) == [], fname

def test_api_inventory_one_object_flatdict(self):
"""Confirm a flat dict inventory with one object imports ok.
Expand Down

0 comments on commit ca30744

Please sign in to comment.