xref: /aosp_15_r20/external/bazelbuild-rules_python/tests/support/py_executable_info_subject.bzl (revision 60517a1edbc8ecf509223e9af94a7adec7d736b8)
1# Copyright 2024 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"""PyExecutableInfo testing subject."""
15
16load("@rules_testing//lib:truth.bzl", "subjects")
17
18def _py_executable_info_subject_new(info, *, meta):
19    """Creates a new `PyExecutableInfoSubject` for a PyExecutableInfo provider instance.
20
21    Method: PyExecutableInfoSubject.new
22
23    Args:
24        info: The PyExecutableInfo object
25        meta: ExpectMeta object.
26
27    Returns:
28        A `PyExecutableInfoSubject` struct
29    """
30
31    # buildifier: disable=uninitialized
32    public = struct(
33        # go/keep-sorted start
34        actual = info,
35        interpreter_path = lambda *a, **k: _py_executable_info_subject_interpreter_path(self, *a, **k),
36        main = lambda *a, **k: _py_executable_info_subject_main(self, *a, **k),
37        runfiles_without_exe = lambda *a, **k: _py_executable_info_subject_runfiles_without_exe(self, *a, **k),
38        # go/keep-sorted end
39    )
40    self = struct(
41        actual = info,
42        meta = meta,
43    )
44    return public
45
46def _py_executable_info_subject_interpreter_path(self):
47    """Returns a subject for `PyExecutableInfo.interpreter_path`."""
48    return subjects.str(
49        self.actual.interpreter_path,
50        meta = self.meta.derive("interpreter_path()"),
51    )
52
53def _py_executable_info_subject_main(self):
54    """Returns a subject for `PyExecutableInfo.main`."""
55    return subjects.file(
56        self.actual.main,
57        meta = self.meta.derive("main()"),
58    )
59
60def _py_executable_info_subject_runfiles_without_exe(self):
61    """Returns a subject for `PyExecutableInfo.runfiles_without_exe`."""
62    return subjects.runfiles(
63        self.actual.runfiles_without_exe,
64        meta = self.meta.derive("runfiles_without_exe()"),
65    )
66
67# buildifier: disable=name-conventions
68PyExecutableInfoSubject = struct(
69    new = _py_executable_info_subject_new,
70)
71