Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions tests/test_command_line.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import os.path
import sys
from typing import Any

import pytest
Expand All @@ -9,6 +10,11 @@
from sphinx.cmd.build import get_parser
from sphinx.cmd.make_mode import run_make_mode

broken_argparse = (
sys.version_info[:3] <= (3, 12, 6)
or sys.version_info[:3] == (3, 13, 0)
) # fmt: skip

DEFAULTS = {
'filenames': [],
'jobs': 1,
Expand Down Expand Up @@ -79,7 +85,6 @@
'--isolated',
]
OPTS = EARLY_OPTS + LATE_OPTS
OPTS_BUILD_MAIN = BUILDER_BUILD_MAIN + OPTS


def parse_arguments(args: list[str]) -> dict[str, Any]:
Expand Down Expand Up @@ -116,7 +121,10 @@ def test_build_main_parse_arguments_pos_middle() -> None:
assert parse_arguments(args) == EXPECTED_BUILD_MAIN


@pytest.mark.xfail(reason='sphinx-build does not yet support filenames after options')
@pytest.mark.xfail(
broken_argparse,
reason='sphinx-build does not yet support filenames after options',
)
def test_build_main_parse_arguments_filenames_last() -> None:
args = [
*POSITIONAL_DIRS,
Expand All @@ -136,10 +144,13 @@ def test_build_main_parse_arguments_pos_intermixed(
*LATE_OPTS,
*POSITIONAL_FILENAMES,
]
with pytest.raises(SystemExit):
parse_arguments(args)
stderr = capsys.readouterr().err.splitlines()
assert stderr[-1].endswith('error: unrecognized arguments: filename1 filename2')
if broken_argparse:
with pytest.raises(SystemExit):
parse_arguments(args)
stderr = capsys.readouterr().err.splitlines()
assert stderr[-1].endswith('error: unrecognized arguments: filename1 filename2')
else:
assert parse_arguments(args) == EXPECTED_BUILD_MAIN


def test_make_mode_parse_arguments_pos_first(monkeypatch: pytest.MonkeyPatch) -> None:
Expand Down Expand Up @@ -185,10 +196,14 @@ def test_make_mode_parse_arguments_pos_middle(
assert stderr[-1].endswith('error: argument --builder/-b: expected one argument')


@pytest.mark.xfail(reason='sphinx-build does not yet support filenames after options')
@pytest.mark.xfail(
broken_argparse,
reason='sphinx-build does not yet support filenames after options',
)
def test_make_mode_parse_arguments_filenames_last(
monkeypatch: pytest.MonkeyPatch,
) -> None:
# -M <positional...> <opts> <filenames...>
monkeypatch.setattr(make_mode, 'build_main', parse_arguments)
args = [
*BUILDER_MAKE_MODE,
Expand All @@ -203,6 +218,7 @@ def test_make_mode_parse_arguments_pos_intermixed(
monkeypatch: pytest.MonkeyPatch,
capsys: pytest.CaptureFixture[str],
) -> None:
# -M <opts> <positional...> <opts> <filenames...>
monkeypatch.setattr(make_mode, 'build_main', parse_arguments)
args = [
*EARLY_OPTS,
Expand Down
Loading