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

Added test, but I cannot get it sys.exit to work correctly

parent 8c13789c
...@@ -234,3 +234,86 @@ directory: ...@@ -234,3 +234,86 @@ directory:
<BLANKLINE> <BLANKLINE>
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(zc.buildout.buildout.main()) sys.exit(zc.buildout.buildout.main())
When buildout restarts and the restarted buildout exits with an error code,
the original buildout that called the second buildout also exits with that
error code. Otherwise build scripts can erroneously detect a succesful
buildout run even if it failed.
Make a recipe that fails:
>>> mkdir(sample_buildout, 'failrecipe')
>>> write(sample_buildout, 'failrecipe', 'failrecipe.py',
... """
... import pkg_resources
... import sys
... print_ = lambda *a: sys.stdout.write(' '.join(map(str, a))+'\\n')
...
... class Recipe:
...
... def __init__(self, buildout, name, options):
... sys.exit('recipe sys-exits')
...
... def install(self):
... pass
...
... update = install
... """)
>>> write(sample_buildout, 'failrecipe', 'setup.py',
... """
... from setuptools import setup
...
... setup(
... name = "failrecipe",
... entry_points = {'zc.buildout': ['default = failrecipe:Recipe']},
... )
... """)
Let's downgrade again, triggering a restart. And use the failing recipe that
gives us a sys.exit:
>>> write(sample_buildout, 'buildout.cfg',
... """
... [buildout]
... find-links = %(new_releases)s
... index = %(new_releases)s
... parts = fail
... develop = failrecipe
...
... [versions]
... zc.buildout = < 99
... distribute = < 99
...
... [fail]
... 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='')
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
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