Skip to content

Commit

Permalink
python: Remove tests that require Python 2 support
Browse files Browse the repository at this point in the history
This also removes the last tests that require the Java implementation of the
rules.

Work towards #15684

PiperOrigin-RevId: 508747691
Change-Id: Id976c1f51cb67fbe446074af546cc93ef997e4c4
  • Loading branch information
rickeylev authored and hvadehra committed Feb 14, 2023
1 parent dfa62ff commit 5e050d6
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 285 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:",
"<None>",
"",
"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(
Expand Down Expand Up @@ -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:",
"<None>",
"",
"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:",
"<None>",
"",
"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:",
"<None>",
"",
"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:",
"<None>",
"",
"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:",
"<None>",
"",
"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.
Expand Down

0 comments on commit 5e050d6

Please sign in to comment.