@@ -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
324328class 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
871878class PythonReqs (GradleTestCase ):
0 commit comments