From 563c94768c05ba4325d38ab1556710e30b838091 Mon Sep 17 00:00:00 2001 From: Arthur Moore Date: Thu, 29 Aug 2024 00:48:42 -0400 Subject: [PATCH] Fix openscad_runner not failing when a test should have failed --- tests/openscad_runner.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/openscad_runner.py b/tests/openscad_runner.py index c73987d..1d150bd 100644 --- a/tests/openscad_runner.py +++ b/tests/openscad_runner.py @@ -109,7 +109,7 @@ class OpenScadRunner: TOP_ANGLE_CAMERA = CameraArguments(Vec3(0,0,0),Vec3(45,0,45),150) common_arguments = [ - #'--hardwarnings', // Does not work when setting variables by using functions + #'--hardwarnings', # Does not work when setting variables by using functions '--enable=fast-csg', '--enable=predictible-output', '--imgsize=1280,720', @@ -127,9 +127,9 @@ class OpenScadRunner: self.camera_arguments = None self.parameters = None - def create_image(self, args: [str], image_file_name: str): + def create_image(self, args: [str], image_file_name: str) -> subprocess.CompletedProcess: """ - Run the code, to create an image. + Run the code and create an image. @Important The only verification is that no errors occured. There is no verification if the image was created, or the image contents. """ @@ -150,6 +150,18 @@ class OpenScadRunner: json.dump(params, file, sort_keys=True, indent=2, cls=DataClassJSONEncoder) file.close() command_arguments += ["-p", file.name, "-P", "python_generated"] - return subprocess.run([self.openscad_binary_path]+command_arguments, check=True) + return self._run(command_arguments) else: - return subprocess.run([self.openscad_binary_path]+command_arguments, check=True) + return self._run(command_arguments) + + def _run(self, args: [str]) -> subprocess.CompletedProcess: + """ + Run openscad with the passed in arguments. + """ + output = subprocess.run([self.openscad_binary_path]+args, capture_output=True) + error_strings = output.stderr.decode().strip().splitlines() + if any(line.startswith("ERROR:") for line in error_strings): + # OpenSCAD doesn't set an error return if it errors from bad SCAD code! + output.returncode = 11 + output.check_returncode() + return output