diff --git a/conftest.py b/conftest.py index fae3b7fc..77779727 100644 --- a/conftest.py +++ b/conftest.py @@ -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 @@ -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 diff --git a/requirements-ci.txt b/requirements-ci.txt index 27b23f9c..b07f0b60 100644 --- a/requirements-ci.txt +++ b/requirements-ci.txt @@ -2,6 +2,7 @@ attrs>=17.4 certifi codecov coverage +dictdiffer fuzzywuzzy>=0.3 jsonschema md-toc diff --git a/requirements-dev.txt b/requirements-dev.txt index 56ef758b..3e06912a 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,6 +1,7 @@ attrs>=17.4 certifi coverage +dictdiffer fuzzywuzzy>=0.3 jsonschema md-toc diff --git a/tests/test_api_good.py b/tests/test_api_good.py index e150dd2d..843ee147 100644 --- a/tests/test_api_good.py +++ b/tests/test_api_good.py @@ -31,6 +31,7 @@ import warnings from numbers import Number +import dictdiffer import pytest import sphobjinv as soi @@ -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.