Default analysis tests to use Python 3
This matches the behavior outside of the tests.
Work towards #7903
PiperOrigin-RevId: 452140874
Change-Id: Icab37d01657b07ef6f56366a1e0b64f0f3d26c29
diff --git a/src/test/java/com/google/devtools/build/lib/buildtool/CompileOneDependencyIntegrationTest.java b/src/test/java/com/google/devtools/build/lib/buildtool/CompileOneDependencyIntegrationTest.java
index b120d13..ac1ab8f 100644
--- a/src/test/java/com/google/devtools/build/lib/buildtool/CompileOneDependencyIntegrationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/buildtool/CompileOneDependencyIntegrationTest.java
@@ -39,7 +39,6 @@
addOptions("--compile_one_dependency");
// Make build super minimal.
addOptions("--nobuild_runfile_links");
-
write("package/BUILD", "py_binary(name='foo', srcs=['foo.py'])");
write("package/foo.py");
buildTarget("package/foo.py");
diff --git a/src/test/java/com/google/devtools/build/lib/rules/python/PyBaseConfiguredTargetTestBase.java b/src/test/java/com/google/devtools/build/lib/rules/python/PyBaseConfiguredTargetTestBase.java
index 3f7452b..5f1ec40 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/python/PyBaseConfiguredTargetTestBase.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/python/PyBaseConfiguredTargetTestBase.java
@@ -15,7 +15,6 @@
package com.google.devtools.build.lib.rules.python;
import static com.google.common.truth.Truth.assertThat;
-import static com.google.devtools.build.lib.rules.python.PythonTestUtils.assumesDefaultIsPY2;
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
@@ -68,14 +67,13 @@
}
@Test
- public void versionIs2IfUnspecified() throws Exception {
- assumesDefaultIsPY2();
+ public void versionIs3IfUnspecified() throws Exception {
scratch.file(
"pkg/BUILD", //
ruleName + "(",
" name = 'foo',",
" srcs = ['foo.py'])");
- assertThat(getPythonVersion(getConfiguredTarget("//pkg:foo"))).isEqualTo(PythonVersion.PY2);
+ assertThat(getPythonVersion(getConfiguredTarget("//pkg:foo"))).isEqualTo(PythonVersion.PY3);
}
@Test
diff --git a/src/test/java/com/google/devtools/build/lib/rules/python/PyRuntimeConfiguredTargetTest.java b/src/test/java/com/google/devtools/build/lib/rules/python/PyRuntimeConfiguredTargetTest.java
index d3b4530..cef3adc 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/python/PyRuntimeConfiguredTargetTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/python/PyRuntimeConfiguredTargetTest.java
@@ -15,7 +15,6 @@
package com.google.devtools.build.lib.rules.python;
import static com.google.common.truth.Truth.assertThat;
-import static com.google.devtools.build.lib.rules.python.PythonTestUtils.assumesDefaultIsPY2;
import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
@@ -72,27 +71,26 @@
@Test
public void pythonVersionDefault() throws Exception {
- assumesDefaultIsPY2();
// When using toolchains, the python_version attribute is mandatory.
useConfiguration("--incompatible_use_python_toolchains=false");
scratch.file(
"pkg/BUILD",
"py_runtime(",
" name = 'myruntime_default',",
- " interpreter_path = '/system/interpreter',",
+ " interpreter_path = '/default/interpreter',",
")",
"py_runtime(",
" name = 'myruntime_explicit',",
- " interpreter_path = '/system/interpreter',",
- " python_version = 'PY3',",
+ " interpreter_path = '/explicit/interpreter',",
+ " python_version = 'PY2',",
")");
PyRuntimeInfo infoDefault =
getConfiguredTarget("//pkg:myruntime_default").get(PyRuntimeInfo.PROVIDER);
PyRuntimeInfo infoExplicit =
getConfiguredTarget("//pkg:myruntime_explicit").get(PyRuntimeInfo.PROVIDER);
- assertThat(infoDefault.getPythonVersion()).isEqualTo(PythonVersion.PY2);
- assertThat(infoExplicit.getPythonVersion()).isEqualTo(PythonVersion.PY3);
+ assertThat(infoDefault.getPythonVersion()).isEqualTo(PythonVersion.PY3);
+ assertThat(infoExplicit.getPythonVersion()).isEqualTo(PythonVersion.PY2);
}
@Test
diff --git a/src/test/java/com/google/devtools/build/lib/rules/python/PythonConfigurationTest.java b/src/test/java/com/google/devtools/build/lib/rules/python/PythonConfigurationTest.java
index 54b1987..28ad7af 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/python/PythonConfigurationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/python/PythonConfigurationTest.java
@@ -132,9 +132,8 @@
@Test
public void getNormalized() throws Exception {
- assumesDefaultIsPY2();
PythonOptions opts = parsePythonOptions();
PythonOptions normalizedOpts = (PythonOptions) opts.getNormalized();
- assertThat(normalizedOpts.pythonVersion).isEqualTo(PythonVersion.PY2);
+ assertThat(normalizedOpts.pythonVersion).isEqualTo(PythonVersion.PY3);
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/rules/python/PythonStarlarkApiTest.java b/src/test/java/com/google/devtools/build/lib/rules/python/PythonStarlarkApiTest.java
index 3ba118e..8614eb3 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/python/PythonStarlarkApiTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/python/PythonStarlarkApiTest.java
@@ -142,7 +142,7 @@
" name = 'pyruntime',",
" interpreter = ':intr',",
" files = ['data.txt'],",
- " python_version = 'PY2',",
+ " python_version = 'PY3',",
")",
"userruntime(",
" name = 'userruntime',",
@@ -152,7 +152,7 @@
")",
"py_runtime_pair(",
" name = 'userruntime_pair',",
- " py2_runtime = 'userruntime',",
+ " py3_runtime = 'userruntime',",
")",
"toolchain(",
" name = 'usertoolchain',",
diff --git a/src/test/java/com/google/devtools/build/lib/rules/python/PythonTestUtils.java b/src/test/java/com/google/devtools/build/lib/rules/python/PythonTestUtils.java
index c3fae56..8db0e89 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/python/PythonTestUtils.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/python/PythonTestUtils.java
@@ -29,10 +29,6 @@
* <p>Marking test cases that depend on the default Python version helps to diagnose failures. It
* also helps guard against accidentally making the test spuriously pass, e.g. if the expected
* value becomes the same as the default value..
- *
- * <p>Although the hard-coded default in {@link PythonOptions} has been flipped to PY3, we
- * override this back to PY2 in our analysis-time tests and some of our integration tests. These
- * tests will need to be ported in the future.
*/
public static void assumesDefaultIsPY2() {
// No-op.
diff --git a/src/test/java/com/google/devtools/build/lib/testutil/TestConstants.java b/src/test/java/com/google/devtools/build/lib/testutil/TestConstants.java
index 6c5495c..408e2d6 100644
--- a/src/test/java/com/google/devtools/build/lib/testutil/TestConstants.java
+++ b/src/test/java/com/google/devtools/build/lib/testutil/TestConstants.java
@@ -132,9 +132,6 @@
"--target_platform_fallback=@bazel_tools//platforms:default_target",
"--platforms=@bazel_tools//platforms:default_target",
"--host_platform=@bazel_tools//platforms:default_host",
- // TODO(#7903): Remove once our own tests are migrated.
- "--incompatible_py3_is_default=false",
- "--incompatible_py2_outputs_are_suffixed=false",
// TODO(#7849): Remove after flag flip.
"--incompatible_use_toolchain_resolution_for_java_rules");