def test_download_should_skip_existing_files(): """ It should not download files already existing in the scratch dir """ env = reset_env() write_file('test-req.txt', textwrap.dedent(""" INITools==0.1 """)) result = run_pip('install', '-r', env.scratch_path/ 'test-req.txt', '-d', '.', expect_error=True) assert Path('scratch')/ 'INITools-0.1.tar.gz' in result.files_created assert env.site_packages/ 'initools' not in result.files_created # adding second package to test-req.txt write_file('test-req.txt', textwrap.dedent(""" INITools==0.1 python-openid==2.2.5 """)) # only the second package should be downloaded result = run_pip('install', '-r', env.scratch_path/ 'test-req.txt', '-d', '.', expect_error=True) openid_tarball_prefix = str(Path('scratch')/ 'python-openid-') assert any(path.startswith(openid_tarball_prefix) for path in result.files_created) assert Path('scratch')/ 'INITools-0.1.tar.gz' not in result.files_created assert env.site_packages/ 'initools' not in result.files_created assert env.site_packages/ 'openid' not in result.files_created
def test_download_should_download_dependencies(): """ It should download dependencies (in the scratch path) """ env = reset_env() result = run_pip('install', 'Paste[openid]==1.7.5.1', '-d', '.', expect_error=True) assert Path('scratch')/ 'Paste-1.7.5.1.tar.gz' in result.files_created openid_tarball_prefix = str(Path('scratch')/ 'python-openid-') assert any(path.startswith(openid_tarball_prefix) for path in result.files_created) assert env.site_packages/ 'openid' not in result.files_created
def test_install_folder_using_relative_path(): """ Test installing a folder using pip install folder1/folder2 """ env = reset_env() mkdir('initools') mkdir(Path('initools') / 'mock') pkg_path = env.scratch_path / 'initools' / 'mock' write_file('setup.py', mock100_setup_py, pkg_path) result = run_pip('install', Path('initools') / 'mock') egg_folder = env.site_packages / 'mock-100.1-py%s.egg-info' % pyversion assert egg_folder in result.files_created, str(result)
def test_create_bundle(): """ Test making a bundle. We'll grab one package from the filesystem (the FSPkg dummy package), one from vcs (initools) and one from an index (pip itself). """ env = reset_env() fspkg = path_to_url2(Path(here) / 'packages' / 'FSPkg') run_pip('install', '-e', fspkg) pkg_lines = textwrap.dedent( '''\ -e %s -e %s#egg=initools-dev pip''' % (fspkg, local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'))) write_file('bundle-req.txt', pkg_lines) # Create a bundle in env.scratch_path/ test.pybundle result = run_pip('bundle', '-r', env.scratch_path / 'bundle-req.txt', env.scratch_path / 'test.pybundle') bundle = result.files_after.get(join('scratch', 'test.pybundle'), None) assert bundle is not None files = zipfile.ZipFile(bundle.full).namelist() assert 'src/FSPkg/' in files assert 'src/initools/' in files assert 'build/pip/' in files
def test_install_package_with_target(): """ Test installing a package using pip install --target """ env = reset_env() target_dir = env.scratch_path/'target' result = run_pip('install', '-t', target_dir, "initools==0.1") assert Path('scratch')/'target'/'initools' in result.files_created, str(result)
def test_download_if_requested(): """ It should download (in the scratch path) and not install if requested. """ env = reset_env() result = run_pip('install', 'INITools==0.1', '-d', '.', expect_error=True) assert Path('scratch') / 'INITools-0.1.tar.gz' in result.files_created assert env.site_packages / 'initools' not in result.files_created
def run(self, *args, **kw): if self.verbose: print('>> running %s %s' % (args, kw)) cwd = kw.pop('cwd', None) run_from = kw.pop('run_from', None) assert not cwd or not run_from, "Don't use run_from; it's going away" cwd = Path.string(cwd or run_from or self.cwd) assert not isinstance(cwd, Path) return TestPipResult(super(TestPipEnvironment, self).run(cwd=cwd, *args, **kw), verbose=self.verbose)
def test_single_download_from_requirements_file(): """ It should support download (in the scratch path) from PyPi from a requirements file """ env = reset_env() write_file('test-req.txt', textwrap.dedent(""" INITools==0.1 """)) result = run_pip('install', '-r', env.scratch_path/ 'test-req.txt', '-d', '.', expect_error=True) assert Path('scratch')/ 'INITools-0.1.tar.gz' in result.files_created assert env.site_packages/ 'initools' not in result.files_created
def test_download_editable_to_custom_path(): """ Test downloading an editable using a relative custom src folder. """ reset_env() mkdir('customdl') result = run_pip( 'install', '-e', '%s#egg=initools-dev' % local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'), '--src', 'customsrc', '--download', 'customdl') customsrc = Path('scratch') / 'customsrc' / 'initools' assert customsrc in result.files_created, sorted( result.files_created.keys()) assert customsrc / 'setup.py' in result.files_created, sorted( result.files_created.keys()) customdl = Path('scratch') / 'customdl' / 'initools' customdl_files_created = [ filename for filename in result.files_created if filename.startswith(customdl) ] assert customdl_files_created
def test_no_install_and_download_should_not_leave_build_dir(): """ It should remove build/ dir if it was pip that created """ env = reset_env() mkdir('downloaded_packages') assert not os.path.exists(env.venv_path / '/build') result = run_pip('install', '--no-install', 'INITools==0.2', '-d', 'downloaded_packages') assert Path( 'scratch' ) / 'downloaded_packages/build' not in result.files_created, 'pip should not leave build/ dir' assert not os.path.exists( env.venv_path / '/build'), "build/ dir should be deleted"
def relpath(root, other): """a poor man's os.path.relpath, since we may not have Python 2.6""" prefix = root + Path.sep assert other.startswith(prefix) return Path(other[len(prefix):])
def __init__(self, environ=None, sitecustomize=None): import virtualenv self.root_path = fast_test_env_root self.backup_path = fast_test_env_backup self.scratch_path = self.root_path / self.scratch # We will set up a virtual environment at root_path. self.venv_path = self.root_path / self.venv if not environ: environ = os.environ.copy() environ = clear_environ(environ) environ['PIP_DOWNLOAD_CACHE'] = str(download_cache) environ['PIP_NO_INPUT'] = '1' environ['PIP_LOG_FILE'] = str(self.root_path / 'pip-log.txt') TestFileEnvironment.__init__(self, self.root_path, ignore_hidden=False, environ=environ, split_cmd=False, start_clear=False, cwd=self.scratch_path, capture_temp=True, assert_no_temp=True) virtualenv_paths = virtualenv.path_locations(self.venv_path) for id, path in zip(('venv', 'lib', 'include', 'bin'), virtualenv_paths): #fix for virtualenv issue #306 if hasattr(sys, "pypy_version_info") and id == 'lib': path = os.path.join(self.venv_path, 'lib-python', pyversion) setattr(self, id + '_path', Path(path)) setattr(self, id, relpath(self.root_path, path)) assert self.venv == TestPipEnvironment.venv # sanity check if hasattr(sys, "pypy_version_info"): self.site_packages = self.venv / 'site-packages' else: self.site_packages = self.lib / 'site-packages' self.user_base_path = self.venv_path / 'user' self.user_site_path = self.venv_path / 'user' / 'lib' / self.lib.name / 'site-packages' self.user_site = relpath(self.root_path, self.user_site_path) self.environ["PYTHONUSERBASE"] = self.user_base_path # put the test-scratch virtualenv's bin dir first on the PATH self.environ['PATH'] = Path.pathsep.join( (self.bin_path, self.environ['PATH'])) self.use_distribute = os.environ.get('PIP_TEST_USE_DISTRIBUTE', False) if self.root_path.exists: rmtree(self.root_path) if self.backup_path.exists: shutil.copytree(self.backup_path, self.root_path, True) else: demand_dirs(self.venv_path) demand_dirs(self.scratch_path) # Create a virtualenv and remember where it's putting things. create_virtualenv(self.venv_path, distribute=self.use_distribute) demand_dirs(self.user_site_path) # create easy-install.pth in user_site, so we always have it updated instead of created open(self.user_site_path / 'easy-install.pth', 'w').close() # test that test-scratch virtualenv creation produced sensible venv python result = self.run('python', '-c', 'import sys; print(sys.executable)') pythonbin = result.stdout.strip() if Path(pythonbin).noext != self.bin_path / 'python': raise RuntimeError( "Oops! 'python' in our test environment runs %r" " rather than expected %r" % (pythonbin, self.bin_path / 'python')) # make sure we have current setuptools to avoid svn incompatibilities if not self.use_distribute: install_setuptools(self) # Uninstall whatever version of pip came with the virtualenv. # Earlier versions of pip were incapable of # self-uninstallation on Windows, so we use the one we're testing. self.run( 'python', '-c', '"import sys; sys.path.insert(0, %r); import pip; sys.exit(pip.main());"' % os.path.dirname(here), 'uninstall', '-vvv', '-y', 'pip') # Install this version instead self.run('python', 'setup.py', 'install', cwd=src_folder, expect_stderr=True) # Install snakebasket as well self.run('python', 'setup.py', 'install', cwd=os.path.abspath(os.path.join(src_folder, '../')), expect_stderr=True) # Backup up test dir shutil.copytree(self.root_path, self.backup_path, True) #create sitecustomize.py and add patches self._create_empty_sitecustomize() self._use_cached_pypi_server() if sitecustomize: self._add_to_sitecustomize(sitecustomize) assert self.root_path.exists # Ensure that $TMPDIR exists (because we use start_clear=False, it's not created for us) if self.temp_path and not os.path.exists(self.temp_path): os.makedirs(self.temp_path)
class TestPipEnvironment(TestFileEnvironment): """A specialized TestFileEnvironment for testing pip""" # # Attribute naming convention # --------------------------- # # Instances of this class have many attributes representing paths # in the filesystem. To keep things straight, absolute paths have # a name of the form xxxx_path and relative paths have a name that # does not end in '_path'. # The following paths are relative to the root_path, and should be # treated by clients as instance attributes. The fact that they # are defined in the class is an implementation detail # where we'll create the virtual Python installation for testing # # Named with a leading dot to reduce the chance of spurious # results due to being mistaken for the virtualenv package. venv = Path('.virtualenv') # The root of a directory tree to be used arbitrarily by tests scratch = Path('scratch') exe = sys.platform == 'win32' and '.exe' or '' verbose = False def __init__(self, environ=None, use_distribute=None, sitecustomize=None): self.root_path = Path(tempfile.mkdtemp('-piptest')) # We will set up a virtual environment at root_path. self.scratch_path = self.root_path / self.scratch self.venv_path = self.root_path / self.venv if not environ: environ = os.environ.copy() environ = clear_environ(environ) environ['PIP_DOWNLOAD_CACHE'] = str(download_cache) environ['PIP_NO_INPUT'] = '1' environ['PIP_LOG_FILE'] = str(self.root_path / 'pip-log.txt') super(TestPipEnvironment, self).__init__(self.root_path, ignore_hidden=False, environ=environ, split_cmd=False, start_clear=False, cwd=self.scratch_path, capture_temp=True, assert_no_temp=True) demand_dirs(self.venv_path) demand_dirs(self.scratch_path) if use_distribute is None: use_distribute = os.environ.get('PIP_TEST_USE_DISTRIBUTE', False) self.use_distribute = use_distribute # Create a virtualenv and remember where it's putting things. virtualenv_paths = create_virtualenv(self.venv_path, distribute=self.use_distribute) assert self.venv_path == virtualenv_paths[0] # sanity check for id, path in zip(('venv', 'lib', 'include', 'bin'), virtualenv_paths): #fix for virtualenv issue #306 if hasattr(sys, "pypy_version_info") and id == 'lib': path = os.path.join(self.venv_path, 'lib-python', pyversion) setattr(self, id + '_path', Path(path)) setattr(self, id, relpath(self.root_path, path)) assert self.venv == TestPipEnvironment.venv # sanity check if hasattr(sys, "pypy_version_info"): self.site_packages = self.venv / 'site-packages' else: self.site_packages = self.lib / 'site-packages' self.user_base_path = self.venv_path / 'user' self.user_site_path = self.venv_path / 'user' / site_packages_suffix self.user_site = relpath(self.root_path, self.user_site_path) demand_dirs(self.user_site_path) self.environ["PYTHONUSERBASE"] = self.user_base_path # create easy-install.pth in user_site, so we always have it updated instead of created open(self.user_site_path / 'easy-install.pth', 'w').close() # put the test-scratch virtualenv's bin dir first on the PATH self.environ['PATH'] = Path.pathsep.join( (self.bin_path, self.environ['PATH'])) # test that test-scratch virtualenv creation produced sensible venv python result = self.run('python', '-c', 'import sys; print(sys.executable)') pythonbin = result.stdout.strip() if Path(pythonbin).noext != self.bin_path / 'python': raise RuntimeError("Oops! 'python' in our test environment runs %r" " rather than expected %r" % (pythonbin, self.bin_path / 'python')) # make sure we have current setuptools to avoid svn incompatibilities if not self.use_distribute: install_setuptools(self) # Uninstall whatever version of pip came with the virtualenv. # Earlier versions of pip were incapable of # self-uninstallation on Windows, so we use the one we're testing. self.run( 'python', '-c', '"import sys; sys.path.insert(0, %r); import pip; sys.exit(pip.main());"' % os.path.dirname(here), 'uninstall', '-vvv', '-y', 'pip') # Install this version instead self.run('python', 'setup.py', 'install', cwd=src_folder, expect_stderr=True) # Install snakebasket as well self.run('python', 'setup.py', 'install', cwd=os.path.abspath(os.path.join(src_folder, '../')), expect_stderr=True) #create sitecustomize.py and add patches self._create_empty_sitecustomize() self._use_cached_pypi_server() if sitecustomize: self._add_to_sitecustomize(sitecustomize) # Ensure that $TMPDIR exists (because we use start_clear=False, it's not created for us) if self.temp_path and not os.path.exists(self.temp_path): os.makedirs(self.temp_path) def _ignore_file(self, fn): if fn.endswith('__pycache__') or fn.endswith(".pyc"): result = True else: result = super(TestPipEnvironment, self)._ignore_file(fn) return result def run(self, *args, **kw): if self.verbose: print('>> running %s %s' % (args, kw)) cwd = kw.pop('cwd', None) run_from = kw.pop('run_from', None) assert not cwd or not run_from, "Don't use run_from; it's going away" cwd = Path.string(cwd or run_from or self.cwd) assert not isinstance(cwd, Path) return TestPipResult(super(TestPipEnvironment, self).run(cwd=cwd, *args, **kw), verbose=self.verbose) def __del__(self): rmtree(str(self.root_path), ignore_errors=True) def _use_cached_pypi_server(self): # previously, this was handled in a pth file, and not in sitecustomize.py # pth processing happens during the construction of sys.path. # 'import pypi_server' ultimately imports pkg_resources (which intializes pkg_resources.working_set based on the current state of sys.path) # pkg_resources.get_distribution (used in pip.req) requires an accurate pkg_resources.working_set # therefore, 'import pypi_server' shouldn't occur in a pth file. official_pip_tests_dir = os.path.abspath( os.path.join(str(here), '../pip/tests')) patch = """ import sys sys.path.insert(0, %r) import pypi_server pypi_server.PyPIProxy.setup() sys.path.remove(%r)""" % (official_pip_tests_dir, official_pip_tests_dir) self._add_to_sitecustomize(patch) def _create_empty_sitecustomize(self): "Create empty sitecustomize.py." sitecustomize_path = self.lib_path / 'sitecustomize.py' sitecustomize = open(sitecustomize_path, 'w') sitecustomize.close() def _add_to_sitecustomize(self, snippet): "Adds a python code snippet to sitecustomize.py." sitecustomize_path = self.lib_path / 'sitecustomize.py' sitecustomize = open(sitecustomize_path, 'a') sitecustomize.write( textwrap.dedent(''' %s ''' % snippet)) sitecustomize.close()
def __init__(self, environ=None, use_distribute=None): self.root_path = Path(tempfile.mkdtemp('-piptest')) # We will set up a virtual environment at root_path. self.scratch_path = self.root_path / self.scratch self.venv_path = self.root_path / self.venv if not environ: environ = os.environ.copy() environ = clear_environ(environ) environ['PIP_DOWNLOAD_CACHE'] = str(download_cache) environ['PIP_NO_INPUT'] = '1' environ['PIP_LOG_FILE'] = str(self.root_path / 'pip-log.txt') super(TestPipEnvironment, self).__init__(self.root_path, ignore_hidden=False, environ=environ, split_cmd=False, start_clear=False, cwd=self.scratch_path, capture_temp=True, assert_no_temp=True) demand_dirs(self.venv_path) demand_dirs(self.scratch_path) if use_distribute is None: 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, distribute=use_distribute) assert self.venv_path == virtualenv_paths[0] # sanity check for id, path in zip(('venv', 'lib', 'include', 'bin'), virtualenv_paths): setattr(self, id + '_path', Path(path)) setattr(self, id, relpath(self.root_path, path)) assert self.venv == TestPipEnvironment.venv # sanity check self.site_packages = self.lib / 'site-packages' self.user_base_path = self.venv_path / 'user' self.user_site_path = self.venv_path / 'user' / 'lib' / self.lib.name / 'site-packages' self.user_site = relpath(self.root_path, self.user_site_path) demand_dirs(self.user_site_path) self.environ["PYTHONUSERBASE"] = self.user_base_path # create easy-install.pth in user_site, so we always have it updated instead of created open(self.user_site_path / 'easy-install.pth', 'w').close() # put the test-scratch virtualenv's bin dir first on the PATH self.environ['PATH'] = Path.pathsep.join( (self.bin_path, self.environ['PATH'])) # test that test-scratch virtualenv creation produced sensible venv python result = self.run('python', '-c', 'import sys; print(sys.executable)') pythonbin = result.stdout.strip() if Path(pythonbin).noext != self.bin_path / 'python': raise RuntimeError("Oops! 'python' in our test environment runs %r" " rather than expected %r" % (pythonbin, self.bin_path / 'python')) # make sure we have current setuptools to avoid svn incompatibilities if not use_distribute: install_setuptools(self) # Uninstall whatever version of pip came with the virtualenv. # Earlier versions of pip were incapable of # self-uninstallation on Windows, so we use the one we're testing. self.run( 'python', '-c', '"import sys; sys.path.insert(0, %r); import pip; sys.exit(pip.main());"' % os.path.dirname(here), 'uninstall', '-vvv', '-y', 'pip') # Install this version instead self.run('python', 'setup.py', 'install', cwd=src_folder, expect_stderr=True) self._use_cached_pypi_server()
import os import sys import tempfile import shutil import glob import atexit import textwrap import site import imp from scripttest import TestFileEnvironment, FoundDir from tests.path import Path, curdir, u pyversion = sys.version[:3] # the directory containing all the tests here = Path(__file__).abspath.folder # the directory containing all the tests src_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), '../pip')) # the root of this pip source distribution download_cache = tempfile.mkdtemp(prefix='pip-test-cache') site_packages_suffix = site.USER_SITE[len(site.USER_BASE) + 1:] # Tweak the path so we can find up-to-date pip sources # (http://bitbucket.org/ianb/pip/issue/98) sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'pip')) from pip.util import rmtree def path_to_url(path):
class TestPipEnvironment(TestFileEnvironment): """A specialized TestFileEnvironment for testing pip""" # # Attribute naming convention # --------------------------- # # Instances of this class have many attributes representing paths # in the filesystem. To keep things straight, absolute paths have # a name of the form xxxx_path and relative paths have a name that # does not end in '_path'. # The following paths are relative to the root_path, and should be # treated by clients as instance attributes. The fact that they # are defined in the class is an implementation detail # where we'll create the virtual Python installation for testing # # Named with a leading dot to reduce the chance of spurious # results due to being mistaken for the virtualenv package. venv = Path('.virtualenv') # The root of a directory tree to be used arbitrarily by tests scratch = Path('scratch') exe = sys.platform == 'win32' and '.exe' or '' verbose = False def __init__(self, environ=None, use_distribute=None): self.root_path = Path(tempfile.mkdtemp('-piptest')) # We will set up a virtual environment at root_path. self.scratch_path = self.root_path / self.scratch self.venv_path = self.root_path / self.venv if not environ: environ = os.environ.copy() environ = clear_environ(environ) environ['PIP_DOWNLOAD_CACHE'] = str(download_cache) environ['PIP_NO_INPUT'] = '1' environ['PIP_LOG_FILE'] = str(self.root_path / 'pip-log.txt') super(TestPipEnvironment, self).__init__(self.root_path, ignore_hidden=False, environ=environ, split_cmd=False, start_clear=False, cwd=self.scratch_path, capture_temp=True, assert_no_temp=True) demand_dirs(self.venv_path) demand_dirs(self.scratch_path) if use_distribute is None: 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, distribute=use_distribute) assert self.venv_path == virtualenv_paths[0] # sanity check for id, path in zip(('venv', 'lib', 'include', 'bin'), virtualenv_paths): setattr(self, id + '_path', Path(path)) setattr(self, id, relpath(self.root_path, path)) assert self.venv == TestPipEnvironment.venv # sanity check self.site_packages = self.lib / 'site-packages' self.user_base_path = self.venv_path / 'user' self.user_site_path = self.venv_path / 'user' / 'lib' / self.lib.name / 'site-packages' self.user_site = relpath(self.root_path, self.user_site_path) demand_dirs(self.user_site_path) self.environ["PYTHONUSERBASE"] = self.user_base_path # create easy-install.pth in user_site, so we always have it updated instead of created open(self.user_site_path / 'easy-install.pth', 'w').close() # put the test-scratch virtualenv's bin dir first on the PATH self.environ['PATH'] = Path.pathsep.join( (self.bin_path, self.environ['PATH'])) # test that test-scratch virtualenv creation produced sensible venv python result = self.run('python', '-c', 'import sys; print(sys.executable)') pythonbin = result.stdout.strip() if Path(pythonbin).noext != self.bin_path / 'python': raise RuntimeError("Oops! 'python' in our test environment runs %r" " rather than expected %r" % (pythonbin, self.bin_path / 'python')) # make sure we have current setuptools to avoid svn incompatibilities if not use_distribute: install_setuptools(self) # Uninstall whatever version of pip came with the virtualenv. # Earlier versions of pip were incapable of # self-uninstallation on Windows, so we use the one we're testing. self.run( 'python', '-c', '"import sys; sys.path.insert(0, %r); import pip; sys.exit(pip.main());"' % os.path.dirname(here), 'uninstall', '-vvv', '-y', 'pip') # Install this version instead self.run('python', 'setup.py', 'install', cwd=src_folder, expect_stderr=True) self._use_cached_pypi_server() def _ignore_file(self, fn): if fn.endswith('__pycache__') or fn.endswith(".pyc"): result = True else: result = super(TestPipEnvironment, self)._ignore_file(fn) return result def run(self, *args, **kw): if self.verbose: print('>> running %s %s' % (args, kw)) cwd = kw.pop('cwd', None) run_from = kw.pop('run_from', None) assert not cwd or not run_from, "Don't use run_from; it's going away" cwd = Path.string(cwd or run_from or self.cwd) assert not isinstance(cwd, Path) return TestPipResult(super(TestPipEnvironment, self).run(cwd=cwd, *args, **kw), verbose=self.verbose) def __del__(self): rmtree(str(self.root_path), ignore_errors=True) def _use_cached_pypi_server(self): site_packages = self.root_path / self.site_packages pth = open(os.path.join(site_packages, 'pypi_intercept.pth'), 'w') pth.write('import sys; ') pth.write('sys.path.insert(0, %r); ' % str(here)) pth.write('import pypi_server; pypi_server.PyPIProxy.setup(); ') pth.write('sys.path.remove(%r); ' % str(here)) pth.close()
from pip.backwardcompat import urllib from pip.req import InstallRequirement from pip.index import PackageFinder from tests.path import Path from tests.test_pip import here find_links = 'file://' + urllib.quote( str(Path(here).abspath / 'packages').replace('\\', '/')) def test_no_mpkg(): """Finder skips zipfiles with "macosx10" in the name.""" finder = PackageFinder([find_links], []) req = InstallRequirement.from_line("pkgwithmpkg") found = finder.find_requirement(req, False) assert found.url.endswith("pkgwithmpkg-1.0.tar.gz"), found def test_no_partial_name_match(): """Finder requires the full project name to match, not just beginning.""" finder = PackageFinder([find_links], []) req = InstallRequirement.from_line("gmpy") found = finder.find_requirement(req, False) assert found.url.endswith("gmpy-1.15.tar.gz"), found
def assert_installed(self, pkg_name, with_files=[], without_files=[], without_egg_link=False, use_user_site=False): e = self.test_env pkg_dir = e.venv/ 'src'/ pkg_name.lower() if use_user_site: egg_link_path = e.user_site / pkg_name + '.egg-link' else: egg_link_path = e.site_packages / pkg_name + '.egg-link' if without_egg_link: if egg_link_path in self.files_created: raise TestFailure('unexpected egg link file created: '\ '%r\n%s' % (egg_link_path, self)) else: if not egg_link_path in self.files_created: raise TestFailure('expected egg link file missing: '\ '%r\n%s' % (egg_link_path, self)) egg_link_file = self.files_created[egg_link_path] if not (# FIXME: I don't understand why there's a trailing . here egg_link_file.bytes.endswith('.') and egg_link_file.bytes[:-1].strip().endswith(pkg_dir)): raise TestFailure(textwrap.dedent(u('''\ Incorrect egg_link file %r Expected ending: %r ------- Actual contents ------- %s -------------------------------''' % ( egg_link_file, pkg_dir + u('\n.'), egg_link_file.bytes)))) if use_user_site: pth_file = Path.string(e.user_site / 'easy-install.pth') else: pth_file = Path.string(e.site_packages / 'easy-install.pth') if (pth_file in self.files_updated) == without_egg_link: raise TestFailure('%r unexpectedly %supdated by install' % ( pth_file, (not without_egg_link and 'not ' or ''))) if (pkg_dir in self.files_created) == (curdir in without_files): raise TestFailure(textwrap.dedent('''\ expected package directory %r %sto be created actually created: %s ''') % ( Path.string(pkg_dir), (curdir in without_files and 'not ' or ''), sorted(self.files_created.keys()))) for f in with_files: if not (pkg_dir/f).normpath in self.files_created: raise TestFailure('Package directory %r missing '\ 'expected content %f' % (pkg_dir, f)) for f in without_files: if (pkg_dir/f).normpath in self.files_created: raise TestFailure('Package directory %r has '\ 'unexpected content %f' % (pkg_dir, f))
from pip.backwardcompat import urllib from tests.test_pip import here, reset_env, run_pip, pyversion from tests.path import Path index_url = 'file://' + urllib.quote( str(Path(here).abspath / 'in dex').replace('\\', '/')) def test_install(): """ Test installing from a local index. """ env = reset_env() result = run_pip('install', '-vvv', '--index-url', index_url, 'FSPkg', expect_error=False) assert (env.site_packages / 'fspkg') in result.files_created, str( result.stdout) assert (env.site_packages / 'FSPkg-0.1dev-py%s.egg-info' % pyversion) in result.files_created, str(result)
def assert_installed(self, pkg_name, with_files=[], without_files=[], without_egg_link=False, use_user_site=False): e = self.test_env pkg_dir = e.venv / 'src' / pkg_name.lower() if use_user_site: egg_link_path = e.user_site / pkg_name + '.egg-link' else: egg_link_path = e.site_packages / pkg_name + '.egg-link' if without_egg_link: if egg_link_path in self.files_created: raise TestFailure('unexpected egg link file created: '\ '%r\n%s' % (egg_link_path, self)) else: if not egg_link_path in self.files_created: raise TestFailure('expected egg link file missing: '\ '%r\n%s' % (egg_link_path, self)) egg_link_file = self.files_created[egg_link_path] if not ( # FIXME: I don't understand why there's a trailing . here egg_link_file.bytes.endswith('.') and egg_link_file.bytes[:-1].strip().endswith(pkg_dir)): raise TestFailure( textwrap.dedent( u('''\ Incorrect egg_link file %r Expected ending: %r ------- Actual contents ------- %s -------------------------------''' % (egg_link_file, pkg_dir + u('\n.'), egg_link_file.bytes)))) if use_user_site: pth_file = Path.string(e.user_site / 'easy-install.pth') else: pth_file = Path.string(e.site_packages / 'easy-install.pth') if (pth_file in self.files_updated) == without_egg_link: raise TestFailure('%r unexpectedly %supdated by install' % (pth_file, (not without_egg_link and 'not ' or ''))) if (pkg_dir in self.files_created) == (curdir in without_files): raise TestFailure( textwrap.dedent('''\ expected package directory %r %sto be created actually created: %s ''') % (Path.string(pkg_dir), (curdir in without_files and 'not ' or ''), sorted(self.files_created.keys()))) for f in with_files: if not (pkg_dir / f).normpath in self.files_created: raise TestFailure('Package directory %r missing '\ 'expected content %f' % (pkg_dir, f)) for f in without_files: if (pkg_dir / f).normpath in self.files_created: raise TestFailure('Package directory %r has '\ 'unexpected content %f' % (pkg_dir, f))