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

pantsbuild / pants / 20332790708

18 Dec 2025 09:48AM UTC coverage: 64.992% (-15.3%) from 80.295%
20332790708

Pull #22949

github

web-flow
Merge f730a56cd into 407284c67
Pull Request #22949: Add experimental uv resolver for Python lockfiles

54 of 97 new or added lines in 5 files covered. (55.67%)

8270 existing lines in 295 files now uncovered.

48990 of 75379 relevant lines covered (64.99%)

1.81 hits per line

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

68.63
/src/python/pants/backend/build_files/fmt/yapf/integration_test.py
1
# Copyright 2022 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.yapf.register import YapfRequest
1✔
9
from pants.backend.build_files.fmt.yapf.register import rules as yapf_build_rules
1✔
10
from pants.backend.python.lint.yapf.rules import rules as yapf_fmt_rules
1✔
11
from pants.backend.python.lint.yapf.subsystem import Yapf
1✔
12
from pants.backend.python.lint.yapf.subsystem import rules as yapf_subsystem_rules
1✔
13
from pants.backend.python.target_types import PythonSourcesGeneratorTarget
1✔
14
from pants.core.goals.fmt import FmtResult
1✔
15
from pants.core.util_rules import config_files
1✔
16
from pants.engine.fs import PathGlobs
1✔
17
from pants.engine.internals.native_engine import Snapshot
1✔
18
from pants.testutil.python_interpreter_selection import all_major_minor_python_versions
1✔
19
from pants.testutil.rule_runner import QueryRule, RuleRunner
1✔
20

21

22
@pytest.fixture
1✔
23
def rule_runner() -> RuleRunner:
1✔
24
    return RuleRunner(
1✔
25
        rules=[
26
            *yapf_build_rules(),
27
            *yapf_fmt_rules(),
28
            *yapf_subsystem_rules(),
29
            *config_files.rules(),
30
            QueryRule(FmtResult, (YapfRequest.Batch,)),
31
        ],
32
        target_types=[PythonSourcesGeneratorTarget],
33
    )
34

35

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

50

51
@pytest.mark.platform_specific_behavior
1✔
52
@pytest.mark.parametrize(
1✔
53
    "major_minor_interpreter",
54
    all_major_minor_python_versions(Yapf.default_interpreter_constraints),
55
)
56
def test_passing(rule_runner: RuleRunner, major_minor_interpreter: str) -> None:
1✔
57
    rule_runner.write_files({"BUILD": 'python_sources(name="t")\n'})
1✔
58
    interpreter_constraint = (
1✔
59
        ">=3.6.2,<3.7" if major_minor_interpreter == "3.6" else f"=={major_minor_interpreter}.*"
60
    )
61
    fmt_result = run_yapf(
1✔
62
        rule_runner,
63
        extra_args=[f"--yapf-interpreter-constraints=['{interpreter_constraint}']"],
64
    )
65
    assert fmt_result.output == rule_runner.make_snapshot({"BUILD": 'python_sources(name="t")\n'})
1✔
66
    assert fmt_result.did_change is False
1✔
67

68

69
def test_failing(rule_runner: RuleRunner) -> None:
1✔
UNCOV
70
    rule_runner.write_files({"BUILD": 'python_sources(name = "t")\n'})
×
UNCOV
71
    fmt_result = run_yapf(rule_runner)
×
UNCOV
72
    assert fmt_result.output == rule_runner.make_snapshot({"BUILD": 'python_sources(name="t")\n'})
×
UNCOV
73
    assert fmt_result.did_change is True
×
74

75

76
def test_multiple_files(rule_runner: RuleRunner) -> None:
1✔
UNCOV
77
    rule_runner.write_files(
×
78
        {
79
            "good/BUILD": 'python_sources(name="t")\n',
80
            "bad/BUILD": 'python_sources(name = "t")\n',
81
        }
82
    )
UNCOV
83
    fmt_result = run_yapf(rule_runner)
×
UNCOV
84
    assert fmt_result.output == rule_runner.make_snapshot(
×
85
        {"good/BUILD": 'python_sources(name="t")\n', "bad/BUILD": 'python_sources(name="t")\n'},
86
    )
UNCOV
87
    assert fmt_result.did_change is True
×
88

89

90
@pytest.mark.parametrize(
1✔
91
    "path,section,extra_args",
92
    (
93
        (".style.yapf", "style", []),
94
        ("custom.style", "style", ["--yapf-config=custom.style"]),
95
    ),
96
)
97
def test_config_file(
1✔
98
    rule_runner: RuleRunner, path: str, section: str, extra_args: list[str]
99
) -> None:
UNCOV
100
    rule_runner.write_files(
×
101
        {
102
            "BUILD": 'python_sources(name = "t")\n',
103
            path: f"[{section}]\nspaces_around_default_or_named_assign = True\n",
104
        }
105
    )
UNCOV
106
    fmt_result = run_yapf(rule_runner, extra_args=extra_args)
×
UNCOV
107
    assert fmt_result.output == rule_runner.make_snapshot({"BUILD": 'python_sources(name = "t")\n'})
×
UNCOV
108
    assert fmt_result.did_change is False
×
109

110

111
def test_passthrough_args(rule_runner: RuleRunner) -> None:
1✔
UNCOV
112
    rule_runner.write_files({"BUILD": 'python_sources(name = "t")\n'})
×
UNCOV
113
    fmt_result = run_yapf(
×
114
        rule_runner,
115
        extra_args=["--yapf-args=--style='{spaces_around_default_or_named_assign: True}'"],
116
    )
UNCOV
117
    assert fmt_result.output == rule_runner.make_snapshot({"BUILD": 'python_sources(name = "t")\n'})
×
UNCOV
118
    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