Use pathlib in the tests (#13051)

This commit is contained in:
Adam Turner
2024-10-25 22:41:08 +01:00
committed by GitHub
parent 63a4175b53
commit 71c0fcfbc5
17 changed files with 59 additions and 65 deletions

View File

@@ -1,6 +1,5 @@
"""Test the sphinx.apidoc module."""
import os.path
from collections import namedtuple
from pathlib import Path
@@ -732,7 +731,7 @@ def test_no_duplicates(rootdir, tmp_path):
apidoc_main(['-o', str(outdir), '-T', str(package), '--implicit-namespaces'])
# Ensure the module has been documented
assert os.path.isfile(outdir / 'fish_licence.rst')
assert (outdir / 'fish_licence.rst').is_file()
# Ensure the submodule only appears once
text = (outdir / 'fish_licence.rst').read_text(encoding='utf-8')

View File

@@ -2,7 +2,9 @@
import platform
import sys
from collections.abc import Iterator
from contextlib import contextmanager
from pathlib import Path
import pytest
@@ -19,7 +21,7 @@ IS_PYPY = platform.python_implementation() == 'PyPy'
@contextmanager
def overwrite_file(path, content):
def overwrite_file(path: Path, content: str) -> Iterator[None]:
current_content = path.read_bytes() if path.exists() else None
try:
path.write_text(content, encoding='utf-8')

View File

@@ -1,9 +1,9 @@
"""Test sphinx.ext.inheritance_diagram extension."""
import os
import re
import sys
import zlib
from pathlib import Path
import pytest
@@ -26,7 +26,7 @@ def test_inheritance_diagram(app):
def new_run(self):
result = orig_run(self)
node = result[0]
source = os.path.basename(node.document.current_source).replace('.rst', '')
source = Path(node.document.current_source).stem
graphs[source] = node['graph']
return result