Make it testable with distribute in place of setuptools. Pass '--distribute' to auto_test.py to try using it in place of setuptools.

This commit is contained in:
Dave Abrahams 2010-05-21 10:31:14 -04:00
parent 51512d7db7
commit 9784af7bf9
3 changed files with 25 additions and 20 deletions

View File

@ -3,21 +3,10 @@ from subprocess import check_call, PIPE
from path import Path
import shutil
from tempfile import mkdtemp, gettempdir
from test_pip import create_virtualenv
exe = '.EXE' if sys.platform == 'win32' else ''
def create_virtualenv(where):
save_argv = sys.argv
try:
import virtualenv
sys.argv = ['virtualenv', '--quiet', '--unzip-setuptools', '--no-site-packages', where]
virtualenv.main()
finally:
sys.argv = save_argv
return virtualenv.path_locations(where)
def rmtree(path):
# From pathutils by Michael Foord: http://www.voidspace.org.uk/python/pathutils.html
def onerror(func, path, exc_info):
@ -47,7 +36,12 @@ def system(*args):
check_call(args, stdout=PIPE, shell=(sys.platform=='win32'))
def call(*args):
check_call(args)
if not '--distribute' in sys.argv:
check_call(args)
else:
env = os.environ.copy()
env['PIP_TEST_USE_DISTRIBUTE']='1'
check_call(args, env=env)
def assert_in_path(exe):
system(exe, '--version')
@ -99,7 +93,7 @@ def main(argv):
# Prepare a clean, writable workspace
#
print >> sys.stderr, 'Preparing test environment ...'
venv, lib, include, bin = create_virtualenv(temp_dir)
venv, lib, include, bin = create_virtualenv(temp_dir, distribute=('--distribute' in sys.argv))
abs_bin = Path(bin).abspath
@ -123,7 +117,7 @@ def main(argv):
pip_install('scripttest>=1.0.4')
print >> sys.stderr, 'ok'
nosetests = abs_bin/'nosetests'+exe
call( nosetests, '-w', pip_root/'tests', *argv[1:] )
call( nosetests, '-w', pip_root/'tests', *(x for x in argv[1:] if x != '--distribute') )
finally:
os.chdir(save_dir)

View File

@ -1,9 +1,11 @@
import os, sys
import os, sys, re
import textwrap
from doctest import OutputChecker, ELLIPSIS
from test_pip import reset_env, run_pip, pyversion, write_file, get_env
distribute_re = re.compile('^distribute==[0-9.]+\n', re.MULTILINE)
def _check_output(result, expected):
checker = OutputChecker()
actual = str(result)
@ -19,6 +21,10 @@ def _check_output(result, expected):
if sys.platform == 'win32':
actual = actual.replace('initools','INITools')
# This allows our existing tests to work when run in a context
# with distribute installed.
actual = distribute_re.sub('', actual)
def banner(msg): return '\n========== %s ==========\n'%msg
assert checker.check_output(expected, actual, ELLIPSIS), banner('EXPECTED')+expected+banner('ACTUAL')+actual+banner(6*'=')

View File

@ -23,12 +23,13 @@ demand_dirs(download_cache)
sys.path = [src, os.path.join(src, 'scripttest')] + sys.path
from scripttest import TestFileEnvironment
def create_virtualenv(where):
def create_virtualenv(where, distribute=False):
save_argv = sys.argv
try:
import virtualenv
sys.argv = ['virtualenv', '--quiet', '--no-site-packages', '--unzip-setuptools', where]
distribute_opt = ['--distribute'] if distribute else []
sys.argv = ['virtualenv', '--quiet'] + distribute_opt + ['--no-site-packages', '--unzip-setuptools', where]
virtualenv.main()
finally:
sys.argv = save_argv
@ -238,8 +239,11 @@ class TestPipEnvironment(TestFileEnvironment):
demand_dirs(self.venv_path)
demand_dirs(self.scratch_path)
use_distribute = os.environ.get('PIP_TEST_USE_DISTRIBUTE', False)
# Create a virtualenv and remember where it's putting things.
virtualenv_paths = create_virtualenv(self.venv_path)
virtualenv_paths = create_virtualenv(self.venv_path, distribute=use_distribute)
assert self.venv_path == virtualenv_paths[0] # sanity check
for id,path in zip(('venv', 'lib', 'include', 'bin'), virtualenv_paths):
@ -263,7 +267,8 @@ class TestPipEnvironment(TestFileEnvironment):
" rather than expected %r" % (pythonbin, self.bin_path/'python'))
# make sure we have current setuptools to avoid svn incompatibilities
install_setuptools(self)
if not use_distribute:
install_setuptools(self)
# Uninstall whatever version of pip came with the virtualenv.
# Earlier versions of pip were incapable of