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"""PyRuntimeInfo testing subject.""" 15 16load("@rules_testing//lib:truth.bzl", "subjects") 17 18def py_runtime_info_subject(info, *, meta): 19 """Creates a new `PyRuntimeInfoSubject` for a PyRuntimeInfo provider instance. 20 21 Method: PyRuntimeInfoSubject.new 22 23 Args: 24 info: The PyRuntimeInfo object 25 meta: ExpectMeta object. 26 27 Returns: 28 A `PyRuntimeInfoSubject` struct 29 """ 30 31 # buildifier: disable=uninitialized 32 public = struct( 33 # go/keep-sorted start 34 actual = info, 35 bootstrap_template = lambda *a, **k: _py_runtime_info_subject_bootstrap_template(self, *a, **k), 36 coverage_files = lambda *a, **k: _py_runtime_info_subject_coverage_files(self, *a, **k), 37 coverage_tool = lambda *a, **k: _py_runtime_info_subject_coverage_tool(self, *a, **k), 38 files = lambda *a, **k: _py_runtime_info_subject_files(self, *a, **k), 39 interpreter = lambda *a, **k: _py_runtime_info_subject_interpreter(self, *a, **k), 40 interpreter_path = lambda *a, **k: _py_runtime_info_subject_interpreter_path(self, *a, **k), 41 interpreter_version_info = lambda *a, **k: _py_runtime_info_subject_interpreter_version_info(self, *a, **k), 42 python_version = lambda *a, **k: _py_runtime_info_subject_python_version(self, *a, **k), 43 stub_shebang = lambda *a, **k: _py_runtime_info_subject_stub_shebang(self, *a, **k), 44 # go/keep-sorted end 45 ) 46 self = struct( 47 actual = info, 48 meta = meta, 49 ) 50 return public 51 52def _py_runtime_info_subject_bootstrap_template(self): 53 return subjects.file( 54 self.actual.bootstrap_template, 55 meta = self.meta.derive("bootstrap_template()"), 56 ) 57 58def _py_runtime_info_subject_coverage_files(self): 59 """Returns a `DepsetFileSubject` for the `coverage_files` attribute. 60 61 Args: 62 self: implicitly added. 63 """ 64 return subjects.depset_file( 65 self.actual.coverage_files, 66 meta = self.meta.derive("coverage_files()"), 67 ) 68 69def _py_runtime_info_subject_coverage_tool(self): 70 return subjects.file( 71 self.actual.coverage_tool, 72 meta = self.meta.derive("coverage_tool()"), 73 ) 74 75def _py_runtime_info_subject_files(self): 76 return subjects.depset_file( 77 self.actual.files, 78 meta = self.meta.derive("files()"), 79 ) 80 81def _py_runtime_info_subject_interpreter(self): 82 return subjects.file( 83 self.actual.interpreter, 84 meta = self.meta.derive("interpreter()"), 85 ) 86 87def _py_runtime_info_subject_interpreter_path(self): 88 return subjects.str( 89 self.actual.interpreter_path, 90 meta = self.meta.derive("interpreter_path()"), 91 ) 92 93def _py_runtime_info_subject_python_version(self): 94 return subjects.str( 95 self.actual.python_version, 96 meta = self.meta.derive("python_version()"), 97 ) 98 99def _py_runtime_info_subject_stub_shebang(self): 100 return subjects.str( 101 self.actual.stub_shebang, 102 meta = self.meta.derive("stub_shebang()"), 103 ) 104 105def _py_runtime_info_subject_interpreter_version_info(self): 106 return subjects.struct( 107 self.actual.interpreter_version_info, 108 attrs = dict( 109 major = subjects.int, 110 minor = subjects.int, 111 micro = subjects.int, 112 releaselevel = subjects.str, 113 serial = subjects.int, 114 ), 115 meta = self.meta.derive("interpreter_version_info()"), 116 ) 117