# Copyright 2010-2025 Google LLC # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Macros to test binaries.""" load("@pip_deps//:requirements.bzl", "requirement") load("@rules_python//python:py_test.bzl", "py_test") def _get_path(label): """Returns the path of a label.""" # According to https://bazel.build/reference/be/make-variables#predefined_label_variables # `rootpath` may fail to work for non C++ binaries. As an alternative if such an issue comes # up we can create the absolute path manually from the label. return "$(rootpath %s)" % label def _get_env(named_data): """Returns the environment variables to pass to the test.""" return { "BINTEST_" + key: _get_path(label) for key, label in named_data.items() } def py_bintest(named_data, env = {}, deps = [], **kwargs): """Runs a Python test that can access data binaries. Args: named_data: A dictionary mapping names to data labels. The test will be able to access the path of each data label using the `$(