mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Use pathlib in the tests (#13051)
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user