def _get_vcs_and_checkout_url(remote_repository):
    tests_cache = _get_vcs_folder()
    vcs_classes = {
        'svn': subversion.Subversion,
        'git': git.Git,
        'bzr': bazaar.Bazaar,
        'hg': mercurial.Mercurial
    }
    default_vcs = 'svn'
    if '+' not in remote_repository:
        remote_repository = '%s+%s' % (default_vcs, remote_repository)
    vcs, repository_path = remote_repository.split('+', 1)
    vcs_class = vcs_classes[vcs]
    branch = ''
    if vcs == 'svn':
        branch = os.path.basename(remote_repository)
        repository_name = os.path.basename(
            remote_repository[:-len(branch) - 1])  # remove the slash
    else:
        repository_name = os.path.basename(remote_repository)

    destination_path = os.path.join(tests_cache, repository_name)
    if not os.path.exists(destination_path):
        vcs_class(remote_repository).obtain(destination_path)
    return '%s+%s' % (
        vcs, path_to_url('/'.join([tests_cache, repository_name, branch])))
Exemplo n.º 2
0
def test_sort_locations_file_not_find_link():
    """
    Test that a file:// url dir that's not a find-link, doesn't get a listdir run
    """
    index_url = path_to_url(os.path.join(here, 'indexes', 'empty_with_pkg'))
    finder = PackageFinder([], [])
    files, urls = finder._sort_locations([index_url])
    assert urls and not files, "urls, but not files should have been found"
Exemplo n.º 3
0
def test_sort_locations_file_not_find_link():
    """
    Test that a file:// url dir that's not a find-link, doesn't get a listdir run
    """
    index_url = path_to_url(os.path.join(here, 'indexes', 'empty_with_pkg'))
    finder = PackageFinder([], [])
    files, urls = finder._sort_locations([index_url])
    assert urls and not files, "urls, but not files should have been found"
Exemplo n.º 4
0
def test_sort_locations_file_find_link():
    """
    Test that a file:// find-link dir gets listdir run
    """
    find_links_url = path_to_url(os.path.join(here, 'packages'))
    find_links = [find_links_url]
    finder = PackageFinder(find_links, [])
    files, urls = finder._sort_locations(find_links)
    assert files and not urls, "files and not urls should have been found at find-links url: %s" % find_links_url
Exemplo n.º 5
0
def test_sort_locations_file_find_link():
    """
    Test that a file:// find-link dir gets listdir run
    """
    find_links_url = path_to_url(os.path.join(here, 'packages'))
    find_links = [find_links_url]
    finder = PackageFinder(find_links, [])
    files, urls = finder._sort_locations(find_links)
    assert files and not urls, "files and not urls should have been found at find-links url: %s" % find_links_url
Exemplo n.º 6
0
def test_install_from_file_index_hash_link():
    """
    Test that a pkg can be installed from a file:// index using a link with a hash
    """
    env = reset_env()
    index_url = path_to_url(os.path.join(here, 'indexes', 'simple'))
    result = run_pip('install', '-i', index_url, 'simple==1.0')
    egg_info_folder = env.site_packages / 'simple-1.0-py%s.egg-info' % pyversion
    assert egg_info_folder in result.files_created, str(result)
Exemplo n.º 7
0
def test_file_index_url_quoting():
    """
    Test url quoting of file index url with a space
    """
    index_url = path_to_url(os.path.join(here, 'indexes', urllib.quote('in dex')))
    env = reset_env()
    result = run_pip('install', '-vvv', '--index-url', index_url, 'simple', expect_error=False)
    assert (env.site_packages/'simple') in result.files_created, str(result.stdout)
    assert (env.site_packages/'simple-1.0-py%s.egg-info' % pyversion) in result.files_created, str(result)
Exemplo n.º 8
0
def test_install_from_file_index_hash_link():
    """
    Test that a pkg can be installed from a file:// index using a link with a hash
    """
    env = reset_env()
    index_url = path_to_url(os.path.join(here, 'indexes', 'simple'))
    result = run_pip('install', '-i', index_url, 'simple==1.0')
    egg_info_folder = env.site_packages / 'simple-1.0-py%s.egg-info' % pyversion
    assert egg_info_folder in result.files_created, str(result)
Exemplo n.º 9
0
def test_upgrade_with_newest_already_installed():
    """
    If the newest version of a package is already installed, the package should
    not be reinstalled and the user should be informed.
    """

    find_links = path_to_url(os.path.join(here, 'packages'))
    env = reset_env()
    run_pip('install', '-f', find_links, '--no-index', 'simple')
    result =  run_pip('install', '--upgrade', '-f', find_links, '--no-index', 'simple')
    assert not result.files_created, 'simple upgraded when it should not have'
    assert 'already up-to-date' in result.stdout, result.stdout
def test_relative_requirements_file():
    """
    Test installing from a requirements file with a relative path with an egg= definition..

    """
    url = path_to_url(os.path.join(here, 'packages', '..', 'packages', 'FSPkg')) + '#egg=FSPkg'
    env = reset_env()
    write_file('file-egg-req.txt', textwrap.dedent("""\
        %s
        """ % url))
    result = run_pip('install', '-vvv', '-r', env.scratch_path / 'file-egg-req.txt')
    assert (env.site_packages/'FSPkg-0.1dev-py%s.egg-info' % pyversion) in result.files_created, str(result)
    assert (env.site_packages/'fspkg') in result.files_created, str(result.stdout)
Exemplo n.º 11
0
def test_command_line_appends_correctly():
    """
    Test multiple appending options set by environmental variables.

    """
    environ = clear_environ(os.environ.copy())
    find_links = path_to_url(os.path.join(here, 'packages'))
    environ['PIP_FIND_LINKS'] = 'http://pypi.pinaxproject.com %s' % find_links
    reset_env(environ)
    result = run_pip('install', '-vvv', 'INITools', expect_error=True)

    assert "Analyzing links from page http://pypi.pinaxproject.com" in result.stdout, result.stdout
    assert "Skipping link %s" % find_links in result.stdout
Exemplo n.º 12
0
def test_install_package_with_root():
    """
    Test installing a package using pip install --root
    """
    env = reset_env()
    root_dir = env.scratch_path/'root'
    find_links = path_to_url(os.path.join(here, 'packages'))
    result = run_pip('install', '--root', root_dir, '-f', find_links, '--no-index', 'simple==1.0')
    normal_install_path = env.root_path / env.site_packages / 'simple-1.0-py%s.egg-info' % pyversion
    #use distutils to change the root exactly how the --root option does it
    from distutils.util import change_root
    root_path = change_root(os.path.join(env.scratch, 'root'), normal_install_path)
    assert root_path in result.files_created, str(result)
Exemplo n.º 13
0
def test_relative_requirements_file():
    """
    Test installing from a requirements file with a relative path with an egg= definition..

    """
    url = path_to_url(os.path.join(here, 'packages', '..', 'packages', 'FSPkg')) + '#egg=FSPkg'
    env = reset_env()
    write_file('file-egg-req.txt', textwrap.dedent("""\
        %s
        """ % url))
    result = run_pip('install', '-vvv', '-r', env.scratch_path / 'file-egg-req.txt')
    assert (env.site_packages/'FSPkg-0.1dev-py%s.egg-info' % pyversion) in result.files_created, str(result)
    assert (env.site_packages/'fspkg') in result.files_created, str(result.stdout)
Exemplo n.º 14
0
def test_uninstall_rollback():
    """
    Test uninstall-rollback (using test package with a setup.py
    crafted to fail on install).

    """
    env = reset_env()
    find_links = path_to_url(os.path.join(here, 'packages'))
    result = run_pip('install', '-f', find_links, '--no-index', 'broken==0.1')
    assert env.site_packages / 'broken.py' in result.files_created, list(result.files_created.keys())
    result2 = run_pip('install', '-f', find_links, '--no-index', 'broken==0.2broken', expect_error=True)
    assert result2.returncode == 1, str(result2)
    assert env.run('python', '-c', "import broken; print(broken.VERSION)").stdout == '0.1\n'
    assert_all_changes(result.files_after, result2, [env.venv/'build', 'pip-log.txt'])
Exemplo n.º 15
0
def test_install_package_with_root():
    """
    Test installing a package using pip install --root
    """
    env = reset_env()
    root_dir = env.scratch_path / 'root'
    find_links = path_to_url(os.path.join(here, 'packages'))
    result = run_pip('install', '--root', root_dir, '-f', find_links,
                     '--no-index', 'simple==1.0')
    normal_install_path = env.root_path / env.site_packages / 'simple-1.0-py%s.egg-info' % pyversion
    #use distutils to change the root exactly how the --root option does it
    from distutils.util import change_root
    root_path = change_root(os.path.join(env.scratch, 'root'),
                            normal_install_path)
    assert root_path in result.files_created, str(result)
Exemplo n.º 16
0
def test_command_line_append_flags():
    """
    Test command line flags that append to defaults set by environmental variables.

    """
    environ = clear_environ(os.environ.copy())
    environ['PIP_FIND_LINKS'] = 'http://pypi.pinaxproject.com'
    reset_env(environ)
    result = run_pip('install', '-vvv', 'INITools', expect_error=True)
    assert "Analyzing links from page http://pypi.pinaxproject.com" in result.stdout
    reset_env(environ)
    find_links = path_to_url(os.path.join(here, 'packages'))
    result = run_pip('install', '-vvv', '--find-links', find_links, 'INITools', expect_error=True)
    assert "Analyzing links from page http://pypi.pinaxproject.com" in result.stdout
    assert "Skipping link %s" % find_links in result.stdout
Exemplo n.º 17
0
def test_file_index_url_quoting():
    """
    Test url quoting of file index url with a space
    """
    index_url = path_to_url(
        os.path.join(here, 'indexes', urllib.quote('in dex')))
    env = reset_env()
    result = run_pip('install',
                     '-vvv',
                     '--index-url',
                     index_url,
                     'simple',
                     expect_error=False)
    assert (env.site_packages / 'simple') in result.files_created, str(
        result.stdout)
    assert (env.site_packages / 'simple-1.0-py%s.egg-info' %
            pyversion) in result.files_created, str(result)
Exemplo n.º 18
0
def _get_vcs_and_checkout_url(remote_repository):
    tests_cache = _get_vcs_folder()
    vcs_classes = {'svn': subversion.Subversion,
                   'git': git.Git,
                   'bzr': bazaar.Bazaar,
                   'hg': mercurial.Mercurial}
    default_vcs = 'svn'
    if '+' not in remote_repository:
        remote_repository = '%s+%s' % (default_vcs, remote_repository)
    vcs, repository_path = remote_repository.split('+', 1)
    vcs_class = vcs_classes[vcs]
    branch = ''
    if vcs == 'svn':
        branch = os.path.basename(remote_repository)
        repository_name = os.path.basename(remote_repository[:-len(branch)-1]) # remove the slash
    else:
        repository_name = os.path.basename(remote_repository)

    destination_path = os.path.join(tests_cache, repository_name)
    if not os.path.exists(destination_path):
        vcs_class(remote_repository).obtain(destination_path)
    return '%s+%s' % (vcs, path_to_url('/'.join([tests_cache, repository_name, branch])))
Exemplo n.º 19
0
import os
from pkg_resources import parse_version
from pip.backwardcompat import urllib
from pip.req import InstallRequirement
from pip.index import PackageFinder
from pip.exceptions import BestVersionAlreadyInstalled
from tests.path import Path
from tests.test_pip import here, path_to_url
from nose.tools import assert_raises
from mock import Mock

find_links = path_to_url(os.path.join(here, 'packages'))
find_links2 = path_to_url(os.path.join(here, 'packages2'))


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
Exemplo n.º 20
0
import os
import re
import textwrap
from tests.test_pip import pyversion, reset_env, run_pip, write_file, path_to_url, here
from tests.local_repos import local_checkout

find_links = path_to_url(os.path.join(here, 'packages'))


def test_list_command():
    """
    Test default behavior of list command.

    """
    reset_env()
    run_pip('install', '-f', find_links, '--no-index', 'simple==1.0',
            'simple2==3.0')
    result = run_pip('list')
    assert 'simple (1.0)' in result.stdout, str(result)
    assert 'simple2 (3.0)' in result.stdout, str(result)


def test_local_flag():
    """
    Test the behavior of --local flag in the list command

    """
    reset_env()
    run_pip('install', '-f', find_links, '--no-index', 'simple==1.0')
    result = run_pip('list', '--local')
    assert 'simple (1.0)' in result.stdout
Exemplo n.º 21
0
import os
from pkg_resources import parse_version
from pip.backwardcompat import urllib
from pip.req import InstallRequirement
from pip.index import PackageFinder
from pip.exceptions import BestVersionAlreadyInstalled
from tests.path import Path
from tests.test_pip import here, path_to_url
from nose.tools import assert_raises
from mock import Mock

find_links = path_to_url(os.path.join(here, "packages"))
find_links2 = path_to_url(os.path.join(here, "packages2"))


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