From 5e050d65dfa09561923c2663eb47ed00b7e16b76 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Fri, 10 Feb 2023 13:57:05 -0800 Subject: [PATCH] python: Remove tests that require Python 2 support This also removes the last tests that require the Java implementation of the rules. Work towards #15684 PiperOrigin-RevId: 508747691 Change-Id: Id976c1f51cb67fbe446074af546cc93ef997e4c4 --- .../PyExecutableConfiguredTargetTestBase.java | 20 -- .../python/PythonSrcsVersionAspectTest.java | 265 ------------------ 2 files changed, 285 deletions(-) diff --git a/src/test/java/com/google/devtools/build/lib/rules/python/PyExecutableConfiguredTargetTestBase.java b/src/test/java/com/google/devtools/build/lib/rules/python/PyExecutableConfiguredTargetTestBase.java index 8f6a2658e80737..bb1575f393fcd7 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/python/PyExecutableConfiguredTargetTestBase.java +++ b/src/test/java/com/google/devtools/build/lib/rules/python/PyExecutableConfiguredTargetTestBase.java @@ -174,26 +174,6 @@ public void versionAttrWorks_WhenSameAsDefaultValue() throws Exception { assertPythonVersionIs("//pkg:foo", PythonVersion.PY3); } - @Test - public void versionAttrTakesPrecedence_NonDefaultValue() throws Exception { - PythonTestUtils.assumeIsBazel(); // Google has py2 disabled - setBuildLanguageOptions( - "--experimental_builtins_injection_override=-py_test,-py_binary,-py_library"); - scratch.file("pkg/BUILD", ruleDeclWithPyVersionAttr("foo", "PY3")); - - assertPythonVersionIs_UnderNewConfig("//pkg:foo", PythonVersion.PY3, "--python_version=PY2"); - } - - @Test - public void versionAttrTakesPrecedence_DefaultValue() throws Exception { - PythonTestUtils.assumeIsBazel(); // Google has py2 disabled - setBuildLanguageOptions( - "--experimental_builtins_injection_override=-py_test,-py_binary,-py_library"); - scratch.file("pkg/BUILD", ruleDeclWithPyVersionAttr("foo", "PY3")); - - assertPythonVersionIs_UnderNewConfig("//pkg:foo", PythonVersion.PY3, "--python_version=PY2"); - } - @Test public void targetInPackageWithHyphensOkIfSrcsFromOtherPackage() throws Exception { scratch.file( diff --git a/src/test/java/com/google/devtools/build/lib/rules/python/PythonSrcsVersionAspectTest.java b/src/test/java/com/google/devtools/build/lib/rules/python/PythonSrcsVersionAspectTest.java index 6a5847cd4ef230..1bc2f3e0658af2 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/python/PythonSrcsVersionAspectTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/python/PythonSrcsVersionAspectTest.java @@ -56,38 +56,6 @@ private String evaluateAspectFor(String label) throws Exception { return ((FileWriteAction) action).getFileContents(); } - @Test - public void simpleCase() throws Exception { - PythonTestUtils.assumeIsBazel(); // Google has py2 disabled. - setBuildLanguageOptions( - "--experimental_builtins_injection_override=-py_test,-py_binary,-py_library"); - scratch.file( - "pkg/BUILD", - "py_library(", - " name = 'lib',", - " srcs = ['lib.py'],", - " srcs_version = 'PY3ONLY',", - ")", - "py_binary(", - " name = 'bin',", - " srcs = ['bin.py'],", - " deps = [':lib'],", - ")"); - String result = evaluateAspectFor("//pkg:bin"); - String golden = - join( - "Python 2-only deps:", - "", - "", - "Python 3-only deps:", - "@//pkg:lib", - "", - "Paths to these deps:", - "@//pkg:bin -> @//pkg:lib", - ""); - assertThat(result).isEqualTo(golden); - } - @Test public void noRequirements() throws Exception { scratch.file( @@ -116,239 +84,6 @@ public void noRequirements() throws Exception { assertThat(result).isEqualTo(golden); } - @Test - public void indirectDependencies() throws Exception { - PythonTestUtils.assumeIsBazel(); // Google has py2 disabled. - setBuildLanguageOptions( - "--experimental_builtins_injection_override=-py_test,-py_binary,-py_library"); - // A <- B <- C <- bin, where only B has the constraint. - scratch.file( - "pkg/BUILD", - "py_library(", - " name = 'libA',", - " srcs = ['libA.py'],", - ")", - "py_library(", - " name = 'libB',", - " srcs = ['libB.py'],", - " deps = [':libA'],", - " srcs_version = 'PY3ONLY',", - ")", - "py_library(", - " name = 'libC',", - " srcs = ['libC.py'],", - " deps = [':libB'],", - ")", - "py_binary(", - " name = 'bin',", - " srcs = ['bin.py'],", - " deps = [':libC'],", - ")"); - String result = evaluateAspectFor("//pkg:bin"); - String golden = - join( - "Python 2-only deps:", - "", - "", - "Python 3-only deps:", - "@//pkg:libB", - "", - "Paths to these deps:", - "@//pkg:bin -> @//pkg:libC -> @//pkg:libB", - ""); - assertThat(result).isEqualTo(golden); - } - - @Test - public void onlyReportTopmost() throws Exception { - PythonTestUtils.assumeIsBazel(); // Google has py2 disabled. - setBuildLanguageOptions( - "--experimental_builtins_injection_override=-py_test,-py_binary,-py_library"); - // A <- B <- C <- bin, where A and C have the constraint. - scratch.file( - "pkg/BUILD", - "py_library(", - " name = 'libA',", - " srcs = ['libA.py'],", - " srcs_version = 'PY3ONLY',", - ")", - "py_library(", - " name = 'libB',", - " srcs = ['libB.py'],", - " deps = [':libA'],", - ")", - "py_library(", - " name = 'libC',", - " srcs = ['libC.py'],", - " deps = [':libB'],", - " srcs_version = 'PY3ONLY',", - ")", - "py_binary(", - " name = 'bin',", - " srcs = ['bin.py'],", - " deps = [':libC'],", - ")"); - String result = evaluateAspectFor("//pkg:bin"); - String golden = - join( - "Python 2-only deps:", - "", - "", - "Python 3-only deps:", - "@//pkg:libC", - "", - "Paths to these deps:", - "@//pkg:bin -> @//pkg:libC", - ""); - assertThat(result).isEqualTo(golden); - } - - @Test - public void oneTopmostReachesAnother() throws Exception { - PythonTestUtils.assumeIsBazel(); // Google has py2 disabled. - setBuildLanguageOptions( - "--experimental_builtins_injection_override=-py_test,-py_binary,-py_library"); - // A <- B <- C, where A and C have the constraint. - // A <- bin and C <- bin, so both A and C are top-most even though C has a path to A. - scratch.file( - "pkg/BUILD", - "py_library(", - " name = 'libA',", - " srcs = ['libA.py'],", - " srcs_version = 'PY3ONLY',", - ")", - "py_library(", - " name = 'libB',", - " srcs = ['libB.py'],", - " deps = [':libA'],", - ")", - "py_library(", - " name = 'libC',", - " srcs = ['libC.py'],", - " deps = [':libB'],", - " srcs_version = 'PY3ONLY',", - ")", - "py_binary(", - " name = 'bin',", - " srcs = ['bin.py'],", - " deps = [':libA', ':libC'],", - ")"); - String result = evaluateAspectFor("//pkg:bin"); - String golden = - join( - "Python 2-only deps:", - "", - "", - "Python 3-only deps:", - "@//pkg:libA", - "@//pkg:libC", - "", - "Paths to these deps:", - "@//pkg:bin -> @//pkg:libA", - "@//pkg:bin -> @//pkg:libC", - ""); - assertThat(result).isEqualTo(golden); - } - - @Test - public void multiplePathsToRequirement() throws Exception { - PythonTestUtils.assumeIsBazel(); // Google has py2 disabled. - setBuildLanguageOptions( - "--experimental_builtins_injection_override=-py_test,-py_binary,-py_library"); - // Diamond graph A <- B, A <- C, B <- bin, C <- bin, where only A has the constraint. - // A is reached through two different paths but reported only once. - scratch.file( - "pkg/BUILD", - "py_library(", - " name = 'libA',", - " srcs = ['libA.py'],", - " srcs_version = 'PY3ONLY',", - ")", - "py_library(", - " name = 'libB',", - " srcs = ['libB.py'],", - " deps = [':libA'],", - ")", - "py_library(", - " name = 'libC',", - " srcs = ['libC.py'],", - " deps = [':libA'],", - ")", - "py_binary(", - " name = 'bin',", - " srcs = ['bin.py'],", - " deps = [':libB', ':libC'],", - ")"); - String result = evaluateAspectFor("//pkg:bin"); - String golden = - join( - "Python 2-only deps:", - "", - "", - "Python 3-only deps:", - "@//pkg:libA", - "", - "Paths to these deps:", - "@//pkg:bin -> @//pkg:libB -> @//pkg:libA", - ""); - assertThat(result).isEqualTo(golden); - } - - @Test - public void noSrcsVersionButIntroducesRequirement() throws Exception { - PythonTestUtils.assumeIsBazel(); // Google has py2 disabled. - setBuildLanguageOptions( - "--experimental_builtins_injection_override=-py_test,-py_binary,-py_library"); - // A <- B <- C <- bin, B introduces the requirement but not via srcs_version. - // dummy_rule propagates sources and sets the py3-only bit. - scratch.file( - "pkg/rules.bzl", - "def _dummy_rule_impl(ctx):", - " info = PyInfo(", - " transitive_sources = depset(", - " transitive=[d[PyInfo].transitive_sources for d in ctx.attr.deps],", - " order='postorder'),", - " has_py3_only_sources = True)", - " return [info]", - "dummy_rule = rule(", - " implementation = _dummy_rule_impl,", - " attrs = {'deps': attr.label_list()},", - ")"); - scratch.file( - "pkg/BUILD", - "load(':rules.bzl', 'dummy_rule')", - "py_library(", - " name = 'libA',", - " srcs = ['libA.py'],", - ")", - "dummy_rule(", - " name = 'libB',", - " deps = [':libA'],", - ")", - "dummy_rule(", - " name = 'libC',", - " deps = [':libB'],", - ")", - "py_binary(", - " name = 'bin',", - " srcs = ['bin.py'],", - " deps = [':libC'],", - ")"); - String result = evaluateAspectFor("//pkg:bin"); - String golden = - join( - "Python 2-only deps:", - "", - "", - "Python 3-only deps:", - "@//pkg:libB", - "", - "Paths to these deps:", - "@//pkg:bin -> @//pkg:libC -> @//pkg:libB", - ""); - assertThat(result).isEqualTo(golden); - } - @Test public void requirementNotPropagated() throws Exception { // A <- B <- C <- bin, A introduces the requirement, but B doesn't propagate it.