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

pantsbuild / pants / 19381742489

15 Nov 2025 12:52AM UTC coverage: 49.706% (-30.6%) from 80.29%
19381742489

Pull #22890

github

web-flow
Merge d961abf79 into 42e1ebd41
Pull Request #22890: Updated all python subsystem constraints to 3.14

4 of 5 new or added lines in 5 files covered. (80.0%)

14659 existing lines in 485 files now uncovered.

31583 of 63540 relevant lines covered (49.71%)

0.79 hits per line

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

63.27
/src/python/pants/backend/build_files/fmt/ruff/integration_test.py
1
# Copyright 2024 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
from __future__ import annotations
1✔
5

6
import pytest
1✔
7

8
from pants.backend.build_files.fmt.ruff.register import RuffRequest
1✔
9
from pants.backend.build_files.fmt.ruff.register import rules as ruff_build_rules
1✔
10
from pants.backend.python.lint.ruff.check.rules import rules as ruff_fmt_rules
1✔
11
from pants.backend.python.lint.ruff.subsystem import rules as ruff_subsystem_rules
1✔
12
from pants.backend.python.target_types import PythonSourcesGeneratorTarget
1✔
13
from pants.core.goals.fmt import FmtResult
1✔
14
from pants.core.util_rules import config_files
1✔
15
from pants.engine.fs import PathGlobs
1✔
16
from pants.engine.internals.native_engine import Snapshot
1✔
17
from pants.testutil.rule_runner import QueryRule, RuleRunner
1✔
18

19

20
@pytest.fixture
1✔
21
def rule_runner() -> RuleRunner:
1✔
22
    return RuleRunner(
1✔
23
        rules=[
24
            *ruff_build_rules(),
25
            *ruff_fmt_rules(),
26
            *ruff_subsystem_rules(),
27
            *config_files.rules(),
28
            QueryRule(FmtResult, (RuffRequest.Batch,)),
29
        ],
30
        target_types=[PythonSourcesGeneratorTarget],
31
    )
32

33

34
def run_ruff(rule_runner: RuleRunner, *, extra_args: list[str] | None = None) -> FmtResult:
1✔
35
    rule_runner.set_options(
1✔
36
        ["--backend-packages=pants.backend.build_files.fmt.ruff", *(extra_args or ())],
37
        env_inherit={"PATH", "PYENV_ROOT", "HOME"},
38
    )
39
    snapshot = rule_runner.request(Snapshot, [PathGlobs(["**/BUILD"])])
1✔
40
    fmt_result = rule_runner.request(
1✔
41
        FmtResult,
42
        [
43
            RuffRequest.Batch("", snapshot.files, partition_metadata=None, snapshot=snapshot),
44
        ],
45
    )
46
    return fmt_result
1✔
47

48

49
@pytest.mark.platform_specific_behavior
1✔
50
def test_passing(rule_runner: RuleRunner) -> None:
1✔
51
    rule_runner.write_files({"BUILD": 'python_sources(name="t")\n'})
1✔
52
    fmt_result = run_ruff(
1✔
53
        rule_runner,
54
    )
55
    assert "1 file left unchanged" in fmt_result.stdout
1✔
56
    assert fmt_result.output == rule_runner.make_snapshot({"BUILD": 'python_sources(name="t")\n'})
1✔
57
    assert fmt_result.did_change is False
1✔
58

59

60
def test_failing(rule_runner: RuleRunner) -> None:
1✔
UNCOV
61
    rule_runner.write_files({"BUILD": "python_sources(name='t')\n"})
×
UNCOV
62
    fmt_result = run_ruff(rule_runner)
×
UNCOV
63
    assert "1 file reformatted" in fmt_result.stdout
×
UNCOV
64
    assert fmt_result.output == rule_runner.make_snapshot({"BUILD": 'python_sources(name="t")\n'})
×
UNCOV
65
    assert fmt_result.did_change is True
×
66

67

68
def test_multiple_files(rule_runner: RuleRunner) -> None:
1✔
UNCOV
69
    rule_runner.write_files(
×
70
        {
71
            "good/BUILD": 'python_sources(name="t")\n',
72
            "bad/BUILD": "python_sources(name='t')\n",
73
        }
74
    )
UNCOV
75
    fmt_result = run_ruff(rule_runner)
×
UNCOV
76
    assert "1 file reformatted, 1 file left unchanged" in fmt_result.stdout
×
UNCOV
77
    assert fmt_result.output == rule_runner.make_snapshot(
×
78
        {"good/BUILD": 'python_sources(name="t")\n', "bad/BUILD": 'python_sources(name="t")\n'}
79
    )
UNCOV
80
    assert fmt_result.did_change is True
×
81

82

83
@pytest.mark.parametrize(
1✔
84
    "config_path,extra_args",
85
    (["pyproject.toml", []], ["custom_config.toml", ["--ruff-config=custom_config.toml"]]),
86
)
87
def test_config_file(rule_runner: RuleRunner, config_path: str, extra_args: list[str]) -> None:
1✔
88
    # Force single-quote formatting to pass config and ensure there are no changes.
89
    # Use the `tool.ruff` key in pyproject.toml, but don't include in custom config.
UNCOV
90
    config_content = (
×
91
        '[tool.ruff.format]\nquote-style = "single"\n'
92
        if config_path == "pyproject.toml"
93
        else '[format]\nquote-style = "single"\n'
94
    )
UNCOV
95
    rule_runner.write_files(
×
96
        {
97
            "BUILD": "python_sources(name='t')\n",
98
            config_path: config_content,
99
        }
100
    )
UNCOV
101
    before_file_content = rule_runner.read_file("BUILD")
×
UNCOV
102
    fmt_result = run_ruff(rule_runner, extra_args=extra_args)
×
UNCOV
103
    after_file_content = rule_runner.read_file("BUILD")
×
104

UNCOV
105
    assert before_file_content == after_file_content
×
UNCOV
106
    assert fmt_result.output == rule_runner.make_snapshot({"BUILD": "python_sources(name='t')\n"})
×
UNCOV
107
    assert fmt_result.did_change is False
×
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