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

pantsbuild / pants / 20632486505

01 Jan 2026 04:21AM UTC coverage: 43.231% (-37.1%) from 80.281%
20632486505

Pull #22962

github

web-flow
Merge 08d5c63b0 into f52ab6675
Pull Request #22962: Bump the gha-deps group across 1 directory with 6 updates

26122 of 60424 relevant lines covered (43.23%)

0.86 hits per line

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

60.34
/src/python/pants/backend/tools/taplo/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
from __future__ import annotations
2✔
4

5
from typing import Any
2✔
6

7
import pytest
2✔
8

9
from pants.backend.tools.taplo.rules import TaploFmtRequest
2✔
10
from pants.backend.tools.taplo.rules import rules as taplo_rules
2✔
11
from pants.core.goals.fmt import FmtResult, Partitions
2✔
12
from pants.core.util_rules import config_files, external_tool
2✔
13
from pants.engine.fs import PathGlobs
2✔
14
from pants.engine.internals.native_engine import Snapshot
2✔
15
from pants.testutil.rule_runner import QueryRule, RuleRunner
2✔
16

17

18
@pytest.fixture
2✔
19
def rule_runner() -> RuleRunner:
2✔
20
    return RuleRunner(
2✔
21
        rules=[
22
            *taplo_rules(),
23
            *config_files.rules(),
24
            *external_tool.rules(),
25
            QueryRule(Partitions, [TaploFmtRequest.PartitionRequest]),
26
            QueryRule(FmtResult, [TaploFmtRequest.Batch]),
27
        ],
28
    )
29

30

31
GOOD_FILE = """[GLOBAL]\nbackend_packages = ["pants.backend.tools.taplo"]\n"""
2✔
32
BAD_FILE = """[GLOBAL]\nbackend_packages = [\n  "pants.backend.tools.taplo",\n]\n"""
2✔
33
NEEDS_CONFIG_FILE = """[GLOBAL]\npants_version = "2.17.0"\n"""
2✔
34
FIXED_NEEDS_CONFIG_FILE = """[GLOBAL]\npants_version="2.17.0"\n"""
2✔
35

36

37
def run_taplo(
2✔
38
    rule_runner: RuleRunner,
39
    *,
40
    extra_args: list[str] | None = None,
41
) -> FmtResult:
42
    rule_runner.set_options(
2✔
43
        ["--backend-packages=pants.backend.tools.taplo", *(extra_args or ())],
44
    )
45
    snapshot = rule_runner.request(Snapshot, [PathGlobs(["**", "!BUILDROOT"])])
2✔
46
    partition = rule_runner.request(
2✔
47
        Partitions[Any], [TaploFmtRequest.PartitionRequest(snapshot.files)]
48
    )[0]
49
    fmt_result = rule_runner.request(
2✔
50
        FmtResult,
51
        [
52
            TaploFmtRequest.Batch(
53
                "", partition.elements, partition_metadata=partition.metadata, snapshot=snapshot
54
            ),
55
        ],
56
    )
57
    return fmt_result
2✔
58

59

60
def test_no_changes_needed(rule_runner: RuleRunner) -> None:
2✔
61
    rule_runner.write_files({"f.toml": GOOD_FILE, "sub/g.toml": GOOD_FILE})
×
62
    fmt_result = run_taplo(rule_runner)
×
63
    assert not fmt_result.stdout
×
64
    assert "found files total=2" in fmt_result.stderr
×
65
    assert fmt_result.output == rule_runner.make_snapshot(
×
66
        {"f.toml": GOOD_FILE, "sub/g.toml": GOOD_FILE}
67
    )
68
    assert fmt_result.did_change is False
×
69

70

71
@pytest.mark.platform_specific_behavior
2✔
72
def test_changes_needed(rule_runner: RuleRunner) -> None:
2✔
73
    rule_runner.write_files({"f.toml": BAD_FILE, "sub/g.toml": BAD_FILE})
2✔
74
    fmt_result = run_taplo(rule_runner)
2✔
75
    assert not fmt_result.stdout
2✔
76
    assert "found files total=2" in fmt_result.stderr
2✔
77
    assert fmt_result.output == rule_runner.make_snapshot(
2✔
78
        {"f.toml": GOOD_FILE, "sub/g.toml": GOOD_FILE}
79
    )
80
    assert fmt_result.did_change is True
2✔
81

82

83
def test_globs(rule_runner: RuleRunner) -> None:
2✔
84
    rule_runner.write_files({"f.toml": BAD_FILE, "g.toml": BAD_FILE})
×
85
    fmt_result = run_taplo(rule_runner, extra_args=["--taplo-glob-pattern=['f.toml', '!g.toml']"])
×
86
    assert not fmt_result.stdout
×
87
    assert "found files total=1" in fmt_result.stderr
×
88
    assert fmt_result.output == rule_runner.make_snapshot({"f.toml": GOOD_FILE})
×
89

90

91
def test_config_files(rule_runner: RuleRunner) -> None:
2✔
92
    rule_runner.write_files(
×
93
        {
94
            "a/f.toml": NEEDS_CONFIG_FILE,
95
            ".taplo.toml": "[formatting]\ncompact_entries = true\n",
96
            "b/f.toml": NEEDS_CONFIG_FILE,
97
        }
98
    )
99
    fmt_result = run_taplo(rule_runner)
×
100
    assert not fmt_result.stdout
×
101
    assert "found files total=2" in fmt_result.stderr
×
102
    assert fmt_result.output == rule_runner.make_snapshot(
×
103
        {
104
            "a/f.toml": FIXED_NEEDS_CONFIG_FILE,
105
            "b/f.toml": FIXED_NEEDS_CONFIG_FILE,
106
        }
107
    )
108
    assert fmt_result.did_change
×
109

110

111
def test_passthrough_args(rule_runner: RuleRunner) -> None:
2✔
112
    rule_runner.write_files({"f.toml": NEEDS_CONFIG_FILE})
×
113
    fmt_result = run_taplo(rule_runner, extra_args=["--taplo-args='--option=compact_entries=true'"])
×
114
    assert not fmt_result.stdout
×
115
    assert "found files total=1" in fmt_result.stderr
×
116
    assert fmt_result.output == rule_runner.make_snapshot({"f.toml": FIXED_NEEDS_CONFIG_FILE})
×
117
    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