• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pantsbuild / pants / 26080722777

19 May 2026 06:37AM UTC coverage: 52.106% (-11.5%) from 63.597%
26080722777

Pull #23250

github

web-flow
Merge 63ec06323 into 2693df832
Pull Request #23250: Feature: Add generic option to docker image

12 of 50 new or added lines in 3 files covered. (24.0%)

5382 existing lines in 201 files now uncovered.

32053 of 61515 relevant lines covered (52.11%)

1.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.32
/src/python/pants/backend/python/lint/docformatter/rules_integration_test.py
1
# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
from __future__ import annotations
2✔
5

6
import pytest
2✔
7

8
from pants.backend.python import target_types_rules
2✔
9
from pants.backend.python.lint.docformatter.rules import DocformatterFieldSet, DocformatterRequest
2✔
10
from pants.backend.python.lint.docformatter.rules import rules as docformatter_rules
2✔
11
from pants.backend.python.lint.docformatter.subsystem import rules as docformatter_subsystem_rules
2✔
12
from pants.backend.python.target_types import PythonSourcesGeneratorTarget
2✔
13
from pants.core.goals.fmt import FmtResult
2✔
14
from pants.core.util_rules import source_files
2✔
15
from pants.core.util_rules.source_files import SourceFiles, SourceFilesRequest
2✔
16
from pants.engine.addresses import Address
2✔
17
from pants.engine.target import Target
2✔
18
from pants.testutil.python_interpreter_selection import all_major_minor_python_versions
2✔
19
from pants.testutil.rule_runner import QueryRule, RuleRunner
2✔
20

21

22
@pytest.fixture
2✔
23
def rule_runner() -> RuleRunner:
2✔
24
    return RuleRunner(
2✔
25
        rules=[
26
            *docformatter_rules(),
27
            *docformatter_subsystem_rules(),
28
            *source_files.rules(),
29
            *target_types_rules.rules(),
30
            QueryRule(FmtResult, (DocformatterRequest.Batch,)),
31
            QueryRule(SourceFiles, (SourceFilesRequest,)),
32
        ],
33
        target_types=[PythonSourcesGeneratorTarget],
34
    )
35

36

37
GOOD_FILE = '"""Good docstring."""\n'
2✔
38
BAD_FILE = '"""Oops, missing a period"""\n'
2✔
39
FIXED_BAD_FILE = '"""Oops, missing a period."""\n'
2✔
40

41

42
def run_docformatter(
2✔
43
    rule_runner: RuleRunner, targets: list[Target], *, extra_args: list[str] | None = None
44
) -> FmtResult:
45
    rule_runner.set_options(
2✔
46
        args=[
47
            "--backend-packages=pants.backend.python.lint.docformatter",
48
            "--python-interpreter-constraints=['==3.12.*']",
49
            *(extra_args or ()),
50
        ],
51
        env_inherit={"PATH", "PYENV_ROOT", "HOME"},
52
    )
53
    field_sets = [DocformatterFieldSet.create(tgt) for tgt in targets]
2✔
54
    input_sources = rule_runner.request(
2✔
55
        SourceFiles,
56
        [
57
            SourceFilesRequest(field_set.source for field_set in field_sets),
58
        ],
59
    )
60
    fmt_result = rule_runner.request(
2✔
61
        FmtResult,
62
        [
63
            DocformatterRequest.Batch(
64
                "",
65
                input_sources.snapshot.files,
66
                partition_metadata=None,
67
                snapshot=input_sources.snapshot,
68
            ),
69
        ],
70
    )
71
    return fmt_result
2✔
72

73

74
@pytest.mark.platform_specific_behavior
2✔
75
@pytest.mark.parametrize(
2✔
76
    "major_minor_interpreter",
77
    # Excluded due to https://github.com/pantsbuild/pants/issues/21718
78
    # lib2to3 is Officially Removed in 3.13, but some distributions of Python
79
    # remove it earlier See for example https://github.com/PyCQA/docformatter/issues/129
80
    all_major_minor_python_versions(["CPython>=3.9,<3.12"]),
81
)
82
def test_passing(rule_runner: RuleRunner, major_minor_interpreter: str) -> None:
2✔
83
    rule_runner.write_files({"f.py": GOOD_FILE, "BUILD": "python_sources(name='t')"})
2✔
84
    tgt = rule_runner.get_target(Address("", target_name="t", relative_file_path="f.py"))
2✔
85
    fmt_result = run_docformatter(
2✔
86
        rule_runner,
87
        [tgt],
88
        extra_args=[f"--docformatter-interpreter-constraints=['=={major_minor_interpreter}.*']"],
89
    )
90
    assert fmt_result.output == rule_runner.make_snapshot({"f.py": GOOD_FILE})
2✔
91
    assert fmt_result.did_change is False
2✔
92

93

94
def test_failing(rule_runner: RuleRunner) -> None:
2✔
UNCOV
95
    rule_runner.write_files({"f.py": BAD_FILE, "BUILD": "python_sources(name='t')"})
×
UNCOV
96
    tgt = rule_runner.get_target(Address("", target_name="t", relative_file_path="f.py"))
×
UNCOV
97
    fmt_result = run_docformatter(rule_runner, [tgt])
×
UNCOV
98
    assert fmt_result.output == rule_runner.make_snapshot({"f.py": FIXED_BAD_FILE})
×
UNCOV
99
    assert fmt_result.did_change is True
×
100

101

102
def test_multiple_targets(rule_runner: RuleRunner) -> None:
2✔
UNCOV
103
    rule_runner.write_files(
×
104
        {"good.py": GOOD_FILE, "bad.py": BAD_FILE, "BUILD": "python_sources(name='t')"}
105
    )
UNCOV
106
    tgts = [
×
107
        rule_runner.get_target(Address("", target_name="t", relative_file_path="good.py")),
108
        rule_runner.get_target(Address("", target_name="t", relative_file_path="bad.py")),
109
    ]
UNCOV
110
    fmt_result = run_docformatter(rule_runner, tgts)
×
UNCOV
111
    assert fmt_result.output == rule_runner.make_snapshot(
×
112
        {"good.py": GOOD_FILE, "bad.py": FIXED_BAD_FILE}
113
    )
UNCOV
114
    assert fmt_result.did_change is True
×
115

116

117
def test_respects_passthrough_args(rule_runner: RuleRunner) -> None:
2✔
UNCOV
118
    content = '"""\nOne line docstring acting like it\'s multiline.\n"""\n'
×
UNCOV
119
    rule_runner.write_files({"f.py": content, "BUILD": "python_sources(name='t')"})
×
UNCOV
120
    tgt = rule_runner.get_target(Address("", target_name="t", relative_file_path="f.py"))
×
UNCOV
121
    fmt_result = run_docformatter(
×
122
        rule_runner,
123
        [tgt],
124
        extra_args=["--docformatter-args='--make-summary-multi-line'"],
125
    )
UNCOV
126
    assert fmt_result.output == rule_runner.make_snapshot({"f.py": content})
×
UNCOV
127
    assert fmt_result.did_change is False
×
128

129

130
def test_stub_files(rule_runner: RuleRunner) -> None:
2✔
UNCOV
131
    rule_runner.write_files(
×
132
        {"good.pyi": GOOD_FILE, "bad.pyi": BAD_FILE, "BUILD": "python_sources(name='t')"}
133
    )
134

UNCOV
135
    good_tgt = rule_runner.get_target(Address("", target_name="t", relative_file_path="good.pyi"))
×
UNCOV
136
    fmt_result = run_docformatter(rule_runner, [good_tgt])
×
UNCOV
137
    assert fmt_result.output == rule_runner.make_snapshot({"good.pyi": GOOD_FILE})
×
UNCOV
138
    assert not fmt_result.did_change
×
139

UNCOV
140
    bad_tgt = rule_runner.get_target(Address("", target_name="t", relative_file_path="bad.pyi"))
×
UNCOV
141
    fmt_result = run_docformatter(rule_runner, [bad_tgt])
×
UNCOV
142
    assert fmt_result.output == rule_runner.make_snapshot({"bad.pyi": FIXED_BAD_FILE})
×
UNCOV
143
    assert fmt_result.did_change
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc