From 9784af7bf9c34a2928580c955d92b8646e1ffa19 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Fri, 21 May 2010 10:31:14 -0400 Subject: [PATCH] Make it testable with distribute in place of setuptools. Pass '--distribute' to auto_test.py to try using it in place of setuptools. --- tests/auto_test.py | 24 +++++++++--------------- tests/test_freeze.py | 8 +++++++- tests/test_pip.py | 13 +++++++++---- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/tests/auto_test.py b/tests/auto_test.py index 347a4673a..66de521a2 100644 --- a/tests/auto_test.py +++ b/tests/auto_test.py @@ -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) diff --git a/tests/test_freeze.py b/tests/test_freeze.py index be0d2be58..f725754d4 100644 --- a/tests/test_freeze.py +++ b/tests/test_freeze.py @@ -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*'=') diff --git a/tests/test_pip.py b/tests/test_pip.py index de85045c1..3f698887a 100644 --- a/tests/test_pip.py +++ b/tests/test_pip.py @@ -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