[Checkins] SVN: zc.buildout/branches/gary-4/ add full tests for interpreter recipe
Gary Poster
gary.poster at canonical.com
Mon Jan 11 20:18:03 EST 2010
Log message for revision 108043:
add full tests for interpreter recipe
Changed:
U zc.buildout/branches/gary-4/src/zc/buildout/testing.py
U zc.buildout/branches/gary-4/zc.recipe.egg_/src/zc/recipe/egg/egg.py
U zc.buildout/branches/gary-4/zc.recipe.egg_/src/zc/recipe/egg/tests.py
-=-
Modified: zc.buildout/branches/gary-4/src/zc/buildout/testing.py
===================================================================
--- zc.buildout/branches/gary-4/src/zc/buildout/testing.py 2010-01-12 00:29:12 UTC (rev 108042)
+++ zc.buildout/branches/gary-4/src/zc/buildout/testing.py 2010-01-12 01:18:03 UTC (rev 108043)
@@ -282,12 +282,12 @@
register_teardown(lambda: stop_server(url, thread))
return url
- def make_py(initialization='', site_packages_dir=None):
+ def make_py(initialization=''):
"""Returns paths to new executable and to its site-packages.
"""
buildout = tmpdir('executable_buildout')
- if site_packages_dir is None:
- site_packages_dir = mkdir(buildout, 'site-packages')
+ site_packages_dir = os.path.join(buildout, 'site-packages')
+ mkdir(site_packages_dir)
old_wd = os.getcwd()
os.chdir(buildout)
make_buildout()
Modified: zc.buildout/branches/gary-4/zc.recipe.egg_/src/zc/recipe/egg/egg.py
===================================================================
--- zc.buildout/branches/gary-4/zc.recipe.egg_/src/zc/recipe/egg/egg.py 2010-01-12 00:29:12 UTC (rev 108042)
+++ zc.buildout/branches/gary-4/zc.recipe.egg_/src/zc/recipe/egg/egg.py 2010-01-12 01:18:03 UTC (rev 108043)
@@ -24,7 +24,7 @@
def __init__(self, buildout, name, options):
self.buildout = buildout
- self.name = name
+ self.name = self.default_eggs = name
self.options = options
b_options = buildout['buildout']
links = options.get('find-links', b_options['find-links'])
@@ -66,7 +66,7 @@
distributions = [
r.strip()
- for r in options.get('eggs', self.name).split('\n')
+ for r in options.get('eggs', self.default_eggs).split('\n')
if r.strip()]
orig_distributions = distributions[:]
distributions.extend(extra)
@@ -196,6 +196,7 @@
if 'extends' in options:
options.update(buildout[options['extends']])
super(Interpreter, self).__init__(buildout, name, options)
+ self.default_eggs = ''
b_options = buildout['buildout']
options['parts-directory'] = os.path.join(
b_options['parts-directory'], self.name)
Modified: zc.buildout/branches/gary-4/zc.recipe.egg_/src/zc/recipe/egg/tests.py
===================================================================
--- zc.buildout/branches/gary-4/zc.recipe.egg_/src/zc/recipe/egg/tests.py 2010-01-12 00:29:12 UTC (rev 108042)
+++ zc.buildout/branches/gary-4/zc.recipe.egg_/src/zc/recipe/egg/tests.py 2010-01-12 01:18:03 UTC (rev 108043)
@@ -29,6 +29,249 @@
return d
return dirname(os.path.dirname(d), level-1)
+# We do not explicitly test the interpreter recipe support for the ``eggs``,
+# ``find-links``, and ``index`` options because they are used for most or
+# all of the examples. The README tests ``extends``,
+# ``include-site-customization`` and ``name``. That leaves ``python``,
+# ``extra-paths``, ``initialization``, ``relative-paths``, and
+# ``include-site-packages``.
+
+def interpreter_recipe_supports_python_option():
+ """
+This simply shows that the ``python`` option can specify another section to
+find the ``executable``. (The ``python`` option defaults to looking in the
+``buildout`` section.) We do this by creating a custom Python that will have
+some initialization that we can look for.
+
+ >>> py_path, site_packages_path = make_py(initialization='''
+ ... import os
+ ... os.environ['zc.buildout'] = 'foo bar baz shazam'
+ ... ''')
+
+ >>> write(sample_buildout, 'buildout.cfg',
+ ... '''
+ ... [buildout]
+ ... parts = py
+ ...
+ ... [custom_python]
+ ... executable = %(py_path)s
+ ...
+ ... [py]
+ ... recipe = zc.recipe.egg:interpreter
+ ... include-site-customization = true
+ ... eggs = demo<0.3
+ ... find-links = %(server)s
+ ... index = %(server)s/index
+ ... python = custom_python
+ ... ''' % dict(server=link_server, py_path=py_path))
+
+ >>> print system(buildout),
+ Installing py.
+ Getting distribution for 'demo<0.3'.
+ Got demo 0.2.
+ Getting distribution for 'demoneeded'.
+ Got demoneeded 1.2c1.
+ Generated interpreter '/sample-buildout/bin/py'.
+
+ >>> print system(join(sample_buildout, 'bin', 'py') +
+ ... ''' -c "import os; print os.environ['zc.buildout']"'''),
+ foo bar baz shazam
+"""
+
+def interpreter_recipe_supports_extra_paths_option():
+ """
+This shows that specifying extra-paths will affect sys.path.
+
+ >>> write(sample_buildout, 'buildout.cfg',
+ ... '''
+ ... [buildout]
+ ... parts = py
+ ...
+ ... [py]
+ ... recipe = zc.recipe.egg:interpreter
+ ... find-links = %(server)s
+ ... index = %(server)s/index
+ ... extra-paths =
+ ... /foo/bar
+ ... ${buildout:directory}/spam
+ ... ''' % dict(server=link_server))
+
+ >>> print system(buildout),
+ Installing py.
+ Generated interpreter '/sample-buildout/bin/py'.
+ >>> print system(join(sample_buildout, 'bin', 'py') +
+ ... ''' -c "import sys;print 'path' + ' '.join(sys.path)"''')
+ ... # doctest:+ELLIPSIS
+ path.../foo/bar /sample-buildout/spam...
+
+"""
+
+def interpreter_recipe_supports_initialization_option():
+ """
+This simply shows that the ``initialization`` option can specify code to
+run on initialization.
+
+ >>> write(sample_buildout, 'buildout.cfg',
+ ... '''
+ ... [buildout]
+ ... parts = py
+ ...
+ ... [py]
+ ... recipe = zc.recipe.egg:interpreter
+ ... initialization =
+ ... import os
+ ... os.environ['zc.buildout'] = 'foo bar baz shazam'
+ ... eggs = demo<0.3
+ ... find-links = %(server)s
+ ... index = %(server)s/index
+ ... ''' % dict(server=link_server))
+
+ >>> print system(buildout),
+ Installing py.
+ Getting distribution for 'demo<0.3'.
+ Got demo 0.2.
+ Getting distribution for 'demoneeded'.
+ Got demoneeded 1.2c1.
+ Generated interpreter '/sample-buildout/bin/py'.
+
+ >>> cat(sample_buildout, 'parts', 'py', 'sitecustomize.py')
+ ... # doctest: +NORMALIZE_WHITESPACE
+ <BLANKLINE>
+ import os
+ os.environ['zc.buildout'] = 'foo bar baz shazam'
+ >>> print system(join(sample_buildout, 'bin', 'py') +
+ ... ''' -c "import os; print os.environ['zc.buildout']"'''),
+ foo bar baz shazam
+
+This also works with the include-site-customization option, processing local
+initialization, and then the Python's initialization. We show this with a
+custom Python.
+
+ >>> py_path, site_packages_path = make_py(initialization='''
+ ... import os
+ ... os.environ['zc.buildout'] = 'foo bar baz shazam'
+ ... ''')
+
+ >>> write(sample_buildout, 'buildout.cfg',
+ ... '''
+ ... [buildout]
+ ... parts = py
+ ...
+ ... [custom_python]
+ ... executable = %(py_path)s
+ ...
+ ... [py]
+ ... recipe = zc.recipe.egg:interpreter
+ ... initialization =
+ ... import os
+ ... os.environ['zc.recipe.egg'] = 'baLOOba'
+ ... include-site-customization = true
+ ... eggs = demo<0.3
+ ... find-links = %(server)s
+ ... index = %(server)s/index
+ ... python = custom_python
+ ... ''' % dict(server=link_server, py_path=py_path))
+
+ >>> print system(buildout),
+ Uninstalling py.
+ Installing py.
+ Generated interpreter '/sample-buildout/bin/py'.
+
+ >>> cat(sample_buildout, 'parts', 'py', 'sitecustomize.py')
+ ... # doctest: +NORMALIZE_WHITESPACE
+ <BLANKLINE>
+ import os
+ os.environ['zc.recipe.egg'] = 'baLOOba'
+ execfile('/executable_buildout/parts/py/sitecustomize.py')
+
+ >>> print system(join(sample_buildout, 'bin', 'py') + ' -c ' +
+ ... '''"import os; print os.environ['zc.recipe.egg']"'''),
+ baLOOba
+ >>> print system(join(sample_buildout, 'bin', 'py') +
+ ... ''' -c "import os; print os.environ['zc.buildout']"'''),
+ foo bar baz shazam
+
+"""
+
+def interpreter_recipe_supports_relative_paths_option():
+ """
+This shows that the relative-paths option affects the code for inserting
+paths into sys.path.
+
+ >>> write(sample_buildout, 'buildout.cfg',
+ ... '''
+ ... [buildout]
+ ... parts = py
+ ...
+ ... [py]
+ ... recipe = zc.recipe.egg:interpreter
+ ... find-links = %(server)s
+ ... index = %(server)s/index
+ ... relative-paths = true
+ ... extra-paths =
+ ... /foo/bar
+ ... ${buildout:directory}/spam
+ ... ''' % dict(server=link_server))
+
+ >>> print system(buildout),
+ Installing py.
+ Generated interpreter '/sample-buildout/bin/py'.
+
+Let's look at the site.py that was generated:
+
+ >>> cat(sample_buildout, 'parts', 'py', 'site.py')
+ ... # doctest: +NORMALIZE_WHITESPACE
+ <BLANKLINE>
+ import os
+ <BLANKLINE>
+ join = os.path.join
+ base = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
+ base = os.path.dirname(base)
+ base = os.path.dirname(base)
+ import sys
+ sys.path[0:0] = [
+ '/foo/bar',
+ join(base, 'spam'),
+ ]
+ import sitecustomize
+
+"""
+
+def interpreter_recipe_supports_include_site_packages_option():
+ """
+This option simply causes the executable's usual site.py to be processed.
+We'll demonstrate this by using a Python that has its own extra path.
+
+ >>> py_path, site_packages_path = make_py()
+
+ >>> write(sample_buildout, 'buildout.cfg',
+ ... '''
+ ... [buildout]
+ ... parts = py
+ ... executable = %(py_path)s
+ ...
+ ... [py]
+ ... recipe = zc.recipe.egg:interpreter
+ ... include-site-packages = true
+ ... eggs = demo<0.3
+ ... find-links = %(server)s
+ ... index = %(server)s/index
+ ... ''' % dict(server=link_server, py_path=py_path))
+
+ >>> print system(buildout),
+ Installing py.
+ Getting distribution for 'demo<0.3'.
+ Got demo 0.2.
+ Getting distribution for 'demoneeded'.
+ Got demoneeded 1.2c1.
+ Generated interpreter '/sample-buildout/bin/py'.
+
+ >>> print system(join(sample_buildout, 'bin', 'py') +
+ ... ''' -c "import sys; print (%r in sys.path) or (%r, sys.path)"''' %
+ ... (site_packages_path, site_packages_path)),
+ True
+"""
+
def setUp(test):
zc.buildout.tests.easy_install_SetUp(test)
zc.buildout.testing.install_develop('zc.recipe.egg', test)
@@ -89,6 +332,15 @@
(re.compile('extdemo[.]pyd'), 'extdemo.so')
]),
),
+ doctest.DocTestSuite(
+ setUp=setUp,
+ tearDown=zc.buildout.testing.buildoutTearDown,
+ checker=renormalizing.RENormalizing([
+ zc.buildout.testing.normalize_path,
+ zc.buildout.testing.normalize_endings,
+ zc.buildout.testing.normalize_egg_py,
+ ]),
+ ),
))
More information about the checkins
mailing list