Commit bc19672c authored by Reinout van Rees's avatar Reinout van Rees

Added proper exit-code-checking test for restart issue.

When the process is restarted (and results in an error),
we can now properly check the exit code that comes out of
the 'root' buildout process.
parent b1b8ccd3
......@@ -107,7 +107,7 @@ def clean_up_pyc(*path):
## FIXME - check for other platforms
MUST_CLOSE_FDS = not sys.platform.startswith('win')
def system(command, input=''):
def system(command, input='', with_exit_code=False):
p = subprocess.Popen(command,
shell=True,
stdin=subprocess.PIPE,
......@@ -121,7 +121,13 @@ def system(command, input=''):
result = o.read() + e.read()
o.close()
e.close()
return result.decode()
output = result.decode()
if with_exit_code:
# Use the with_exit_code=True parameter when you want to test the exit
# code of the command you're running.
p.wait() # Sets the return code.
output += 'EXIT CODE: %s' % p.returncode
return output
def get(url):
return str(urlopen(url).read().decode())
......
......@@ -288,32 +288,14 @@ gives us a sys.exit:
... recipe = failrecipe
... """ % dict(new_releases=new_releases))
Mock the sys.exit:
>>> import sys
>>> orig_exit = sys.exit
>>> def sys_exit(code):
... if code == 'Second exit':
... print_('Exiting with an error')
... else:
... print('Sys.exit with error %s' % code)
... #raise SystemExit(code)
>>> sys.exit = sys_exit
Run the buildout:
>>> print_(system(buildout), end='')
>>> print_(system(buildout, with_exit_code=True), end='')
Upgraded:
zc.buildout version 1.4.4;
distribute version 0.6;
restarting.
Generated script '/sample-buildout/bin/buildout'.
Develop: '/sample-buildout/failrecipe'
sys.exit occurred. Exit code: recipe sys-exits
Restore sys.exit:
>>> sys.exit = orig_exit
>>> print_("We are still alive")
We are still alive
recipe sys-exits
EXIT CODE: 1
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment