• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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        has_py2_only_sources = lambda *a, **k: _py_info_subject_has_py2_only_sources(self, *a, **k),
35        has_py3_only_sources = lambda *a, **k: _py_info_subject_has_py3_only_sources(self, *a, **k),
36        imports = lambda *a, **k: _py_info_subject_imports(self, *a, **k),
37        transitive_sources = lambda *a, **k: _py_info_subject_transitive_sources(self, *a, **k),
38        uses_shared_libraries = lambda *a, **k: _py_info_subject_uses_shared_libraries(self, *a, **k),
39        # go/keep-sorted end
40    )
41    self = struct(
42        actual = info,
43        meta = meta,
44    )
45    return public
46
47def _py_info_subject_has_py2_only_sources(self):
48    """Returns a `BoolSubject` for the `has_py2_only_sources` attribute.
49
50    Method: PyInfoSubject.has_py2_only_sources
51    """
52    return subjects.bool(
53        self.actual.has_py2_only_sources,
54        meta = self.meta.derive("has_py2_only_sources()"),
55    )
56
57def _py_info_subject_has_py3_only_sources(self):
58    """Returns a `BoolSubject` for the `has_py3_only_sources` attribute.
59
60    Method: PyInfoSubject.has_py3_only_sources
61    """
62    return subjects.bool(
63        self.actual.has_py3_only_sources,
64        meta = self.meta.derive("has_py3_only_sources()"),
65    )
66
67def _py_info_subject_imports(self):
68    """Returns a `CollectionSubject` for the `imports` attribute.
69
70    Method: PyInfoSubject.imports
71    """
72    return subjects.collection(
73        self.actual.imports,
74        meta = self.meta.derive("imports()"),
75    )
76
77def _py_info_subject_transitive_sources(self):
78    """Returns a `DepsetFileSubject` for the `transitive_sources` attribute.
79
80    Method: PyInfoSubject.transitive_sources
81    """
82    return subjects.depset_file(
83        self.actual.transitive_sources,
84        meta = self.meta.derive("transitive_sources()"),
85    )
86
87def _py_info_subject_uses_shared_libraries(self):
88    """Returns a `BoolSubject` for the `uses_shared_libraries` attribute.
89
90    Method: PyInfoSubject.uses_shared_libraries
91    """
92    return subjects.bool(
93        self.actual.uses_shared_libraries,
94        meta = self.meta.derive("uses_shared_libraries()"),
95    )
96