Files
psf--black/tests/test_docs.py
T
wehub-resource-sync d0aab9212a
test release tool / test-release-tool (macOS-latest, 3.12) (push) Waiting to run
test release tool / test-release-tool (macOS-latest, 3.13) (push) Waiting to run
test release tool / test-release-tool (macOS-latest, 3.14) (push) Waiting to run
test release tool / test-release-tool (macOS-latest, 3.15) (push) Waiting to run
docker / build (linux/arm64) (push) Waiting to run
docker / push (push) Blocked by required conditions
docs / docs (windows-latest) (push) Waiting to run
test release tool / test-release-tool (windows-latest, 3.12) (push) Waiting to run
test release tool / test-release-tool (windows-latest, 3.13) (push) Waiting to run
test release tool / test-release-tool (windows-latest, 3.14) (push) Waiting to run
test release tool / test-release-tool (windows-latest, 3.15) (push) Waiting to run
test / test (macOS-latest, 3.10) (push) Waiting to run
test / test (macOS-latest, 3.11) (push) Waiting to run
test / test (macOS-latest, 3.12.10) (push) Waiting to run
test / test (macOS-latest, 3.13) (push) Waiting to run
test / test (macOS-latest, 3.14) (push) Waiting to run
test / test (macOS-latest, 3.15) (push) Waiting to run
test / test (macOS-latest, pypy3.11-v7.3.22) (push) Waiting to run
test / test (windows-11-arm, 3.11) (push) Waiting to run
test / test (windows-11-arm, 3.12.10) (push) Waiting to run
test / test (windows-11-arm, 3.13) (push) Waiting to run
test / test (windows-11-arm, 3.14) (push) Waiting to run
test / test (windows-11-arm, 3.15) (push) Waiting to run
test / test (windows-latest, 3.10) (push) Waiting to run
test / test (windows-latest, 3.11) (push) Waiting to run
test / test (windows-latest, 3.12.10) (push) Waiting to run
test / test (windows-latest, 3.13) (push) Waiting to run
test / test (windows-latest, 3.14) (push) Waiting to run
test / test (windows-latest, 3.15) (push) Waiting to run
test / test (windows-latest, pypy3.11-v7.3.22) (push) Waiting to run
test / coveralls-finish (push) Blocked by required conditions
test / uvloop (macOS-latest) (push) Waiting to run
test / uvloop (windows-11-arm) (push) Waiting to run
test / uvloop (windows-latest) (push) Waiting to run
fuzz / fuzz (3.11) (push) Failing after 1s
fuzz / fuzz (3.12) (push) Failing after 1s
build and publish / sdist + pure wheel (push) Failing after 0s
diff-shades / analysis / base / ${{ matrix.mode }} (push) Has been skipped
diff-shades / compare / ${{ matrix.mode }} (push) Waiting to run
docs / docs (ubuntu-latest) (push) Failing after 2s
fuzz / fuzz (3.10) (push) Failing after 1s
fuzz / fuzz (3.14) (push) Failing after 0s
lint and format / lint (push) Failing after 1s
build and publish / publish-mypyc (push) Waiting to run
diff-shades / configure (push) Failing after 1s
docker / build (linux/amd64) (push) Has been skipped
diff-shades / analysis / target / ${{ matrix.mode }} (push) Has been skipped
fuzz / fuzz (3.13) (push) Failing after 0s
fuzz / create-issue (push) Waiting to run
build and publish / generate wheels matrix (push) Failing after 0s
test release tool / test-release-tool (ubuntu-latest, 3.13) (push) Failing after 1s
build and publish / mypyc wheels ${{ matrix.only }} (push) Has been skipped
build and publish / publish-hatch (push) Waiting to run
test / test (ubuntu-latest, 3.10) (push) Failing after 0s
test / test (ubuntu-latest, 3.11) (push) Failing after 1s
test / test (ubuntu-latest, 3.13) (push) Failing after 0s
test / test (ubuntu-latest, pypy3.11-v7.3.22) (push) Failing after 1s
test / test (ubuntu-latest, 3.15) (push) Failing after 1s
test release tool / test-release-tool (ubuntu-latest, 3.15) (push) Failing after 0s
zizmor / zizmor (push) Failing after 0s
test release tool / test-release-tool (ubuntu-latest, 3.12) (push) Failing after 4s
test release tool / test-release-tool (ubuntu-latest, 3.14) (push) Failing after 3s
test / uvloop (ubuntu-latest) (push) Failing after 1s
test / test (ubuntu-latest, 3.14) (push) Failing after 1s
test / test (ubuntu-latest, 3.12.10) (push) Failing after 5s
chore: import upstream snapshot with attribution
2026-07-13 12:07:39 +08:00

75 lines
2.5 KiB
Python

"""
Test that the docs are up to date.
"""
import re
from collections.abc import Sequence
from itertools import islice
from pathlib import Path
import pytest
from black.mode import UNSTABLE_FEATURES, Preview
DOCS_PATH = Path("docs/the_black_code_style/future_style.md")
def check_feature_list(
lines: Sequence[str], expected_feature_names: set[str], label: str
) -> str | None:
start_index = lines.index(f"(labels/{label}-features)=\n")
if start_index == -1:
return (
f"Could not find the {label} features list in {DOCS_PATH}. Ensure the"
" preview-features label is present."
)
num_blank_lines_seen = 0
seen_preview_feature_names = set()
for line in islice(lines, start_index + 1, None):
if not line.strip():
num_blank_lines_seen += 1
if num_blank_lines_seen == 3:
break
continue
if line.startswith("- "):
match = re.search(r"^- `([a-z\d_]+)`", line)
if match:
seen_preview_feature_names.add(match.group(1))
if seen_preview_feature_names - expected_feature_names:
extra = ", ".join(sorted(seen_preview_feature_names - expected_feature_names))
return (
f"The following features should not be in the list of {label} features:"
f" {extra}. Please remove them from the {label}-features label in"
f" {DOCS_PATH}"
)
elif expected_feature_names - seen_preview_feature_names:
missing = ", ".join(sorted(expected_feature_names - seen_preview_feature_names))
return (
f"The following features are missing from the list of {label} features:"
f" {missing}. Please document them under the {label}-features label in"
f" {DOCS_PATH}"
)
else:
return None
def test_feature_lists_are_up_to_date() -> None:
repo_root = Path(__file__).parent.parent
if not (repo_root / "docs").exists():
pytest.skip("docs not found")
with (repo_root / DOCS_PATH).open(encoding="utf-8") as f:
future_style = f.readlines()
preview_error = check_feature_list(
future_style,
{feature.name for feature in set(Preview) - UNSTABLE_FEATURES},
"preview",
)
assert preview_error is None, preview_error
unstable_error = check_feature_list(
future_style, {feature.name for feature in UNSTABLE_FEATURES}, "unstable"
)
assert unstable_error is None, unstable_error