mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Use pathlib in `sphinx.project`
This commit is contained in:
@@ -10,6 +10,7 @@ import time
|
||||
import wsgiref.handlers
|
||||
from base64 import b64encode
|
||||
from http.server import BaseHTTPRequestHandler
|
||||
from pathlib import Path
|
||||
from queue import Queue
|
||||
from typing import TYPE_CHECKING
|
||||
from unittest import mock
|
||||
@@ -1061,7 +1062,7 @@ def test_connection_contention(get_adapter, app, capsys):
|
||||
wqueue: Queue[CheckRequest] = Queue()
|
||||
rqueue: Queue[CheckResult] = Queue()
|
||||
for _ in range(link_count):
|
||||
wqueue.put(CheckRequest(0, Hyperlink(f"http://{address}", "test", "test.rst", 1)))
|
||||
wqueue.put(CheckRequest(0, Hyperlink(f"http://{address}", "test", Path("test.rst"), 1)))
|
||||
|
||||
begin = time.time()
|
||||
checked: list[CheckResult] = []
|
||||
|
||||
@@ -14,7 +14,7 @@ def _doctree_for_test(builder, docname: str) -> nodes.document:
|
||||
builder.env.prepare_settings(docname)
|
||||
publisher = create_publisher(builder.app, 'restructuredtext')
|
||||
with sphinx_domains(builder.env):
|
||||
publisher.set_source(source_path=builder.env.doc2path(docname))
|
||||
publisher.set_source(source_path=str(builder.env.doc2path(docname)))
|
||||
publisher.publish()
|
||||
return publisher.document
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
"""Tests project module."""
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -64,15 +65,15 @@ def test_project_doc2path(app):
|
||||
project.discover()
|
||||
|
||||
# absolute path
|
||||
assert project.doc2path('index', absolute=True) == str(app.srcdir / 'index.rst')
|
||||
assert project.doc2path('index', absolute=True) == app.srcdir / 'index.rst'
|
||||
|
||||
# relative path
|
||||
assert project.doc2path('index', absolute=False) == 'index.rst'
|
||||
assert project.doc2path('index', absolute=False) == Path('index.rst')
|
||||
|
||||
# first source_suffix is used for missing file
|
||||
assert project.doc2path('foo', absolute=False) == 'foo.rst'
|
||||
assert project.doc2path('foo', absolute=False) == Path('foo.rst')
|
||||
|
||||
# matched source_suffix is used if exists
|
||||
(app.srcdir / 'bar.txt').touch()
|
||||
project.discover()
|
||||
assert project.doc2path('bar', absolute=False) == 'bar.txt'
|
||||
assert project.doc2path('bar', absolute=False) == Path('bar.txt')
|
||||
|
||||
Reference in New Issue
Block a user