Skip to content

Commit 568502e

Browse files
committed
Use pytest's tmp_path fixture for Sphinx tests
Thanks @webknjaz
1 parent b4a09fe commit 568502e

1 file changed

Lines changed: 34 additions & 38 deletions

File tree

tests/test_slots.py

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -778,54 +778,50 @@ def documented(self):
778778
return True
779779

780780

781-
def test_sphinx_autodocuments_cached_property():
781+
def test_sphinx_autodocuments_cached_property(tmp_path):
782782
"""
783783
Sphinx can generate autodocs for cached properties in slots classes
784784
"""
785785
here = Path(__file__).parent
786-
with TemporaryDirectory() as td:
787-
tmp_path = Path(td)
788-
rst = here.joinpath("explicit-autoproperty-cached.rst")
789-
index = tmp_path.joinpath("index.rst")
790-
with rst.open("r") as inf, index.open("w") as outf:
791-
for line in inf:
792-
outf.write(line)
793-
outdir = tmp_path.joinpath("docs")
794-
outdir.mkdir()
795-
app = Sphinx(
796-
tmp_path, here.parent.joinpath("docs"), outdir, tmp_path, "text"
797-
)
798-
app.build(force_all=True)
799-
with (
800-
outdir.joinpath("index.txt").open("r") as written,
801-
here.joinpath("index.txt").open("r") as good,
802-
):
803-
assert written.read() == good.read()
786+
rst = here.joinpath("explicit-autoproperty-cached.rst")
787+
index = tmp_path.joinpath("index.rst")
788+
with rst.open("r") as inf, index.open("w") as outf:
789+
for line in inf:
790+
outf.write(line)
791+
outdir = tmp_path.joinpath("docs")
792+
outdir.mkdir()
793+
app = Sphinx(
794+
tmp_path, here.parent.joinpath("docs"), outdir, tmp_path, "text"
795+
)
796+
app.build(force_all=True)
797+
with (
798+
outdir.joinpath("index.txt").open("r") as written,
799+
here.joinpath("index.txt").open("r") as good,
800+
):
801+
assert written.read() == good.read()
804802

805803

806-
def test_sphinx_automembers_cached_property():
804+
def test_sphinx_automembers_cached_property(tmp_path):
807805
"""
808806
Sphinx can find cached properties in the :members: of slots classes
809807
"""
810808
here = Path(__file__).parent
811-
with TemporaryDirectory() as td:
812-
tmp_path = Path(td)
813-
rst = here.joinpath("members-cached-property.rst")
814-
index = tmp_path.joinpath("index.rst")
815-
with rst.open("r") as inf, index.open("w") as outf:
816-
for line in inf:
817-
outf.write(line)
818-
outdir = tmp_path.joinpath("docs")
819-
outdir.mkdir()
820-
app = Sphinx(
821-
tmp_path, here.parent.joinpath("docs"), outdir, tmp_path, "text"
822-
)
823-
app.build(force_all=True)
824-
with (
825-
outdir.joinpath("index.txt").open("r") as written,
826-
here.joinpath("index.txt").open("r") as good,
827-
):
828-
assert written.read() == good.read()
809+
rst = here.joinpath("members-cached-property.rst")
810+
index = tmp_path.joinpath("index.rst")
811+
with rst.open("r") as inf, index.open("w") as outf:
812+
for line in inf:
813+
outf.write(line)
814+
outdir = tmp_path.joinpath("docs")
815+
outdir.mkdir()
816+
app = Sphinx(
817+
tmp_path, here.parent.joinpath("docs"), outdir, tmp_path, "text"
818+
)
819+
app.build(force_all=True)
820+
with (
821+
outdir.joinpath("index.txt").open("r") as written,
822+
here.joinpath("index.txt").open("r") as good,
823+
):
824+
assert written.read() == good.read()
829825

830826

831827
def test_slots_cached_property_allows_call():

0 commit comments

Comments
 (0)