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

pantsbuild / pants / 19015773527

02 Nov 2025 05:33PM UTC coverage: 17.872% (-62.4%) from 80.3%
19015773527

Pull #22816

github

web-flow
Merge a12d75757 into 6c024e162
Pull Request #22816: Update Pants internal Python to 3.14

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

28452 existing lines in 683 files now uncovered.

9831 of 55007 relevant lines covered (17.87%)

0.18 hits per line

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

0.0
/src/python/pants/backend/go/util_rules/tests_analysis.py
1
# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
UNCOV
3
from __future__ import annotations
×
4

UNCOV
5
import json
×
UNCOV
6
from dataclasses import dataclass
×
7

UNCOV
8
from pants.backend.go.go_sources import load_go_binary
×
UNCOV
9
from pants.backend.go.go_sources.load_go_binary import LoadedGoBinaryRequest, setup_go_binary
×
UNCOV
10
from pants.engine.addresses import Address
×
UNCOV
11
from pants.engine.engine_aware import EngineAwareParameter
×
UNCOV
12
from pants.engine.fs import Digest, MergeDigests
×
UNCOV
13
from pants.engine.internals.native_engine import EMPTY_DIGEST
×
UNCOV
14
from pants.engine.intrinsics import execute_process, merge_digests
×
UNCOV
15
from pants.engine.process import Process
×
UNCOV
16
from pants.engine.rules import collect_rules, implicitly, rule
×
UNCOV
17
from pants.util.logging import LogLevel
×
UNCOV
18
from pants.util.ordered_set import FrozenOrderedSet
×
19

20

UNCOV
21
@dataclass(frozen=True)
×
UNCOV
22
class GenerateTestMainRequest(EngineAwareParameter):
×
UNCOV
23
    digest: Digest
×
UNCOV
24
    test_paths: FrozenOrderedSet[str]
×
UNCOV
25
    xtest_paths: FrozenOrderedSet[str]
×
UNCOV
26
    import_path: str
×
UNCOV
27
    register_cover: bool
×
UNCOV
28
    address: Address
×
29

UNCOV
30
    def debug_hint(self) -> str:
×
31
        return self.address.spec
×
32

33

UNCOV
34
@dataclass(frozen=True)
×
UNCOV
35
class GeneratedTestMain:
×
UNCOV
36
    digest: Digest
×
UNCOV
37
    has_tests: bool
×
UNCOV
38
    has_xtests: bool
×
UNCOV
39
    failed_exit_code_and_stderr: tuple[int, str] | None
×
40

UNCOV
41
    TEST_MAIN_FILE = "testmain.go"
×
UNCOV
42
    TEST_PKG = "_test"
×
UNCOV
43
    XTEST_PKG = "_xtest"
×
44

45

UNCOV
46
@rule
×
UNCOV
47
async def generate_testmain(request: GenerateTestMainRequest) -> GeneratedTestMain:
×
48
    generator_binary_name = "./generator"
×
49
    analyzer = await setup_go_binary(
×
50
        LoadedGoBinaryRequest("generate_testmain", ("main.go",), generator_binary_name),
51
        **implicitly(),
52
    )
53
    input_digest = await merge_digests(MergeDigests([request.digest, analyzer.digest]))
×
54

55
    test_paths = tuple(f"{GeneratedTestMain.TEST_PKG}:{path}" for path in request.test_paths)
×
56
    xtest_paths = tuple(f"{GeneratedTestMain.XTEST_PKG}:{path}" for path in request.xtest_paths)
×
57

58
    env = {}
×
59
    if request.register_cover:
×
60
        env["GENERATE_COVER"] = "1"
×
61

62
    result = await execute_process(
×
63
        Process(
64
            argv=(
65
                generator_binary_name,
66
                GeneratedTestMain.TEST_MAIN_FILE,
67
                request.import_path,
68
                *test_paths,
69
                *xtest_paths,
70
            ),
71
            input_digest=input_digest,
72
            env=env,
73
            description=f"Analyze Go test sources for {request.address}",
74
            level=LogLevel.DEBUG,
75
            output_files=(GeneratedTestMain.TEST_MAIN_FILE,),
76
        ),
77
        **implicitly(),
78
    )
79

80
    if result.exit_code != 0:
×
81
        return GeneratedTestMain(
×
82
            digest=EMPTY_DIGEST,
83
            has_tests=False,
84
            has_xtests=False,
85
            failed_exit_code_and_stderr=(result.exit_code, result.stderr.decode("utf-8")),
86
        )
87

88
    metadata = json.loads(result.stdout.decode("utf-8"))
×
89
    return GeneratedTestMain(
×
90
        digest=result.output_digest,
91
        has_tests=metadata["has_tests"],
92
        has_xtests=metadata["has_xtests"],
93
        failed_exit_code_and_stderr=None,
94
    )
95

96

UNCOV
97
def rules():
×
UNCOV
98
    return (*collect_rules(), *load_go_binary.rules())
×
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