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

pantsbuild / pants / 18517631058

15 Oct 2025 04:18AM UTC coverage: 69.207% (-11.1%) from 80.267%
18517631058

Pull #22745

github

web-flow
Merge 642a76ca1 into 99919310e
Pull Request #22745: [windows] Add windows support in the stdio crate.

53815 of 77759 relevant lines covered (69.21%)

2.42 hits per line

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

56.94
/src/python/pants/backend/tools/yamllint/rules_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
2✔
5

6
from typing import Any, overload
2✔
7

8
import pytest
2✔
9

10
from pants.backend.python.util_rules.pex import rules as pex_rules
2✔
11
from pants.backend.tools.yamllint.rules import PartitionInfo, YamllintRequest
2✔
12
from pants.backend.tools.yamllint.rules import rules as yamllint_rules
2✔
13
from pants.core.goals.lint import LintResult, Partitions
2✔
14
from pants.core.util_rules import config_files, external_tool, source_files
2✔
15
from pants.engine.fs import PathGlobs
2✔
16
from pants.engine.internals.native_engine import Snapshot
2✔
17
from pants.testutil.rule_runner import QueryRule, RuleRunner
2✔
18

19

20
@pytest.fixture
2✔
21
def rule_runner() -> RuleRunner:
2✔
22
    return RuleRunner(
2✔
23
        rules=[
24
            *yamllint_rules(),
25
            *config_files.rules(),
26
            *source_files.rules(),
27
            *external_tool.rules(),
28
            *pex_rules(),
29
            QueryRule(Partitions, [YamllintRequest.PartitionRequest]),
30
            QueryRule(LintResult, [YamllintRequest.Batch]),
31
        ],
32
    )
33

34

35
GOOD_FILE = """\
2✔
36
this: is
37
valid: YAML
38
"""
39

40
DOCUMENT_START_DISABLE_CONFIG = """\
2✔
41
extends: default
42

43
rules:
44
  document-start: disable
45
"""
46

47
RELAXED_CONFIG = """
2✔
48
extends: relaxed
49
"""
50

51
GOOD_FILE_WITH_START = """\
2✔
52
---
53
this: is
54
valid: YAML
55
"""
56

57
REPEATED_KEY = """\
2✔
58
---
59
this: key
60
is: repeated
61
this: here
62
"""
63

64
NOT_YAML = """\
2✔
65
This definitely
66
isn't valid YAML,
67
is it?
68
"""
69

70

71
@overload
72
def run_yamllint(
73
    rule_runner: RuleRunner,
74
    *,
75
    extra_args: list[str] | None = None,
76
    expected_partitions: None = None,
77
) -> LintResult: ...
78

79

80
@overload
81
def run_yamllint(
82
    rule_runner: RuleRunner,
83
    *,
84
    extra_args: list[str] | None = None,
85
    expected_partitions: tuple[tuple[str, ...], dict[str, tuple[str, ...]]],
86
) -> list[LintResult]: ...
87

88

89
def run_yamllint(
2✔
90
    rule_runner: RuleRunner,
91
    *,
92
    extra_args: list[str] | None = None,
93
    expected_partitions: tuple[tuple[str, ...], dict[str, tuple[str, ...]]] | None = None,
94
) -> LintResult | list[LintResult]:
95
    rule_runner.set_options(
2✔
96
        ["--backend-packages=pants.backend.tools.experimental.yamllint", *(extra_args or ())],
97
        env_inherit={"PATH", "PYENV_ROOT"},
98
    )
99
    snapshot = rule_runner.request(Snapshot, [PathGlobs(["**"])])
2✔
100
    partitions = rule_runner.request(
2✔
101
        Partitions[Any, PartitionInfo], [YamllintRequest.PartitionRequest(snapshot.files)]
102
    )
103

104
    if expected_partitions:
2✔
105
        expected_default_partition = expected_partitions[0]
×
106
        default_partitions = tuple(p for p in partitions if p.metadata.config_snapshot is None)
×
107
        if expected_default_partition:
×
108
            assert len(default_partitions) == 1
×
109
            assert default_partitions[0].elements == expected_default_partition
×
110
        else:
111
            assert len(default_partitions) == 0
×
112

113
        config_partitions = tuple(p for p in partitions if p.metadata.config_snapshot)
×
114
        expected_config_partitions = expected_partitions[1]
×
115
        assert len(config_partitions) == len(expected_config_partitions)
×
116
        for partition in config_partitions:
×
117
            assert partition.metadata.config_snapshot is not None
×
118
            config_file = partition.metadata.config_snapshot.files[0]
×
119

120
            assert config_file in expected_config_partitions
×
121
            assert partition.elements == expected_config_partitions[config_file]
×
122
    else:
123
        assert len(partitions) == 1
2✔
124

125
    results = [
2✔
126
        rule_runner.request(
127
            LintResult,
128
            [
129
                YamllintRequest.Batch(
130
                    "",
131
                    partition.elements,
132
                    partition_metadata=partition.metadata,
133
                )
134
            ],
135
        )
136
        for partition in partitions
137
    ]
138
    return results if expected_partitions else results[0]
2✔
139

140

141
def assert_success(rule_runner: RuleRunner, *, extra_args: list[str] | None = None) -> None:
2✔
142
    result = run_yamllint(rule_runner, extra_args=extra_args)
×
143
    assert result.exit_code == 0
×
144
    assert not result.stdout
×
145
    assert not result.stderr
×
146

147

148
def assert_failure_with(
2✔
149
    snippet: str,
150
    rule_runner: RuleRunner,
151
    *,
152
    extra_args: list[str] | None = None,
153
) -> None:
154
    result = run_yamllint(rule_runner, extra_args=extra_args)
2✔
155
    assert result.exit_code == 1
2✔
156
    assert snippet in result.stdout
2✔
157

158

159
def test_passing(rule_runner: RuleRunner) -> None:
2✔
160
    rule_runner.write_files({"test.yaml": GOOD_FILE_WITH_START, "not_yaml": NOT_YAML})
×
161
    assert_success(rule_runner)
×
162

163

164
@pytest.mark.platform_specific_behavior
2✔
165
def test_failure(rule_runner: RuleRunner) -> None:
2✔
166
    rule_runner.write_files({"test.yaml": REPEATED_KEY, "not_yaml": NOT_YAML})
2✔
167
    assert_failure_with('duplication of key "this"', rule_runner)
2✔
168

169

170
def test_config_autodiscovery(rule_runner: RuleRunner) -> None:
2✔
171
    rule_runner.write_files(
×
172
        {
173
            "test.yaml": GOOD_FILE,
174
            ".yamllint": DOCUMENT_START_DISABLE_CONFIG,
175
            "not_yaml": NOT_YAML,
176
        }
177
    )
178
    assert_success(rule_runner)
×
179

180

181
def test_config_autodiscovery_yml(rule_runner: RuleRunner) -> None:
2✔
182
    rule_runner.write_files(
×
183
        {
184
            "test.yaml": GOOD_FILE,
185
            ".yamllint.yml": DOCUMENT_START_DISABLE_CONFIG,
186
            "not_yaml": NOT_YAML,
187
        }
188
    )
189
    assert_success(rule_runner, extra_args=["--yamllint-config-file-name=.yamllint.yml"])
×
190

191

192
def test_multi_config(rule_runner: RuleRunner) -> None:
2✔
193
    rule_runner.write_files(
×
194
        {
195
            "test.yaml": GOOD_FILE_WITH_START,
196
            "subdir1/.yamllint": DOCUMENT_START_DISABLE_CONFIG,
197
            "subdir1/subdir.yaml": GOOD_FILE,
198
            "subdir1/nested/subdir.yaml": GOOD_FILE,
199
            "subdir2/.yamllint": RELAXED_CONFIG,
200
            "subdir2/subdir.yaml": GOOD_FILE,
201
            "not_yaml": NOT_YAML,
202
        }
203
    )
204
    results = run_yamllint(
×
205
        rule_runner,
206
        extra_args=["--yamllint-args=-s"],
207
        expected_partitions=(
208
            ("test.yaml",),
209
            {
210
                "subdir1/.yamllint": ("subdir1/nested/subdir.yaml", "subdir1/subdir.yaml"),
211
                "subdir2/.yamllint": ("subdir2/subdir.yaml",),
212
            },
213
        ),
214
    )
215
    assert len(results) == 3
×
216
    for result in results:
×
217
        assert result.exit_code == 0
×
218
        assert not result.stdout
×
219
        assert not result.stderr
×
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