Changeset View
Changeset View
Standalone View
Standalone View
tests/python/modules/test_utils.py
| Show First 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | def run_blender(self, filepath: str, python_script: str, timeout: int=300) -> str: | ||||
| :param filepath: taken relative to self.testdir. | :param filepath: taken relative to self.testdir. | ||||
| :param timeout: in seconds | :param timeout: in seconds | ||||
| """ | """ | ||||
| assert self.blender, "Path to Blender binary is to be set in setUpClass()" | assert self.blender, "Path to Blender binary is to be set in setUpClass()" | ||||
| assert self.testdir, "Path to tests binary is to be set in setUpClass()" | assert self.testdir, "Path to tests binary is to be set in setUpClass()" | ||||
| blendfile = self.testdir / filepath | blendfile = self.testdir / filepath if filepath else "" | ||||
| command = ( | command = [ | ||||
sybren: Using a list instead of a tuple will allow you to do `command.extend(...)` or `command.append(.. | |||||
| self.blender, | self.blender, | ||||
| '--background', | '--background', | ||||
| '-noaudio', | '-noaudio', | ||||
| '--factory-startup', | '--factory-startup', | ||||
| '--enable-autoexec', | '--enable-autoexec', | ||||
| str(blendfile), | ] | ||||
| if blendfile: | |||||
| command.append(str(blendfile)) | |||||
| command.extend([ | |||||
Done Inline ActionsYou may want to leave the trailing comma in place. It allows for clean diffs (now and in the future). sybren: You may want to leave the trailing comma in place. It allows for clean diffs (now and in the… | |||||
| '-E', 'CYCLES', | '-E', 'CYCLES', | ||||
| '--python-exit-code', '47', | '--python-exit-code', '47', | ||||
| '--python-expr', python_script, | '--python-expr', python_script, | ||||
| ] | |||||
| ) | ) | ||||
| proc = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, | proc = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, | ||||
| timeout=timeout) | timeout=timeout) | ||||
| output = proc.stdout.decode('utf8') | output = proc.stdout.decode('utf8') | ||||
| if proc.returncode: | if proc.returncode: | ||||
| self.fail('Error %d running Blender:\n%s' % (proc.returncode, output)) | self.fail('Error %d running Blender:\n%s' % (proc.returncode, output)) | ||||
| return output | return output | ||||
Using a list instead of a tuple will allow you to do command.extend(...) or command.append(...) without requiring the existing tuple to be copied. Doesn't matter much, though.