Skip to content

Commit

Permalink
python: delete overly strict and defunct tests
Browse files Browse the repository at this point in the history
These tests fail when run with rules_python 0.33+, but ultimately
can be deleted since they're either overly strict or unnecessary

* hermeticRuntime: overly strict test. It fails because it doesn't expect
  the interpreter executable to also be returned in the files, which was a
  bug fix rules_python made. This test was also ported to rules_python.
* versionAttributeMandatoryWhenUsingToolchains: defunct test. With
  Python 2 support removed, requiring the attribute is no longer necessary.
* runtimeSandwich: overly strict and defunct test. Looking at the origin of it, it main
  purpose is verifying the Starlark PyRuntimeInfo symbol was available. Lots
  of code relies on that, and the symbol is moved to rules_python, so no need
  to test this in Bazel itself.

PiperOrigin-RevId: 645118335
Change-Id: I971c1d4350f81e4b39e7e442da00aac4efb80fda
  • Loading branch information
rickeylev authored and copybara-github committed Jun 20, 2024
1 parent 0e220f0 commit 27423f4
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.rules.python.PythonTestUtils.getPyLoad;

import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -33,25 +32,6 @@ public final void setUpPython() throws Exception {
analysisMock.pySupport().setup(mockToolsConfig);
}

@Test
public void hermeticRuntime() throws Exception {
scratch.file(
"pkg/BUILD",
getPyLoad("py_runtime"),
"py_runtime(",
" name = 'myruntime',",
" files = [':myfile'],",
" interpreter = ':myinterpreter',",
" python_version = 'PY3',",
")");
PyRuntimeInfo info = PyRuntimeInfo.fromTarget(getConfiguredTarget("//pkg:myruntime"));

assertThat(info.getInterpreterPathString()).isNull();
assertThat(info.getInterpreter().getExecPathString()).isEqualTo("pkg/myinterpreter");
assertThat(ActionsTestUtil.baseArtifactNames(info.getFiles())).containsExactly("myfile");
assertThat(info.getPythonVersion()).isEqualTo(PythonVersion.PY3);
}

@Test
public void nonhermeticRuntime() throws Exception {
scratch.file(
Expand Down Expand Up @@ -177,20 +157,4 @@ public void badPythonVersionAttribute() throws Exception {

assertContainsEvent("invalid value in 'python_version' attribute");
}

@Test
public void versionAttributeMandatoryWhenUsingToolchains() throws Exception {
reporter.removeHandler(failFastHandler);
useConfiguration("--incompatible_use_python_toolchains=true");
scratch.file(
"pkg/BUILD",
getPyLoad("py_runtime"),
"py_runtime(",
" name = 'myruntime',",
" interpreter_path = '/system/interpreter',",
")");
getConfiguredTarget("//pkg:myruntime");

assertContainsEvent("must be set explicitly to either 'PY2' or 'PY3'");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
import com.google.devtools.build.lib.testutil.TestConstants;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand Down Expand Up @@ -113,67 +112,4 @@ public void librarySandwich() throws Exception {
assertThat(info.getHasPy2OnlySources()).isTrue();
assertThat(info.getHasPy3OnlySources()).isTrue();
}

@Test
public void runtimeSandwich() throws Exception {
scratch.file(
"pkg/rules.bzl",
getPyLoad("PyRuntimeInfo"),
"def _userruntime_impl(ctx):",
" info = ctx.attr.runtime[PyRuntimeInfo]",
" return [PyRuntimeInfo(",
" interpreter = ctx.file.interpreter,",
" files = depset(direct = ctx.files.files, transitive=[info.files]),",
" python_version = info.python_version,",
" bootstrap_template = ctx.file.bootstrap_template)]",
"",
"userruntime = rule(",
" implementation = _userruntime_impl,",
" attrs = {",
" 'runtime': attr.label(),",
" 'interpreter': attr.label(allow_single_file=True),",
" 'files': attr.label_list(allow_files=True),",
" 'bootstrap_template': attr.label(allow_single_file=True),",
" },",
")");
scratch.file(
"pkg/BUILD",
getPyLoad("py_binary"),
getPyLoad("py_runtime"),
getPyLoad("py_runtime_pair"),
"load(':rules.bzl', 'userruntime')",
"py_runtime(",
" name = 'pyruntime',",
" interpreter = ':intr',",
" files = ['data.txt'],",
" python_version = 'PY3',",
")",
"userruntime(",
" name = 'userruntime',",
" runtime = ':pyruntime',",
" interpreter = ':userintr',",
" files = ['userdata.txt'],",
" bootstrap_template = 'bootstrap.txt',",
")",
"py_runtime_pair(",
" name = 'userruntime_pair',",
" py3_runtime = 'userruntime',",
")",
"toolchain(",
" name = 'usertoolchain',",
" toolchain = ':userruntime_pair',",
" toolchain_type = '"
+ TestConstants.TOOLS_REPOSITORY
+ "//tools/python:toolchain_type',",
")",
"py_binary(",
" name = 'pybin',",
" srcs = ['pybin.py'],",
")");
useConfiguration(
"--extra_toolchains=//pkg:usertoolchain", "--incompatible_use_python_toolchains=true");
ConfiguredTarget target = getConfiguredTarget("//pkg:pybin");
assertThat(collectRunfiles(target).toList())
.containsAtLeast(getSourceArtifact("pkg/data.txt"), getSourceArtifact("pkg/userdata.txt"));
}
}

0 comments on commit 27423f4

Please sign in to comment.