Skip to content

Commit 93f6e51

Browse files
rickeylevcopybara-github
authored andcommitted
Default analysis tests to use Python 3
This matches the behavior outside of the tests. Work towards #7903 PiperOrigin-RevId: 452140874 Change-Id: Icab37d01657b07ef6f56366a1e0b64f0f3d26c29
1 parent fcaa247 commit 93f6e51

7 files changed

+10
-23
lines changed

src/test/java/com/google/devtools/build/lib/buildtool/CompileOneDependencyIntegrationTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public void testPyBinaryMember() throws Exception {
3939
addOptions("--compile_one_dependency");
4040
// Make build super minimal.
4141
addOptions("--nobuild_runfile_links");
42-
4342
write("package/BUILD", "py_binary(name='foo', srcs=['foo.py'])");
4443
write("package/foo.py");
4544
buildTarget("package/foo.py");

src/test/java/com/google/devtools/build/lib/rules/python/PyBaseConfiguredTargetTestBase.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package com.google.devtools.build.lib.rules.python;
1616

1717
import static com.google.common.truth.Truth.assertThat;
18-
import static com.google.devtools.build.lib.rules.python.PythonTestUtils.assumesDefaultIsPY2;
1918

2019
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
2120
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
@@ -68,14 +67,13 @@ public void goodSrcsVersionValue() throws Exception {
6867
}
6968

7069
@Test
71-
public void versionIs2IfUnspecified() throws Exception {
72-
assumesDefaultIsPY2();
70+
public void versionIs3IfUnspecified() throws Exception {
7371
scratch.file(
7472
"pkg/BUILD", //
7573
ruleName + "(",
7674
" name = 'foo',",
7775
" srcs = ['foo.py'])");
78-
assertThat(getPythonVersion(getConfiguredTarget("//pkg:foo"))).isEqualTo(PythonVersion.PY2);
76+
assertThat(getPythonVersion(getConfiguredTarget("//pkg:foo"))).isEqualTo(PythonVersion.PY3);
7977
}
8078

8179
@Test

src/test/java/com/google/devtools/build/lib/rules/python/PyRuntimeConfiguredTargetTest.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package com.google.devtools.build.lib.rules.python;
1616

1717
import static com.google.common.truth.Truth.assertThat;
18-
import static com.google.devtools.build.lib.rules.python.PythonTestUtils.assumesDefaultIsPY2;
1918

2019
import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
2120
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
@@ -72,27 +71,26 @@ public void nonhermeticRuntime() throws Exception {
7271

7372
@Test
7473
public void pythonVersionDefault() throws Exception {
75-
assumesDefaultIsPY2();
7674
// When using toolchains, the python_version attribute is mandatory.
7775
useConfiguration("--incompatible_use_python_toolchains=false");
7876
scratch.file(
7977
"pkg/BUILD",
8078
"py_runtime(",
8179
" name = 'myruntime_default',",
82-
" interpreter_path = '/system/interpreter',",
80+
" interpreter_path = '/default/interpreter',",
8381
")",
8482
"py_runtime(",
8583
" name = 'myruntime_explicit',",
86-
" interpreter_path = '/system/interpreter',",
87-
" python_version = 'PY3',",
84+
" interpreter_path = '/explicit/interpreter',",
85+
" python_version = 'PY2',",
8886
")");
8987
PyRuntimeInfo infoDefault =
9088
getConfiguredTarget("//pkg:myruntime_default").get(PyRuntimeInfo.PROVIDER);
9189
PyRuntimeInfo infoExplicit =
9290
getConfiguredTarget("//pkg:myruntime_explicit").get(PyRuntimeInfo.PROVIDER);
9391

94-
assertThat(infoDefault.getPythonVersion()).isEqualTo(PythonVersion.PY2);
95-
assertThat(infoExplicit.getPythonVersion()).isEqualTo(PythonVersion.PY3);
92+
assertThat(infoDefault.getPythonVersion()).isEqualTo(PythonVersion.PY3);
93+
assertThat(infoExplicit.getPythonVersion()).isEqualTo(PythonVersion.PY2);
9694
}
9795

9896
@Test

src/test/java/com/google/devtools/build/lib/rules/python/PythonConfigurationTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,8 @@ public void getHost_Py3IsDefaultFlagChangesHost() throws Exception {
132132

133133
@Test
134134
public void getNormalized() throws Exception {
135-
assumesDefaultIsPY2();
136135
PythonOptions opts = parsePythonOptions();
137136
PythonOptions normalizedOpts = (PythonOptions) opts.getNormalized();
138-
assertThat(normalizedOpts.pythonVersion).isEqualTo(PythonVersion.PY2);
137+
assertThat(normalizedOpts.pythonVersion).isEqualTo(PythonVersion.PY3);
139138
}
140139
}

src/test/java/com/google/devtools/build/lib/rules/python/PythonStarlarkApiTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public void runtimeSandwich() throws Exception {
142142
" name = 'pyruntime',",
143143
" interpreter = ':intr',",
144144
" files = ['data.txt'],",
145-
" python_version = 'PY2',",
145+
" python_version = 'PY3',",
146146
")",
147147
"userruntime(",
148148
" name = 'userruntime',",
@@ -152,7 +152,7 @@ public void runtimeSandwich() throws Exception {
152152
")",
153153
"py_runtime_pair(",
154154
" name = 'userruntime_pair',",
155-
" py2_runtime = 'userruntime',",
155+
" py3_runtime = 'userruntime',",
156156
")",
157157
"toolchain(",
158158
" name = 'usertoolchain',",

src/test/java/com/google/devtools/build/lib/rules/python/PythonTestUtils.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ private PythonTestUtils() {}
2929
* <p>Marking test cases that depend on the default Python version helps to diagnose failures. It
3030
* also helps guard against accidentally making the test spuriously pass, e.g. if the expected
3131
* value becomes the same as the default value..
32-
*
33-
* <p>Although the hard-coded default in {@link PythonOptions} has been flipped to PY3, we
34-
* override this back to PY2 in our analysis-time tests and some of our integration tests. These
35-
* tests will need to be ported in the future.
3632
*/
3733
public static void assumesDefaultIsPY2() {
3834
// No-op.

src/test/java/com/google/devtools/build/lib/testutil/TestConstants.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@ private TestConstants() {
132132
"--target_platform_fallback=@bazel_tools//platforms:default_target",
133133
"--platforms=@bazel_tools//platforms:default_target",
134134
"--host_platform=@bazel_tools//platforms:default_host",
135-
// TODO(#7903): Remove once our own tests are migrated.
136-
"--incompatible_py3_is_default=false",
137-
"--incompatible_py2_outputs_are_suffixed=false",
138135
// TODO(#7849): Remove after flag flip.
139136
"--incompatible_use_toolchain_resolution_for_java_rules");
140137

0 commit comments

Comments
 (0)