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

pantsbuild / pants / 19250292619

11 Nov 2025 12:09AM UTC coverage: 77.865% (-2.4%) from 80.298%
19250292619

push

github

web-flow
flag non-runnable targets used with `code_quality_tool` (#22875)

2 of 5 new or added lines in 2 files covered. (40.0%)

1487 existing lines in 72 files now uncovered.

71448 of 91759 relevant lines covered (77.86%)

3.22 hits per line

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

88.24
/src/python/pants/backend/python/goals/repl_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
2✔
5

6
from textwrap import dedent
2✔
7

8
import pytest
2✔
9

10
from pants.backend.codegen.protobuf.target_types import ProtobufSourceTarget
2✔
11
from pants.backend.python.goals import repl as python_repl
2✔
12
from pants.backend.python.target_types import (
2✔
13
    PythonRequirementTarget,
14
    PythonSourcesGeneratorTarget,
15
    PythonSourceTarget,
16
)
17
from pants.backend.python.target_types_rules import rules as target_types_rules
2✔
18
from pants.backend.python.util_rules import local_dists, pex_from_targets
2✔
19
from pants.backend.python.util_rules.pex import PexProcess
2✔
20
from pants.core.goals.generate_lockfiles import NoCompatibleResolveException
2✔
21
from pants.core.goals.repl import Repl
2✔
22
from pants.core.goals.repl import rules as repl_rules
2✔
23
from pants.engine.process import Process
2✔
24
from pants.testutil.python_interpreter_selection import all_major_minor_python_versions
2✔
25
from pants.testutil.python_rule_runner import PythonRuleRunner
2✔
26
from pants.testutil.rule_runner import GoalRuleResult, QueryRule, engine_error, mock_console
2✔
27

28

29
@pytest.fixture
2✔
30
def rule_runner() -> PythonRuleRunner:
2✔
31
    rule_runner = PythonRuleRunner(
2✔
32
        rules=[
33
            *repl_rules(),
34
            *python_repl.rules(),
35
            *pex_from_targets.rules(),
36
            *local_dists.rules(),
37
            *target_types_rules(),
38
            QueryRule(Process, (PexProcess,)),
39
        ],
40
        target_types=[
41
            PythonSourcesGeneratorTarget,
42
            ProtobufSourceTarget,
43
            PythonSourceTarget,
44
            PythonRequirementTarget,
45
        ],
46
    )
47
    rule_runner.write_files(
2✔
48
        {
49
            "src/python/foo.proto": 'syntax = "proto3";message Foo {}',
50
            "src/python/lib.py": "from foo import Foo\nclass SomeClass:\n  pass\n",
51
            "src/python/BUILD": dedent(
52
                """\
53
                protobuf_source(name='proto', source='foo.proto')
54
                python_sources(dependencies=[':proto'])
55
                """
56
            ),
57
        }
58
    )
59
    return rule_runner
2✔
60

61

62
def run_repl(
2✔
63
    rule_runner: PythonRuleRunner, args: list[str], *, global_args: list[str] | None = None
64
) -> GoalRuleResult:
65
    # TODO(#9108): Expand `mock_console` to allow for providing input for the repl to verify
66
    # that, e.g., the generated protobuf code is available. Right now this test prepares for
67
    # that by including generated code, but cannot actually verify it.
68
    with mock_console(rule_runner.options_bootstrapper):
2✔
69
        return rule_runner.run_goal_rule(
2✔
70
            Repl,
71
            global_args=global_args or (),
72
            args=args,
73
            env_inherit={"PATH", "PYENV_ROOT", "HOME"},
74
        )
75

76

77
def test_default_repl(rule_runner: PythonRuleRunner) -> None:
2✔
UNCOV
78
    assert run_repl(rule_runner, ["src/python/lib.py"]).exit_code == 0
×
79

80

81
@pytest.mark.platform_specific_behavior
2✔
82
@pytest.mark.parametrize(
2✔
83
    "major_minor_interpreter",
84
    all_major_minor_python_versions(["CPython>=3.9,<4"]),
85
)
86
def test_ipython(rule_runner: PythonRuleRunner, major_minor_interpreter: str) -> None:
2✔
87
    assert (
2✔
88
        run_repl(
89
            rule_runner,
90
            ["src/python/lib.py"],
91
            global_args=[
92
                "--repl-shell=ipython",
93
                f"--python-interpreter-constraints=['=={major_minor_interpreter}.*']",
94
            ],
95
        ).exit_code
96
        == 0
97
    )
98

99

100
def test_eagerly_validate_roots_have_common_resolve(rule_runner: PythonRuleRunner) -> None:
2✔
UNCOV
101
    rule_runner.write_files(
×
102
        {
103
            "BUILD": dedent(
104
                """\
105
                python_requirement(name='t1', requirements=[], resolve='a')
106
                python_source(name='t2', source='f.py', resolve='b')
107
                """
108
            )
109
        }
110
    )
UNCOV
111
    with engine_error(NoCompatibleResolveException, contains="pants peek"):
×
UNCOV
112
        run_repl(
×
113
            rule_runner,
114
            ["//:t1", "//:t2"],
115
            global_args=["--python-resolves={'a': '', 'b': ''}", "--python-enable-resolves"],
116
        )
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

© 2025 Coveralls, Inc