Remove unneeded content from within `with` statements

This commit is contained in:
Adam Turner
2025-01-04 06:36:34 +00:00
parent f63784310c
commit e17ed74fe0
10 changed files with 56 additions and 52 deletions

View File

@@ -86,12 +86,12 @@ def test_custom_templates(make_app, apidoc):
# Assert that the legacy filename is discovered
with open(builddir / 'mypackage.txt', encoding='utf-8') as f:
txt = f.read()
assert 'The legacy package template was found!' in txt
assert 'The legacy package template was found!' in txt
# Assert that the new filename is preferred
with open(builddir / 'mypackage.mymodule.txt', encoding='utf-8') as f:
txt = f.read()
assert 'The Jinja module template was found!' in txt
assert 'The Jinja module template was found!' in txt
@pytest.mark.apidoc(
@@ -107,17 +107,17 @@ def test_pep_0420_enabled(make_app, apidoc):
with open(outdir / 'a.b.c.rst', encoding='utf-8') as f:
rst = f.read()
assert 'automodule:: a.b.c.d\n' in rst
assert 'automodule:: a.b.c\n' in rst
assert 'automodule:: a.b.c.d\n' in rst
assert 'automodule:: a.b.c\n' in rst
with open(outdir / 'a.b.e.rst', encoding='utf-8') as f:
rst = f.read()
assert 'automodule:: a.b.e.f\n' in rst
assert 'automodule:: a.b.e.f\n' in rst
with open(outdir / 'a.b.x.rst', encoding='utf-8') as f:
rst = f.read()
assert 'automodule:: a.b.x.y\n' in rst
assert 'automodule:: a.b.x\n' not in rst
assert 'automodule:: a.b.x.y\n' in rst
assert 'automodule:: a.b.x\n' not in rst
app = make_app('text', srcdir=outdir)
app.build()
@@ -131,15 +131,15 @@ def test_pep_0420_enabled(make_app, apidoc):
with open(builddir / 'a.b.c.txt', encoding='utf-8') as f:
txt = f.read()
assert 'a.b.c package\n' in txt
assert 'a.b.c package\n' in txt
with open(builddir / 'a.b.e.txt', encoding='utf-8') as f:
txt = f.read()
assert 'a.b.e.f module\n' in txt
assert 'a.b.e.f module\n' in txt
with open(builddir / 'a.b.x.txt', encoding='utf-8') as f:
txt = f.read()
assert 'a.b.x namespace\n' in txt
assert 'a.b.x namespace\n' in txt
@pytest.mark.apidoc(
@@ -157,15 +157,15 @@ def test_pep_0420_enabled_separate(make_app, apidoc):
with open(outdir / 'a.b.c.rst', encoding='utf-8') as f:
rst = f.read()
assert '.. toctree::\n :maxdepth: 4\n\n a.b.c.d\n' in rst
assert '.. toctree::\n :maxdepth: 4\n\n a.b.c.d\n' in rst
with open(outdir / 'a.b.e.rst', encoding='utf-8') as f:
rst = f.read()
assert '.. toctree::\n :maxdepth: 4\n\n a.b.e.f\n' in rst
assert '.. toctree::\n :maxdepth: 4\n\n a.b.e.f\n' in rst
with open(outdir / 'a.b.x.rst', encoding='utf-8') as f:
rst = f.read()
assert '.. toctree::\n :maxdepth: 4\n\n a.b.x.y\n' in rst
assert '.. toctree::\n :maxdepth: 4\n\n a.b.x.y\n' in rst
app = make_app('text', srcdir=outdir)
app.build()
@@ -181,15 +181,15 @@ def test_pep_0420_enabled_separate(make_app, apidoc):
with open(builddir / 'a.b.c.txt', encoding='utf-8') as f:
txt = f.read()
assert 'a.b.c package\n' in txt
assert 'a.b.c package\n' in txt
with open(builddir / 'a.b.e.f.txt', encoding='utf-8') as f:
txt = f.read()
assert 'a.b.e.f module\n' in txt
assert 'a.b.e.f module\n' in txt
with open(builddir / 'a.b.x.txt', encoding='utf-8') as f:
txt = f.read()
assert 'a.b.x namespace\n' in txt
assert 'a.b.x namespace\n' in txt
@pytest.mark.apidoc(coderoot='test-apidoc-pep420/a')
@@ -214,9 +214,9 @@ def test_pep_0420_disabled_top_level_verify(make_app, apidoc):
with open(outdir / 'c.rst', encoding='utf-8') as f:
rst = f.read()
assert 'c package\n' in rst
assert 'automodule:: c.d\n' in rst
assert 'automodule:: c\n' in rst
assert 'c package\n' in rst
assert 'automodule:: c.d\n' in rst
assert 'automodule:: c\n' in rst
app = make_app('text', srcdir=outdir)
app.build()
@@ -238,8 +238,8 @@ def test_trailing_underscore(make_app, apidoc):
builddir = outdir / '_build' / 'text'
with open(builddir / 'package_.txt', encoding='utf-8') as f:
rst = f.read()
assert 'package_ package\n' in rst
assert 'package_.module_ module\n' in rst
assert 'package_ package\n' in rst
assert 'package_.module_ module\n' in rst
@pytest.mark.apidoc(
@@ -349,7 +349,7 @@ def test_extension_parsed(apidoc):
with open(outdir / 'conf.py', encoding='utf-8') as f:
rst = f.read()
assert 'sphinx.ext.mathjax' in rst
assert 'sphinx.ext.mathjax' in rst
@pytest.mark.apidoc(