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

pantsbuild / pants / 21552830208

31 Jan 2026 11:40PM UTC coverage: 80.277% (-0.05%) from 80.324%
21552830208

Pull #23062

github

web-flow
Merge 808a9786c into 2c4dcf9cf
Pull Request #23062: Remove support for Get

18 of 25 new or added lines in 4 files covered. (72.0%)

17119 existing lines in 541 files now uncovered.

78278 of 97510 relevant lines covered (80.28%)

3.36 hits per line

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

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

4
from __future__ import annotations
3✔
5

6
import pytest
3✔
7

8
from pants.backend.python import target_types_rules
3✔
9
from pants.backend.python.lint.autoflake.rules import AutoflakeFieldSet, AutoflakeRequest
3✔
10
from pants.backend.python.lint.autoflake.rules import rules as autoflake_rules
3✔
11
from pants.backend.python.lint.autoflake.subsystem import Autoflake
3✔
12
from pants.backend.python.lint.autoflake.subsystem import rules as autoflake_subsystem_rules
3✔
13
from pants.backend.python.target_types import PythonSourcesGeneratorTarget
3✔
14
from pants.core.goals.fix import FixResult
3✔
15
from pants.core.util_rules import config_files, source_files
3✔
16
from pants.core.util_rules.source_files import SourceFiles, SourceFilesRequest
3✔
17
from pants.engine.addresses import Address
3✔
18
from pants.engine.target import Target
3✔
19
from pants.testutil.python_interpreter_selection import all_major_minor_python_versions
3✔
20
from pants.testutil.rule_runner import QueryRule, RuleRunner
3✔
21

22

23
@pytest.fixture
3✔
24
def rule_runner() -> RuleRunner:
3✔
25
    return RuleRunner(
3✔
26
        rules=[
27
            *autoflake_rules(),
28
            *autoflake_subsystem_rules(),
29
            *source_files.rules(),
30
            *config_files.rules(),
31
            *target_types_rules.rules(),
32
            QueryRule(FixResult, (AutoflakeRequest.Batch,)),
33
            QueryRule(SourceFiles, (SourceFilesRequest,)),
34
        ],
35
        target_types=[PythonSourcesGeneratorTarget],
36
    )
37

38

39
GOOD_FILE = "from foo import Foo\nprint(Foo())\n"
3✔
40
BAD_FILE = "from foo import Foo\nprint(Bar())\n"
3✔
41
FIXED_BAD_FILE = "print(Bar())\n"
3✔
42

43

44
def run_autoflake(
3✔
45
    rule_runner: RuleRunner,
46
    targets: list[Target],
47
    *,
48
    extra_args: list[str] | None = None,
49
) -> FixResult:
50
    rule_runner.set_options(
3✔
51
        ["--backend-packages=pants.backend.python.lint.autoflake", *(extra_args or ())],
52
        env_inherit={"PATH", "PYENV_ROOT", "HOME"},
53
    )
54
    field_sets = [AutoflakeFieldSet.create(tgt) for tgt in targets]
3✔
55
    input_sources = rule_runner.request(
3✔
56
        SourceFiles,
57
        [
58
            SourceFilesRequest(field_set.source for field_set in field_sets),
59
        ],
60
    )
61
    fix_result = rule_runner.request(
3✔
62
        FixResult,
63
        [
64
            AutoflakeRequest.Batch(
65
                "",
66
                input_sources.snapshot.files,
67
                partition_metadata=None,
68
                snapshot=input_sources.snapshot,
69
            ),
70
        ],
71
    )
72
    return fix_result
3✔
73

74

75
@pytest.mark.platform_specific_behavior
3✔
76
@pytest.mark.parametrize(
3✔
77
    "major_minor_interpreter",
78
    all_major_minor_python_versions(Autoflake.default_interpreter_constraints),
79
)
80
def test_passing_source(rule_runner: RuleRunner, major_minor_interpreter: str) -> None:
3✔
81
    rule_runner.write_files({"f.py": GOOD_FILE, "BUILD": "python_sources(name='t')"})
3✔
82
    tgt = rule_runner.get_target(Address("", target_name="t", relative_file_path="f.py"))
3✔
83
    fix_result = run_autoflake(
3✔
84
        rule_runner,
85
        [tgt],
86
        extra_args=[f"--autoflake-interpreter-constraints=['=={major_minor_interpreter}.*']"],
87
    )
88
    assert fix_result.stdout == ""
3✔
89
    assert fix_result.output == rule_runner.make_snapshot({"f.py": GOOD_FILE})
3✔
90
    assert fix_result.did_change is False
3✔
91

92

93
def test_failing_source(rule_runner: RuleRunner) -> None:
3✔
UNCOV
94
    rule_runner.write_files({"f.py": BAD_FILE, "BUILD": "python_sources(name='t')"})
1✔
UNCOV
95
    tgt = rule_runner.get_target(Address("", target_name="t", relative_file_path="f.py"))
1✔
UNCOV
96
    fix_result = run_autoflake(rule_runner, [tgt])
1✔
UNCOV
97
    assert fix_result.output == rule_runner.make_snapshot({"f.py": FIXED_BAD_FILE})
1✔
UNCOV
98
    assert fix_result.did_change is True
1✔
99

100

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

115

116
def test_stub_files(rule_runner: RuleRunner) -> None:
3✔
UNCOV
117
    rule_runner.write_files(
1✔
118
        {
119
            "good.pyi": GOOD_FILE,
120
            "good.py": GOOD_FILE,
121
            "bad.pyi": BAD_FILE,
122
            "bad.py": BAD_FILE,
123
            "BUILD": "python_sources(name='t')",
124
        }
125
    )
126

UNCOV
127
    good_tgts = [
1✔
128
        rule_runner.get_target(Address("", target_name="t", relative_file_path="good.pyi")),
129
        rule_runner.get_target(Address("", target_name="t", relative_file_path="good.py")),
130
    ]
UNCOV
131
    fix_result = run_autoflake(rule_runner, good_tgts)
1✔
UNCOV
132
    assert fix_result.stdout == ""
1✔
UNCOV
133
    assert fix_result.output == rule_runner.make_snapshot(
1✔
134
        {"good.py": GOOD_FILE, "good.pyi": GOOD_FILE}
135
    )
UNCOV
136
    assert not fix_result.did_change
1✔
137

UNCOV
138
    bad_tgts = [
1✔
139
        rule_runner.get_target(Address("", target_name="t", relative_file_path="bad.pyi")),
140
        rule_runner.get_target(Address("", target_name="t", relative_file_path="bad.py")),
141
    ]
UNCOV
142
    fix_result = run_autoflake(rule_runner, bad_tgts)
1✔
UNCOV
143
    assert fix_result.output == rule_runner.make_snapshot(
1✔
144
        {"bad.py": FIXED_BAD_FILE, "bad.pyi": FIXED_BAD_FILE}
145
    )
UNCOV
146
    assert fix_result.did_change
1✔
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