eggs/zc.buildout-1.5.2-py2.6.egg/zc/buildout/testselectingpython.py
changeset 307 c6bca38c1cbf
equal deleted inserted replaced
306:5ff1fc726848 307:c6bca38c1cbf
       
     1 ##############################################################################
       
     2 #
       
     3 # Copyright (c) 2006 Zope Corporation and Contributors.
       
     4 # All Rights Reserved.
       
     5 #
       
     6 # This software is subject to the provisions of the Zope Public License,
       
     7 # Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
       
     8 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
       
     9 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
    10 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
       
    11 # FOR A PARTICULAR PURPOSE.
       
    12 #
       
    13 ##############################################################################
       
    14 import os, re, subprocess, sys, textwrap, unittest, doctest
       
    15 from zope.testing import renormalizing
       
    16 import zc.buildout.tests
       
    17 import zc.buildout.testing
       
    18 
       
    19 if sys.version_info[:2] == (2, 4):
       
    20     other_version = "2.5"
       
    21 else:
       
    22     other_version = "2.4"
       
    23 
       
    24 __test__ = dict(
       
    25     test_selecting_python_via_easy_install=
       
    26     """\
       
    27 
       
    28 We can specify a specific Python executable.
       
    29 
       
    30     >>> dest = tmpdir('sample-install')
       
    31     >>> ws = zc.buildout.easy_install.install(
       
    32     ...     ['demo'], dest, links=[link_server],
       
    33     ...     index='http://www.python.org/pypi/',
       
    34     ...     always_unzip=True, executable=other_executable)
       
    35 
       
    36     >>> ls(dest)
       
    37     d  demo-0.3-py%(other_version)s.egg
       
    38     d  demoneeded-1.1-py%(other_version)s.egg
       
    39 
       
    40 """ % dict(other_version=other_version)
       
    41     )
       
    42 
       
    43 def multi_python(test):
       
    44     other_executable = zc.buildout.testing.find_python(other_version)
       
    45     command = textwrap.dedent('''\
       
    46         try:
       
    47             import setuptools
       
    48         except ImportError:
       
    49             import sys
       
    50             sys.exit(1)
       
    51         ''')
       
    52     env = dict(os.environ)
       
    53     env.pop('PYTHONPATH', None)
       
    54     if subprocess.call([other_executable, '-c', command], env=env):
       
    55         # the other executable does not have setuptools.  Get setuptools.
       
    56         # We will do this using the same tools we are testing, for better or
       
    57         # worse.  Alternatively, we could try using bootstrap.
       
    58         executable_dir = test.globs['tmpdir']('executable_dir')
       
    59         executable_parts = os.path.join(executable_dir, 'parts')
       
    60         test.globs['mkdir'](executable_parts)
       
    61         ws = zc.buildout.easy_install.install(
       
    62             ['setuptools'], executable_dir,
       
    63             index='http://www.python.org/pypi/',
       
    64             always_unzip=True, executable=other_executable)
       
    65         zc.buildout.easy_install.sitepackage_safe_scripts(
       
    66             executable_dir, ws, other_executable, executable_parts,
       
    67             reqs=['setuptools'], interpreter='py')
       
    68         original_executable = other_executable
       
    69         other_executable = os.path.join(executable_dir, 'py')
       
    70         assert not subprocess.call(
       
    71             [other_executable, '-c', command], env=env), (
       
    72             'test set up failed')
       
    73     sample_eggs = test.globs['tmpdir']('sample_eggs')
       
    74     os.mkdir(os.path.join(sample_eggs, 'index'))
       
    75     test.globs['sample_eggs'] = sample_eggs
       
    76     zc.buildout.tests.create_sample_eggs(test, executable=other_executable)
       
    77     test.globs['other_executable'] = other_executable
       
    78 
       
    79 
       
    80 def setup(test):
       
    81     zc.buildout.testing.buildoutSetUp(test)
       
    82     multi_python(test)
       
    83     zc.buildout.tests.add_source_dist(test)
       
    84     test.globs['link_server'] = test.globs['start_server'](
       
    85         test.globs['sample_eggs'])
       
    86 
       
    87 
       
    88 def test_suite():
       
    89     return doctest.DocTestSuite(
       
    90         setUp=setup,
       
    91         tearDown=zc.buildout.testing.buildoutTearDown,
       
    92         checker=renormalizing.RENormalizing([
       
    93             (re.compile('setuptools-\S+-py%s.egg' % other_version),
       
    94              'setuptools-V-py%s.egg' % other_version),
       
    95             ]),
       
    96         )