|
| 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 | +"""Starlark tests for PyRuntimeInfo provider.""" |
| 15 | + |
| 16 | +load("@rules_testing//lib:analysis_test.bzl", "analysis_test") |
| 17 | +load("@rules_testing//lib:test_suite.bzl", "test_suite") |
| 18 | +load("//python:py_runtime_info.bzl", "PyRuntimeInfo") |
| 19 | + |
| 20 | +def _create_py_runtime_info_without_interpreter_version_info_impl(ctx): |
| 21 | + return [PyRuntimeInfo( |
| 22 | + interpreter = ctx.file.interpreter, |
| 23 | + files = depset(ctx.files.files), |
| 24 | + python_version = "PY3", |
| 25 | + bootstrap_template = ctx.attr.bootstrap_template, |
| 26 | + )] |
| 27 | + |
| 28 | +_create_py_runtime_info_without_interpreter_version_info = rule( |
| 29 | + implementation = _create_py_runtime_info_without_interpreter_version_info_impl, |
| 30 | + attrs = { |
| 31 | + "interpreter": attr.label(allow_single_file = True, default = "interpreter.sh"), |
| 32 | + "files": attr.label_list(allow_files = True, default = ["data.txt"]), |
| 33 | + "python_version": attr.string(default = "PY3"), |
| 34 | + "bootstrap_template": attr.label(allow_single_file = True, default = "bootstrap.txt"), |
| 35 | + }, |
| 36 | +) |
| 37 | + |
| 38 | +_tests = [] |
| 39 | + |
| 40 | +def _test_can_create_py_runtime_info_without_interpreter_version_info(name): |
| 41 | + _create_py_runtime_info_without_interpreter_version_info( |
| 42 | + name = name + "_subject", |
| 43 | + ) |
| 44 | + analysis_test( |
| 45 | + name = name, |
| 46 | + target = name + "_subject", |
| 47 | + impl = _test_can_create_py_runtime_info_without_interpreter_version_info_impl, |
| 48 | + ) |
| 49 | + |
| 50 | +def _test_can_create_py_runtime_info_without_interpreter_version_info_impl(env, target): |
| 51 | + pass |
| 52 | + |
| 53 | +_tests.append(_test_can_create_py_runtime_info_without_interpreter_version_info) |
| 54 | + |
| 55 | +def py_runtime_info_test_suite(name): |
| 56 | + test_suite( |
| 57 | + name = name, |
| 58 | + tests = _tests, |
| 59 | + ) |
0 commit comments