Skip to content

Commit e61c87f

Browse files
committed
Remove Windows integration tests dependency on Unix commands
1 parent cee8005 commit e61c87f

File tree

5 files changed

+36
-22
lines changed

5 files changed

+36
-22
lines changed

product/gradle-plugin/src/test/integration/data/BuildPython/args_1/app/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ android {
1111
versionCode 1
1212
versionName "0.0.1"
1313
python {
14-
buildPython "echo echo_args1"
14+
def py = System.getProperty("os.name").startsWith("Windows") ? "py" : "python3"
15+
// Single string, split on whitespace.
16+
buildPython "$py -c print('echo_args1')"
1517
pip {
1618
install "six"
1719
}

product/gradle-plugin/src/test/integration/data/BuildPython/args_2/app/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ android {
1111
versionCode 1
1212
versionName "0.0.1"
1313
python {
14-
buildPython "echo", "echo_args2"
14+
def py = System.getProperty("os.name").startsWith("Windows") ? "py" : "python3"
15+
// Multiple strings in a list.
16+
buildPython py, "-c", "print('echo_args2')"
1517
pip {
1618
install "six"
1719
}

product/gradle-plugin/src/test/integration/data/BuildPython/override/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ android {
1414
versionCode 1
1515
versionName "0.0.1"
1616
python {
17-
buildPython System.getenv("buildpython")
17+
buildPython System.getenv("buildpython").split("\s+")
1818
pip {
1919
install "six"
2020
}

product/gradle-plugin/src/test/integration/data/BuildPython/silent_failure/app/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ android {
1111
versionCode 1
1212
versionName "0.0.1"
1313
python {
14-
buildPython "true"
14+
buildPython(
15+
System.getProperty("os.name").startsWith("Windows") ? "py" : "python3",
16+
"-c", "exit()"
17+
)
1518
pip {
1619
install "six"
1720
}

product/gradle-plugin/src/test/integration/test_gradle_plugin.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,14 @@ def check_dsl(self, *layers):
315315
})
316316

317317
run.rerun(variants=["bpProperty-debug"], succeed=False)
318-
self.assertInStderr(BuildPython.problem_error("python-property"), run, re=True)
318+
self.assertInStderr(
319+
BuildPython.invalid_error("python-property", BuildPython.PROBLEM),
320+
run, re=True)
319321

320322
run.rerun(variants=["bpMethod-debug"], succeed=False)
321-
self.assertInStderr(BuildPython.problem_error("python-method"), run, re=True)
323+
self.assertInStderr(
324+
BuildPython.invalid_error("python-method", BuildPython.PROBLEM),
325+
run, re=True)
322326

323327

324328
class ChaquopyPlugin(GradleTestCase):
@@ -682,7 +686,8 @@ def test_syntax_error(self):
682686
self.RunGradle("base", "Pyc/syntax_error", app=["bad.py", "good.pyc"], pyc=["stdlib"])
683687

684688
def test_buildpython(self):
685-
message = BuildPython.problem_error("pythoninvalid", advice="")
689+
message = BuildPython.invalid_error(
690+
"pythoninvalid", BuildPython.PROBLEM, advice="")
686691
kwargs = dict(app=["hello.py"], pyc=["stdlib"])
687692

688693
run = self.RunGradle("base", "Pyc/buildpython_warning", **kwargs)
@@ -738,15 +743,15 @@ def missing_error(cls, version, advice=SEE):
738743
def invalid_error(
739744
cls, command, error, *, version=DEFAULT_PYTHON_VERSION, advice=SEE
740745
):
746+
command_split = re.split(r"\s+", command)
747+
if error in [cls.PROBLEM, cls.NON_ZERO]:
748+
error = error.format(command_split[0])
749+
741750
return (
742-
fr"\[{re.escape(command)}\] is not a valid Python {version} command: "
743-
fr"{error}\. {advice}"
751+
fr"\[{re.escape(', '.join(command_split))}\] "
752+
fr"is not a valid Python {version} command: {error}\. {advice}"
744753
)
745754

746-
@classmethod
747-
def problem_error(cls, command, **kwargs):
748-
return cls.invalid_error(command, cls.PROBLEM.format(command), **kwargs)
749-
750755
def test_default(self):
751756
run = self.RunGradle(
752757
"base", "BuildPython/default", add_path=["bin"], succeed=False)
@@ -785,8 +790,10 @@ def assert_probed(self, run, probed, *, found=True):
785790

786791
def test_invalid(self):
787792
run = self.RunGradle("base", "BuildPython/override", run=False)
788-
self.run_override(run, "python-bad", error=self.PROBLEM.format("python-bad"))
789-
self.run_override(run, "false", error=self.NON_ZERO.format("false"))
793+
self.run_override(run, "python-bad", error=self.PROBLEM)
794+
self.run_override(
795+
run, ("py" if os.name == "nt" else "python3") + " -c exit(1)",
796+
error=self.NON_ZERO)
790797

791798
for version in [OLD_PYTHON_VERSION, NON_DEFAULT_PYTHON_VERSION]:
792799
with self.subTest(version):
@@ -835,14 +842,14 @@ def test_venv(self):
835842

836843
def test_args(self): # Also tests making a change.
837844
run = self.RunGradle("base", "BuildPython/args_1", succeed=False)
838-
self.assertInStdout("echo_args1", run)
845+
self.assertInStdout(r"^echo_args1$", run, re=True)
839846
run.apply_layers("BuildPython/args_2")
840847
run.rerun(succeed=False)
841-
self.assertInStdout("echo_args2", run)
848+
self.assertInStdout(r"^echo_args2$", run, re=True)
842849

843850
def test_space(self):
844851
run = self.RunGradle("base", "BuildPython/space", succeed=False)
845-
self.assertInStdout("Hello Chaquopy", run)
852+
self.assertInStdout(r"^Hello Chaquopy$", run, re=True)
846853

847854
# Test a buildPython which returns success without doing anything (possibly the
848855
# cause of #250).
@@ -856,16 +863,16 @@ def test_silent_failure(self):
856863
def test_variant(self):
857864
run = self.RunGradle("base", "BuildPython/variant", variants=["red-debug"],
858865
succeed=False)
859-
self.assertInStderr(self.problem_error("python-red"), run, re=True)
866+
self.assertInStderr(self.invalid_error("python-red", self.PROBLEM), run, re=True)
860867
run.rerun(variants=["blue-debug"], succeed=False)
861-
self.assertInStderr(self.problem_error("python-blue"), run, re=True)
868+
self.assertInStderr(self.invalid_error("python-blue", self.PROBLEM), run, re=True)
862869

863870
def test_variant_merge(self):
864871
run = self.RunGradle("base", "BuildPython/variant_merge", variants=["red-debug"],
865872
succeed=False)
866-
self.assertInStderr(self.problem_error("python-red"), run, re=True)
873+
self.assertInStderr(self.invalid_error("python-red", self.PROBLEM), run, re=True)
867874
run.rerun(variants=["blue-debug"], succeed=False)
868-
self.assertInStderr(self.problem_error("python-blue"), run, re=True)
875+
self.assertInStderr(self.invalid_error("python-blue", self.PROBLEM), run, re=True)
869876

870877

871878
class PythonReqs(GradleTestCase):

0 commit comments

Comments
 (0)