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

pantsbuild / pants / 21832085155

09 Feb 2026 03:53PM UTC coverage: 70.203% (-10.1%) from 80.282%
21832085155

push

github

web-flow
Prepare 2.30.2rc0 (#23079)

56068 of 79865 relevant lines covered (70.2%)

2.05 hits per line

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

88.57
/src/python/pants/backend/kotlin/dependency_inference/kotlin_parser_test.py
1
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3
from __future__ import annotations
1✔
4

5
import textwrap
1✔
6

7
import pytest
1✔
8

9
from pants.backend.kotlin import target_types
1✔
10
from pants.backend.kotlin.dependency_inference import kotlin_parser
1✔
11
from pants.backend.kotlin.dependency_inference.kotlin_parser import (
1✔
12
    KotlinImport,
13
    KotlinSourceDependencyAnalysis,
14
)
15
from pants.backend.kotlin.target_types import KotlinSourceField, KotlinSourceTarget
1✔
16
from pants.build_graph.address import Address
1✔
17
from pants.core.util_rules import source_files
1✔
18
from pants.core.util_rules.source_files import SourceFiles, SourceFilesRequest
1✔
19
from pants.engine.rules import QueryRule
1✔
20
from pants.engine.target import SourcesField
1✔
21
from pants.jvm import jdk_rules
1✔
22
from pants.jvm import util_rules as jvm_util_rules
1✔
23
from pants.jvm.resolve import jvm_tool
1✔
24
from pants.testutil.rule_runner import PYTHON_BOOTSTRAP_ENV, RuleRunner, logging
1✔
25
from pants.util.frozendict import FrozenDict
1✔
26

27

28
@pytest.fixture
1✔
29
def rule_runner() -> RuleRunner:
1✔
30
    rule_runner = RuleRunner(
1✔
31
        rules=[
32
            *kotlin_parser.rules(),
33
            *jvm_tool.rules(),
34
            *source_files.rules(),
35
            *jdk_rules.rules(),
36
            *target_types.rules(),
37
            *jvm_util_rules.rules(),
38
            QueryRule(SourceFiles, (SourceFilesRequest,)),
39
            QueryRule(KotlinSourceDependencyAnalysis, (SourceFiles,)),
40
        ],
41
        target_types=[KotlinSourceTarget],
42
    )
43
    rule_runner.set_options(args=[], env_inherit=PYTHON_BOOTSTRAP_ENV)
1✔
44
    return rule_runner
1✔
45

46

47
def _analyze(rule_runner: RuleRunner, source: str) -> KotlinSourceDependencyAnalysis:
1✔
48
    rule_runner.write_files(
1✔
49
        {
50
            "BUILD": """kotlin_source(name="source", source="Source.kt")""",
51
            "Source.kt": source,
52
        }
53
    )
54

55
    target = rule_runner.get_target(address=Address("", target_name="source"))
1✔
56

57
    source_files = rule_runner.request(
1✔
58
        SourceFiles,
59
        [
60
            SourceFilesRequest(
61
                (target.get(SourcesField),),
62
                for_sources_types=(KotlinSourceField,),
63
                enable_codegen=True,
64
            )
65
        ],
66
    )
67

68
    return rule_runner.request(KotlinSourceDependencyAnalysis, [source_files])
1✔
69

70

71
@logging
1✔
72
@pytest.mark.platform_specific_behavior
1✔
73
def test_parser_simple(rule_runner: RuleRunner) -> None:
1✔
74
    analysis = _analyze(
1✔
75
        rule_runner,
76
        textwrap.dedent(
77
            """\
78
            package org.pantsbuild.backend.kotlin
79

80
            import java.io.File
81

82
            open class Foo {
83
              fun grok() {
84
                val x = X()
85
                val y = Y()
86
              }
87
            }
88

89
            class Bar {}
90

91
            fun main(args: Array<String>) {
92
            }
93
            """
94
        ),
95
    )
96

97
    assert analysis.imports == {KotlinImport(name="java.io.File", alias=None, is_wildcard=False)}
×
98
    assert analysis.named_declarations == {
×
99
        "org.pantsbuild.backend.kotlin.Bar",
100
        "org.pantsbuild.backend.kotlin.Foo",
101
        "org.pantsbuild.backend.kotlin.main",
102
    }
103
    assert analysis.consumed_symbols_by_scope == FrozenDict(
×
104
        {
105
            "org.pantsbuild.backend.kotlin.Foo": frozenset(
106
                {
107
                    "X",
108
                    "Y",
109
                }
110
            ),
111
            "org.pantsbuild.backend.kotlin": frozenset(
112
                {
113
                    "Array",
114
                    "String",
115
                }
116
            ),
117
        }
118
    )
119
    assert analysis.scopes == {
×
120
        "org.pantsbuild.backend.kotlin",
121
        "org.pantsbuild.backend.kotlin.Foo",
122
        "org.pantsbuild.backend.kotlin.Bar",
123
    }
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