|
| 1 | +import inspect |
| 2 | +import os |
| 3 | +import pytest |
| 4 | +import shutil |
| 5 | +from unittest import mock |
| 6 | + |
| 7 | +from hoverxref.translators import HoverXRefHTMLTranslatorMixin |
| 8 | + |
| 9 | +from .utils import srcdir |
| 10 | + |
| 11 | + |
| 12 | +@pytest.mark.sphinx( |
| 13 | + srcdir=srcdir, |
| 14 | + buildername='latex', |
| 15 | + confoverrides={ |
| 16 | + 'hoverxref_project': 'myproject', |
| 17 | + 'hoverxref_version': 'myversion', |
| 18 | + }, |
| 19 | +) |
| 20 | +def test_dont_override_translator_non_html_builder(app, status, warning): |
| 21 | + app.build() |
| 22 | + path = app.outdir / 'test.tex' |
| 23 | + assert path.exists() is True |
| 24 | + content = open(path).read() |
| 25 | + |
| 26 | + assert app.builder.format == 'latex' |
| 27 | + for name, klass in app.registry.translators.items(): |
| 28 | + assert not issubclass(klass, HoverXRefHTMLTranslatorMixin) |
| 29 | + |
| 30 | + |
| 31 | +@pytest.mark.sphinx( |
| 32 | + srcdir=srcdir, |
| 33 | + buildername='html', |
| 34 | + confoverrides={ |
| 35 | + 'hoverxref_project': 'myproject', |
| 36 | + 'hoverxref_version': 'myversion', |
| 37 | + }, |
| 38 | +) |
| 39 | +def test_override_translator_non_html_builder(app, status, warning): |
| 40 | + app.build() |
| 41 | + path = app.outdir / 'index.html' |
| 42 | + assert path.exists() is True |
| 43 | + content = open(path).read() |
| 44 | + |
| 45 | + assert app.builder.format == 'html' |
| 46 | + for name, klass in app.registry.translators.items(): |
| 47 | + assert issubclass(klass, HoverXRefHTMLTranslatorMixin) |
| 48 | + |
| 49 | + |
| 50 | +@pytest.mark.sphinx( |
| 51 | + srcdir=srcdir, |
| 52 | + buildername='latex', |
| 53 | + confoverrides={ |
| 54 | + 'hoverxref_project': 'myproject', |
| 55 | + 'hoverxref_version': 'myversion', |
| 56 | + 'hoverxref_auto_ref': True, |
| 57 | + }, |
| 58 | +) |
| 59 | +def test_dont_fail_non_html_builder(app, status, warning): |
| 60 | + """ |
| 61 | + Test our resolver is not used by non-HTML builder. |
| 62 | +
|
| 63 | + When running the build with ``latex`` as builder and |
| 64 | + ``hoverxref_auto_ref=True`` it should not fail with |
| 65 | +
|
| 66 | + def _get_docpath(self, builder, docname): |
| 67 | + docpath = builder.get_outfilename(docname) |
| 68 | + AttributeError: 'LaTeXBuilder' object has no attribute 'get_outfilename' |
| 69 | +
|
| 70 | + LaTeXBuilder should never use our resolver. |
| 71 | + """ |
| 72 | + |
| 73 | + with mock.patch('hoverxref.domains.HoverXRefBaseDomain._get_docpath') as _get_docpath: |
| 74 | + app.build() |
| 75 | + assert not _get_docpath.called |
| 76 | + path = app.outdir / 'test.tex' |
| 77 | + assert path.exists() is True |
| 78 | + content = open(path).read() |
| 79 | + |
| 80 | + assert app.builder.format == 'latex' |
0 commit comments