xref: /aosp_15_r20/external/bazelbuild-rules_python/tests/support/py_info_subject.bzl (revision 60517a1edbc8ecf509223e9af94a7adec7d736b8)
1# Copyright 2023 The Bazel Authors. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#    http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""PyInfo testing subject."""
15
16load("@rules_testing//lib:truth.bzl", "subjects")
17
18def py_info_subject(info, *, meta):
19    """Creates a new `PyInfoSubject` for a PyInfo provider instance.
20
21    Method: PyInfoSubject.new
22
23    Args:
24        info: The PyInfo object
25        meta: ExpectMeta object.
26
27    Returns:
28        A `PyInfoSubject` struct
29    """
30
31    # buildifier: disable=uninitialized
32    public = struct(
33        # go/keep-sorted start
34        direct_pyc_files = lambda *a, **k: _py_info_subject_direct_pyc_files(self, *a, **k),
35        has_py2_only_sources = lambda *a, **k: _py_info_subject_has_py2_only_sources(self, *a, **k),
36        has_py3_only_sources = lambda *a, **k: _py_info_subject_has_py3_only_sources(self, *a, **k),
37        imports = lambda *a, **k: _py_info_subject_imports(self, *a, **k),
38        transitive_pyc_files = lambda *a, **k: _py_info_subject_transitive_pyc_files(self, *a, **k),
39        transitive_sources = lambda *a, **k: _py_info_subject_transitive_sources(self, *a, **k),
40        uses_shared_libraries = lambda *a, **k: _py_info_subject_uses_shared_libraries(self, *a, **k),
41        # go/keep-sorted end
42    )
43    self = struct(
44        actual = info,
45        meta = meta,
46    )
47    return public
48
49def _py_info_subject_direct_pyc_files(self):
50    """Returns a `DepsetFileSubject` for the `direct_pyc_files` attribute.
51
52    Method: PyInfoSubject.direct_pyc_files
53    """
54    return subjects.depset_file(
55        self.actual.direct_pyc_files,
56        meta = self.meta.derive("direct_pyc_files()"),
57    )
58
59def _py_info_subject_has_py2_only_sources(self):
60    """Returns a `BoolSubject` for the `has_py2_only_sources` attribute.
61
62    Method: PyInfoSubject.has_py2_only_sources
63    """
64    return subjects.bool(
65        self.actual.has_py2_only_sources,
66        meta = self.meta.derive("has_py2_only_sources()"),
67    )
68
69def _py_info_subject_has_py3_only_sources(self):
70    """Returns a `BoolSubject` for the `has_py3_only_sources` attribute.
71
72    Method: PyInfoSubject.has_py3_only_sources
73    """
74    return subjects.bool(
75        self.actual.has_py3_only_sources,
76        meta = self.meta.derive("has_py3_only_sources()"),
77    )
78
79def _py_info_subject_imports(self):
80    """Returns a `CollectionSubject` for the `imports` attribute.
81
82    Method: PyInfoSubject.imports
83    """
84    return subjects.collection(
85        self.actual.imports.to_list(),
86        meta = self.meta.derive("imports()"),
87    )
88
89def _py_info_subject_transitive_pyc_files(self):
90    """Returns a `DepsetFileSubject` for the `transitive_pyc_files` attribute.
91
92    Method: PyInfoSubject.transitive_pyc_files
93    """
94    return subjects.depset_file(
95        self.actual.transitive_pyc_files,
96        meta = self.meta.derive("transitive_pyc_files()"),
97    )
98
99def _py_info_subject_transitive_sources(self):
100    """Returns a `DepsetFileSubject` for the `transitive_sources` attribute.
101
102    Method: PyInfoSubject.transitive_sources
103    """
104    return subjects.depset_file(
105        self.actual.transitive_sources,
106        meta = self.meta.derive("transitive_sources()"),
107    )
108
109def _py_info_subject_uses_shared_libraries(self):
110    """Returns a `BoolSubject` for the `uses_shared_libraries` attribute.
111
112    Method: PyInfoSubject.uses_shared_libraries
113    """
114    return subjects.bool(
115        self.actual.uses_shared_libraries,
116        meta = self.meta.derive("uses_shared_libraries()"),
117    )
118