2019-02-14 03:25:34 +00:00
|
|
|
import subprocess
|
|
|
|
|
2019-02-18 12:04:59 +00:00
|
|
|
|
|
|
|
def run_subprocess(command, working_dir, expected_returncode=0):
|
|
|
|
"""
|
|
|
|
Helper function to run a shell command and report success/failure
|
|
|
|
depending on the exit status of the shell command.
|
|
|
|
"""
|
|
|
|
# Note we need to capture stdout/stderr from the subprocess,
|
|
|
|
# then print it, which nose/unittest will then capture and
|
|
|
|
# buffer appropriately
|
2019-02-14 03:25:34 +00:00
|
|
|
result = subprocess.run(
|
|
|
|
command,
|
2019-02-18 12:04:59 +00:00
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.STDOUT,
|
|
|
|
cwd=working_dir
|
2019-02-14 03:25:34 +00:00
|
|
|
)
|
|
|
|
print(result.stdout.decode('utf-8'))
|
|
|
|
assert(result.returncode == expected_returncode)
|
2019-02-14 16:29:49 +00:00
|
|
|
return result.stdout.decode('utf-8')
|