def test_help_command_should_exit_status_error_when_command_does_not_exist():
    """
    Test `help` command for non-existing command
    """
    reset_env()
    result = run_pip('help', 'mycommand', expect_error=True)
    assert result.returncode == ERROR
def test_help_command_should_exit_status_ok_when_command_exists():
    """
    Test `help` command for existing command
    """
    reset_env()
    result = run_pip('help', 'freeze')
    assert result.returncode == SUCCESS
def test_help_command_should_exit_status_ok_when_no_command_is_specified():
    """
    Test `help` command for no command
    """
    reset_env()
    result = run_pip('help')
    assert result.returncode == SUCCESS
示例#4
0
def _test_config_file_override_stack(config_file):
    environ = clear_environ(os.environ.copy())
    environ["PIP_CONFIG_FILE"] = config_file  # set this to make pip load it
    reset_env(environ)
    write_file(
        config_file,
        textwrap.dedent(
            """\
        [global]
        index-url = http://download.zope.org/ppix
        """
        ),
    )
    result = run_pip("install", "-vvv", "INITools", expect_error=True)
    assert "Getting page http://download.zope.org/ppix/INITools" in result.stdout
    reset_env(environ)
    write_file(
        config_file,
        textwrap.dedent(
            """\
        [global]
        index-url = http://download.zope.org/ppix
        [install]
        index-url = http://pypi.appspot.com/
        """
        ),
    )
    result = run_pip("install", "-vvv", "INITools", expect_error=True)
    assert "Getting page http://pypi.appspot.com/INITools" in result.stdout
    result = run_pip("install", "-vvv", "--index-url", "http://pypi.python.org/simple", "INITools", expect_error=True)
    assert "Getting page http://download.zope.org/ppix/INITools" not in result.stdout
    assert "Getting page http://pypi.appspot.com/INITools" not in result.stdout
    assert "Getting page http://pypi.python.org/simple/INITools" in result.stdout
示例#5
0
def test_upgrade_editable_if_no_prefer_pinned():
    """
    Upgrade editable if 1)--prefer-pinned-revision is False (default) and 2) previously installed version is pinned and not the latest version.

    """
    reset_env()

    local_url = local_checkout('git+http://github.com/prezi/sb-test-package.git')

    args = ['install',
        # older version
        '-e', '%[email protected]#egg=sb-test-package' % local_url]

    result = run_pip(*args, **{"expect_error": True})
    result.assert_installed('sb-test-package')

    args = ['install',
        # unpinned newer version
        '-e', '%s#egg=sb-test-package' % local_url]
    result = run_pip(*args, **{"expect_error": True})

    # worrysome_files_created are all files that aren't located in .git/, created by the comparison `git fetch`
    expected_files_regex = re.compile('[.]git')
    new_files_created = [file_path for file_path in result.files_created.keys() if not expected_files_regex.search(file_path)]

    # new_files_created should contain a file that appears in versions >=0.2.1, but not in 0.2.2
    assert new_files_created, 'sb install sb-test-package did not upgrade when it should have'
示例#6
0
def test_freeze_mercurial_clone():
    """
    Test freezing a Mercurial clone.

    """
    reset_env()
    env = get_env()
    result = env.run('hg', 'clone',
                     '-r', '7bc186caa7dc',
                     local_repo('hg+http://bitbucket.org/jezdez/django-authority'),
                     'django-authority')
    result = env.run('python', 'setup.py', 'develop',
            cwd=env.scratch_path/'django-authority', expect_stderr=True)
    result = run_pip('freeze', expect_stderr=True)
    expected = textwrap.dedent("""\
        Script result: ...pip freeze
        -- stdout: --------------------
        -e %s@...#egg=django_authority-...
        ...""" % local_checkout('hg+http://bitbucket.org/jezdez/django-authority'))
    _check_output(result, expected)

    result = run_pip('freeze', '-f',
                     '%s#egg=django_authority' % local_checkout('hg+http://bitbucket.org/jezdez/django-authority'),
                     expect_stderr=True)
    expected = textwrap.dedent("""\
        Script result: ...pip freeze -f %(repo)s#egg=django_authority
        -- stdout: --------------------
        -f %(repo)s#egg=django_authority
        -e %(repo)s@...#egg=django_authority-dev
        ...""" % {'repo': local_checkout('hg+http://bitbucket.org/jezdez/django-authority')})
    _check_output(result, expected)
示例#7
0
文件: test_freeze.py 项目: OldBao/pip
def test_freeze_with_requirement_option():
    """
    Test that new requirements are created correctly with --requirement hints

    """
    reset_env()
    ignores = textwrap.dedent("""\
        # Unchanged requirements below this line
        -r ignore.txt
        --requirement ignore.txt
        -Z ignore
        --always-unzip ignore
        -f http://ignore
        -i http://ignore
        --extra-index-url http://ignore
        --find-links http://ignore
        --index-url http://ignore
        """)
    write_file('hint.txt', textwrap.dedent("""\
        INITools==0.1
        NoExist==4.2
        """) + ignores)
    result = run_pip('install', 'initools==0.2')
    result = run_pip('install', 'MarkupSafe')
    result = run_pip('freeze', '--requirement', 'hint.txt', expect_stderr=True)
    expected = textwrap.dedent("""\
        Script result: pip freeze --requirement hint.txt
        -- stderr: --------------------
        Requirement file contains NoExist==4.2, but that package is not installed

        -- stdout: --------------------
        INITools==0.2
        """) + ignores + "## The following requirements were added by pip --freeze:..."
    _check_output(result, expected)
示例#8
0
def test_freeze_with_local_option():
    """
    Test that wsgiref (from global site-packages) is reported normally, but not with --local.

    """
    reset_env()
    result = run_pip('install', 'initools==0.2')
    result = run_pip('freeze', expect_stderr=True)
    expected = textwrap.dedent("""\
        Script result: ...pip freeze
        -- stdout: --------------------
        INITools==0.2
        wsgiref==...
        <BLANKLINE>""")

    # The following check is broken (see
    # http://bitbucket.org/ianb/pip/issue/110).  For now we are simply
    # neutering this test, but if we can't find a way to fix it,
    # this whole function should be removed.

    # _check_output(result, expected)

    result = run_pip('freeze', '--local', expect_stderr=True)
    expected = textwrap.dedent("""\
        Script result: ...pip freeze --local
        -- stdout: --------------------
        INITools==0.2
        <BLANKLINE>""")
    _check_output(result, expected)
示例#9
0
def test_freeze_bazaar_clone():
    """
    Test freezing a Bazaar clone.

    """
    reset_env()
    env = get_env()
    result = env.run('bzr', 'checkout', '-r', '174',
                     local_repo('bzr+http://bazaar.launchpad.net/%7Edjango-wikiapp/django-wikiapp/release-0.1'),
                     'django-wikiapp')
    result = env.run('python', 'setup.py', 'develop',
            cwd=env.scratch_path/'django-wikiapp')
    result = run_pip('freeze', expect_stderr=True)
    expected = textwrap.dedent("""\
        Script result: ...pip freeze
        -- stdout: --------------------
        -e %s@...#egg=django_wikiapp-...
        ...""" % local_checkout('bzr+http://bazaar.launchpad.net/%7Edjango-wikiapp/django-wikiapp/release-0.1'))
    _check_output(result, expected)

    result = run_pip('freeze', '-f',
                     '%s/#egg=django-wikiapp' %
                     local_checkout('bzr+http://bazaar.launchpad.net/%7Edjango-wikiapp/django-wikiapp/release-0.1'),
                     expect_stderr=True)
    expected = textwrap.dedent("""\
        Script result: ...pip freeze -f %(repo)s/#egg=django-wikiapp
        -- stdout: --------------------
        -f %(repo)s/#egg=django-wikiapp
        -e %(repo)s@...#egg=django_wikiapp-...
        ...""" % {'repo':
                  local_checkout('bzr+http://bazaar.launchpad.net/%7Edjango-wikiapp/django-wikiapp/release-0.1')})
    _check_output(result, expected)
示例#10
0
def test_freeze_bazaar_clone():
    """
    Test freezing a Bazaar clone.

    """

    checkout_path = local_checkout('bzr+http://bazaar.launchpad.net/%7Edjango-wikiapp/django-wikiapp/release-0.1')
    #bzr internally stores windows drives as uppercase; we'll match that.
    checkout_pathC = checkout_path.replace('c:', 'C:')

    reset_env()
    env = get_env()
    result = env.run('bzr', 'checkout', '-r', '174',
                     local_repo('bzr+http://bazaar.launchpad.net/%7Edjango-wikiapp/django-wikiapp/release-0.1'),
                     'django-wikiapp')
    result = env.run('python', 'setup.py', 'develop',
            cwd=env.scratch_path/'django-wikiapp')
    result = run_pip('freeze', expect_stderr=True)
    expected = textwrap.dedent("""\
        Script result: ...pip freeze
        -- stdout: --------------------
        ...-e %s@...#egg=django_wikiapp-...
        ...""" % checkout_pathC)
    _check_output(result, expected)

    result = run_pip('freeze', '-f',
                     '%s/#egg=django-wikiapp' % checkout_path,
                     expect_stderr=True)
    expected = textwrap.dedent("""\
        Script result: ...pip freeze -f %(repo)s/#egg=django-wikiapp
        -- stdout: --------------------
        -f %(repo)s/#egg=django-wikiapp
        ...-e %(repoC)s@...#egg=django_wikiapp-...
        ...""" % {'repoC': checkout_pathC, 'repo': checkout_path})
    _check_output(result, expected)
示例#11
0
文件: test_basic.py 项目: saxix/pip
def test_install_with_pax_header():
    """
    test installing from a tarball with pax header for python<2.6
    """
    reset_env()
    run_from = abspath(join(here, 'packages'))
    run_pip('install', 'paxpkg.tar.bz2', cwd=run_from)
示例#12
0
def test_no_upgrade_editable_if_prefer_pinned():
    """
    No upgrade of editable if 1)--prefer-pinned-revision is True and 2) previously installed version is pinned.

    """
    reset_env()

    local_url = local_checkout('git+http://github.com/prezi/sb-test-package.git')

    args = ['install',
        # older version
        '-e', '%[email protected]#egg=sb-test-package' % local_url]

    result = run_pip(*args, **{"expect_error": True})
    result.assert_installed('sb-test-package')

    args = ['install',
        '--prefer-pinned-revision',
        # unpinned newer version
        '-e', '%s#egg=sb-test-package' % local_url]
    result = run_pip(*args, **{"expect_error": True})

    # worrysome_files_created are all files that aren't located in .git/, created by the comparison `git fetch`
    expected_files_regex = re.compile('[.]git')
    worrysome_files_created = [file_path for file_path in result.files_created.keys() if not expected_files_regex.search(file_path)]

    assert not worrysome_files_created, 'sb install sb-test-package upgraded when it should not have'
示例#13
0
def test_search():
    """
    End to end test of search command.

    """
    reset_env()
    output = run_pip('search', 'pip')
    assert 'A tool for installing and managing Python packages' in output.stdout
def test_install_global_option_using_editable():
    """
    Test using global distutils options, but in an editable installation
    """
    reset_env()
    url = "hg+http://bitbucket.org/runeh/anyjson"
    result = run_pip("install", "--global-option=--version", "-e", "%[email protected]#egg=anyjson" % local_checkout(url))
    assert "0.2.5\n" in result.stdout
示例#15
0
 def test_install_fails_with_no_ssl_backport(self):
     """
     Test installing w/o ssl backport fails
     """
     reset_env(insecure=False)
     #expect error because ssl's setup.py is hard coded to install test data to global prefix
     result = run_pip('install', 'INITools', expect_error=True)
     assert "You don't have an importable ssl module" in result.stdout
示例#16
0
文件: test_basic.py 项目: saxix/pip
def test_install_with_hacked_egg_info():
    """
    test installing a package which defines its own egg_info class
    """
    reset_env()
    run_from = abspath(join(here, 'packages', 'HackedEggInfo'))
    result = run_pip('install', '.', cwd=run_from)
    assert 'Successfully installed hackedegginfo\n' in result.stdout
示例#17
0
def test_missing_argument():
    """
    Test show command with no arguments.

    """
    reset_env()
    result = run_pip('show')
    assert 'ERROR: Please provide a package name or names.' in result.stdout
示例#18
0
文件: test_basic.py 项目: saxix/pip
def test_bad_install_with_no_download():
    """
    Test that --no-download behaves sensibly if the package source can't be found.
    """
    reset_env()
    result = run_pip('install', 'INITools==0.2', '--no-download', expect_error=True)
    assert "perhaps --no-download was used without first running "\
            "an equivalent install with --no-install?" in result.stdout
示例#19
0
def test_upgrade_vcs_req_with_no_dists_found():
    """It can upgrade a VCS requirement that has no distributions otherwise."""
    reset_env()
    req = "%s#egg=pip-test-package" % local_checkout(
        "git+http://github.com/pypa/pip-test-package.git")
    run_pip("install", req)
    result = run_pip("install", "-U", req)
    assert not result.returncode
示例#20
0
文件: test_basic.py 项目: saxix/pip
def test_install_global_option():
    """
    Test using global distutils options.
    (In particular those that disable the actual install action)
    """
    reset_env()
    result = run_pip('install', '--global-option=--version', "INITools==0.1")
    assert '0.1\n' in result.stdout
示例#21
0
def test_upgrade_vcs_req_with_dist_found():
    """It can upgrade a VCS requirement that has distributions on the index."""
    reset_env()
    # TODO(pnasrat) Using local_checkout fails on windows - oddness with the test path urls/git.
    req = "%s#egg=virtualenv" % "git+git://github.com/pypa/virtualenv@c21fef2c2d53cf19f49bcc37f9c058a33fb50499"
    run_pip("install", req)
    result = run_pip("install", "-U", req)
    assert not "pypi.python.org" in result.stdout, result.stdout
示例#22
0
def test_git_with_editable_where_egg_contains_dev_string():
    """
    Test cloning a git repository from an editable url which contains "dev" string
    """
    reset_env()
    result = run_pip('install', '-e', '%s#egg=django-devserver' %
                     local_checkout('git+git://github.com/dcramer/django-devserver.git'))
    result.assert_installed('django-devserver', with_files=['.git'])
def test_completion_alone():
    """
    Test getting completion for none shell, just pip completion
    """
    reset_env()
    result = run_pip('completion', expect_error=True)
    assert 'ERROR: You must pass --bash or --zsh' in result.stderr,\
            'completion alone failed -- ' + result.stderr
def test_completion_for_unknown_shell():
    """
    Test getting completion for an unknown shell
    """
    reset_env()
    error_msg = 'error: no such option: --myfooshell'
    result = run_pip('completion', '--myfooshell', expect_error=True)
    assert error_msg in result.stderr, 'tests for an unknown shell failed'
示例#25
0
文件: test_search.py 项目: saxix/pip
def test_search():
    """
    End to end test of search command.

    """
    reset_env()
    output = run_pip('search', 'pip')
    assert 'pip installs packages' in output.stdout
示例#26
0
def test_git_with_non_editable_unpacking():
    """
    Test cloning a git repository from a non-editable URL with a given tag.
    """
    reset_env()
    result = run_pip('install', '--global-option=--version', local_checkout(
                     'git+http://github.com/jezdez/[email protected]#egg=django-staticfiles'
                     ), expect_error=True)
    assert '0.3.1\n' in result.stdout
示例#27
0
文件: test_basic.py 项目: saxix/pip
def test_editable_install():
    """
    Test editable installation.
    """
    reset_env()
    result = run_pip('install', '-e', 'INITools==0.2', expect_error=True)
    assert "INITools==0.2 should either by a path to a local project or a VCS url" in result.stdout
    assert len(result.files_created) == 1, result.files_created
    assert not result.files_updated, result.files_updated
示例#28
0
文件: test_basic.py 项目: douglas/pip
def test_editable_install():
    """
    Test editable installation.
    """
    reset_env()
    result = run_pip('install', '-e', 'INITools==0.2', expect_error=True)
    assert "--editable=INITools==0.2 should be formatted with svn+URL" in result.stdout
    assert len(result.files_created) == 1, result.files_created
    assert not result.files_updated, result.files_updated
示例#29
0
文件: test_basic.py 项目: saxix/pip
def test_editable_install_from_local_directory_with_no_setup_py():
    """
    Test installing from a local directory with no 'setup.py'.
    """
    reset_env()
    result = run_pip('install', '-e', here, expect_error=True)
    assert len(result.files_created) == 1, result.files_created
    assert 'pip-log.txt' in result.files_created, result.files_created
    assert "is not installable. File 'setup.py' not found." in result.stdout
示例#30
0
文件: test_search.py 项目: saxix/pip
def test_multiple_search():
    """
    Test searching for multiple packages at once.

    """
    reset_env()
    output = run_pip('search', 'pip', 'INITools')
    assert 'pip installs packages' in output.stdout
    assert 'Tools for parsing and using INI-style files' in output.stdout
示例#31
0
def test_cleanup_after_install_from_local_directory():
    """
    Test clean up after installing from a local directory.

    """
    env = reset_env()
    to_install = abspath(join(here, 'packages', 'FSPkg'))
    run_pip('install', to_install, expect_error=False)
    build = env.venv_path / 'build'
    src = env.venv_path / 'src'
    assert not exists(build), "unexpected build/ dir exists: %s" % build
    assert not exists(src), "unexpected src/ dir exist: %s" % src
    env.assert_no_temp()
示例#32
0
def test_uninstall_console_scripts():
    """
    Test uninstalling a package with more files (console_script entry points, extra directories).

    """
    env = reset_env()
    args = ['install']
    args.append('discover')
    result = run_pip(*args, **{"expect_error": True})
    assert env.bin / 'discover' + env.exe in result.files_created, sorted(
        result.files_created.keys())
    result2 = run_pip('uninstall', 'discover', '-y', expect_error=True)
    assert_all_changes(result, result2, [env.venv / 'build', 'cache'])
示例#33
0
文件: test_upgrade.py 项目: slacy/pip
def test_upgrade_to_same_version_from_url():
    """
    When installing from a URL the same version that is already installed, no
    need to uninstall and reinstall if --upgrade is not specified.

    """
    env = reset_env()
    result = run_pip('install', 'INITools==0.3', expect_error=True)
    assert env.site_packages/ 'initools' in result.files_created, sorted(result.files_created.keys())
    result2 = run_pip('install', 'http://pypi.python.org/packages/source/I/INITools/INITools-0.3.tar.gz', expect_error=True)
    assert not result2.files_updated, 'INITools 0.3 reinstalled same version'
    result3 = run_pip('uninstall', 'initools', '-y', expect_error=True)
    assert_all_changes(result, result3, [env.venv/'build', 'cache'])
示例#34
0
def test_find_links_relative_path():
    """Test find-links as a relative path."""
    e = reset_env()
    result = run_pip('install',
                     'parent==0.1',
                     '--no-index',
                     '--find-links',
                     'packages/',
                     cwd=here)
    egg_info_folder = e.site_packages / 'parent-0.1-py%s.egg-info' % pyversion
    initools_folder = e.site_packages / 'parent'
    assert egg_info_folder in result.files_created, str(result)
    assert initools_folder in result.files_created, str(result)
示例#35
0
def test_install_using_install_option_and_editable():
    """
    Test installing a tool using -e and --install-option
    """
    env = reset_env()
    folder = 'script_folder'
    mkdir(folder)
    url = 'git+git://github.com/pypa/virtualenv'
    result = run_pip('install', '-e',
                     '%s#egg=virtualenv' % local_checkout(url),
                     '--install-option=--script-dir=%s' % folder)
    virtualenv_bin = env.venv / 'src' / 'virtualenv' / folder / 'virtualenv' + env.exe
    assert virtualenv_bin in result.files_created
示例#36
0
def test_simple_uninstall():
    """
    Test simple install and uninstall.

    """
    env = reset_env()
    result = run_pip('install', 'INITools==0.2')
    assert join(env.site_packages, 'initools') in result.files_created, sorted(
        result.files_created.keys())
    #the import forces the generation of __pycache__ if the version of python supports it
    env.run('python', '-c', "import initools")
    result2 = run_pip('uninstall', 'INITools', '-y')
    assert_all_changes(result, result2, [env.venv / 'build', 'cache'])
示例#37
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)
示例#38
0
def test_uninstall_easy_installed_console_scripts():
    """
    Test uninstalling package with console_scripts that is easy_installed.

    """
    env = reset_env()
    args = ['easy_install']
    args.append('discover')
    result = env.run(*args, **{"expect_stderr": True})
    assert env.bin / 'discover' + env.exe in result.files_created, sorted(
        result.files_created.keys())
    result2 = run_pip('uninstall', 'discover', '-y')
    assert_all_changes(result, result2, [env.venv / 'build', 'cache'])
示例#39
0
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
示例#40
0
def test_freeze_with_requirement_option():
    """
    Test that new requirements are created correctly with --requirement hints

    """
    reset_env()
    ignores = textwrap.dedent("""\
        # Unchanged requirements below this line
        -r ignore.txt
        --requirement ignore.txt
        -Z ignore
        --always-unzip ignore
        -f http://ignore
        -i http://ignore
        --extra-index-url http://ignore
        --find-links http://ignore
        --index-url http://ignore
        """)
    write_file(
        'hint.txt',
        textwrap.dedent("""\
        INITools==0.1
        NoExist==4.2
        """) + ignores)
    result = run_pip('install', 'initools==0.2')
    result = run_pip('install', 'MarkupSafe')
    result = run_pip('freeze', '--requirement', 'hint.txt', expect_stderr=True)
    expected = textwrap.dedent(
        """\
        Script result: pip freeze --requirement hint.txt
        -- stderr: --------------------
        Requirement file contains NoExist==4.2, but that package is not installed

        -- stdout: --------------------
        INITools==0.2
        """
    ) + ignores + "## The following requirements were added by pip --freeze:..."
    _check_output(result, expected)
示例#41
0
def test_git_with_ambiguous_revs():
    """
    Test git with two "names" (tag/branch) pointing to the same commit
    """
    env = reset_env()
    version_pkg_path = _create_test_package(env)
    package_url = 'git+file://%[email protected]#egg=version_pkg' % (
        version_pkg_path.abspath.replace('\\', '/'))
    env.run('git', 'tag', '0.1', cwd=version_pkg_path)
    result = run_pip('install', '-e', package_url)
    assert 'Could not find a tag or branch' not in result.stdout
    # it is 'version-pkg' instead of 'version_pkg' because
    # egg-link name is version-pkg.egg-link because it is a single .py module
    result.assert_installed('version-pkg', with_files=['.git'])
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"
示例#43
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'])
示例#44
0
def test_editable_git_upgrade():
    """
    Test installing an editable git package from a repository, upgrading the repository,
    installing again, and check it gets the newer version
    """
    env = reset_env()
    version_pkg_path = _create_test_package(env)
    run_pip('install', '-e', '%s#egg=version_pkg' % ('git+file://' + version_pkg_path))
    version = env.run('version_pkg')
    assert '0.1' in version.stdout
    _change_test_package_version(env, version_pkg_path)
    run_pip('install', '-e', '%s#egg=version_pkg' % ('git+file://' + version_pkg_path))
    version2 = env.run('version_pkg')
    assert 'some different version' in version2.stdout, "Output: %s" % (version2.stdout)
def test_no_extras_uninstall():
    """
    No extras dependency gets uninstalled when the root package is uninstalled
    """
    env = reset_env()
    result = run_pip('install', 'Paste[openid]==1.7.5.1', expect_stderr=True)
    assert join(env.site_packages, 'paste') in result.files_created, sorted(
        result.files_created.keys())
    assert join(env.site_packages, 'openid') in result.files_created, sorted(
        result.files_created.keys())
    result2 = run_pip('uninstall', 'Paste', '-y')
    # openid should not be uninstalled
    initools_folder = env.site_packages / 'openid'
    assert not initools_folder in result2.files_deleted, result.files_deleted
示例#46
0
def test_upgrade_force_reinstall_newest():
    """
    Force reinstallation of a package even if it is already at its newest
    version if --force-reinstall is supplied.
    """

    env = reset_env()
    result = run_pip('install', 'INITools')
    assert env.site_packages / 'initools' in result.files_created, sorted(
        result.files_created.keys())
    result2 = run_pip('install', '--upgrade', '--force-reinstall', 'INITools')
    assert result2.files_updated, 'upgrade to INITools 0.3 failed'
    result3 = run_pip('uninstall', 'initools', '-y', expect_error=True)
    assert_all_changes(result, result3, [env.venv / 'build', 'cache'])
示例#47
0
def test_git_branch_should_not_be_changed():
    """
    Editable installations should not change branch
    related to issue #32 and #161
    """
    env = reset_env()
    run_pip('install',
            '-e',
            '%s#egg=pip-test-package' %
            local_checkout('git+http://github.com/pypa/pip-test-package.git'),
            expect_error=True)
    source_dir = env.venv_path / 'src' / 'pip-test-package'
    result = env.run('git', 'branch', cwd=source_dir)
    assert '* master' in result.stdout, result.stdout
示例#48
0
def test_git_with_sha1_revisions():
    """
    Git backend should be able to install from SHA1 revisions
    """
    env = reset_env()
    version_pkg_path = _create_test_package(env)
    _change_test_package_version(env, version_pkg_path)
    sha1 = env.run('git', 'rev-parse', 'HEAD~1',
                   cwd=version_pkg_path).stdout.strip()
    run_pip(
        'install', '-e', '%s@%s#egg=version_pkg' %
        ('git+file://' + version_pkg_path.abspath.replace('\\', '/'), sha1))
    version = env.run('version_pkg')
    assert '0.1' in version.stdout, version.stdout
示例#49
0
    def test_install_user_conflict_in_usersite(self):
        """
        Test user install with conflict in usersite updates usersite.
        """

        env = reset_env(system_site_packages=True)
        result1 = run_pip('install', '--user', 'INITools==0.3')
        result2 = run_pip('install', '--user', 'INITools==0.1')

        #usersite has 0.1
        egg_info_folder = env.user_site / 'INITools-0.1-py%s.egg-info' % pyversion
        initools_v3_file = env.root_path / env.user_site / 'initools' / 'configparser.py' #file only in 0.3
        assert egg_info_folder in result2.files_created, str(result2)
        assert not isfile(initools_v3_file), initools_v3_file
示例#50
0
def test_uninstall_editable_from_svn():
    """
    Test uninstalling an editable installation from svn.

    """
    env = reset_env()
    result = run_pip(
        'install', '-e', '%s#egg=initools-dev' %
        local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'))
    result.assert_installed('INITools')
    result2 = run_pip('uninstall', '-y', 'initools')
    assert (env.venv / 'src' / 'initools'
            in result2.files_after), 'oh noes, pip deleted my sources!'
    assert_all_changes(result, result2, [env.venv / 'src', env.venv / 'build'])
示例#51
0
def _test_config_file_override_stack(config_file):
    environ = clear_environ(os.environ.copy())
    environ['PIP_CONFIG_FILE'] = config_file # set this to make pip load it
    reset_env(environ)
    write_file(config_file, textwrap.dedent("""\
        [global]
        index-url = http://download.zope.org/ppix
        """))
    result = run_pip('install', '-vvv', 'INITools', expect_error=True)
    assert "Getting page http://download.zope.org/ppix/INITools" in result.stdout
    reset_env(environ)
    write_file(config_file, textwrap.dedent("""\
        [global]
        index-url = http://download.zope.org/ppix
        [install]
        index-url = http://pypi.appspot.com/
        """))
    result = run_pip('install', '-vvv', 'INITools', expect_error=True)
    assert "Getting page http://pypi.appspot.com/INITools" in result.stdout
    result = run_pip('install', '-vvv', '--index-url', 'http://pypi.python.org/simple', 'INITools', expect_error=True)
    assert "Getting page http://download.zope.org/ppix/INITools" not in result.stdout
    assert "Getting page http://pypi.appspot.com/INITools" not in result.stdout
    assert "Getting page http://pypi.python.org/simple/INITools" in result.stdout
示例#52
0
def test_upgrade_editable_if_no_prefer_pinned():
    """
    Upgrade editable if 1)--prefer-pinned-revision is False (default) and 2) previously installed version is pinned and not the latest version.

    """
    reset_env()

    local_url = local_checkout(
        'git+http://github.com/prezi/sb-test-package.git')

    args = [
        'install',
        # older version
        '-e',
        '%[email protected]#egg=sb-test-package' % local_url
    ]

    result = run_pip(*args, **{"expect_error": True})
    result.assert_installed('sb-test-package')

    args = [
        'install',
        # unpinned newer version
        '-e',
        '%s#egg=sb-test-package' % local_url
    ]
    result = run_pip(*args, **{"expect_error": True})

    # worrysome_files_created are all files that aren't located in .git/, created by the comparison `git fetch`
    expected_files_regex = re.compile('[.]git')
    new_files_created = [
        file_path for file_path in result.files_created.keys()
        if not expected_files_regex.search(file_path)
    ]

    # new_files_created should contain a file that appears in versions >=0.2.1, but not in 0.2.2
    assert new_files_created, 'sb install sb-test-package did not upgrade when it should have'
示例#53
0
def test_no_upgrade_editable_if_prefer_pinned():
    """
    No upgrade of editable if 1)--prefer-pinned-revision is True and 2) previously installed version is pinned.

    """
    reset_env()

    local_url = local_checkout(
        'git+http://github.com/prezi/sb-test-package.git')

    args = [
        'install',
        # older version
        '-e',
        '%[email protected]#egg=sb-test-package' % local_url
    ]

    result = run_pip(*args, **{"expect_error": True})
    result.assert_installed('sb-test-package')

    args = [
        'install',
        '--prefer-pinned-revision',
        # unpinned newer version
        '-e',
        '%s#egg=sb-test-package' % local_url
    ]
    result = run_pip(*args, **{"expect_error": True})

    # worrysome_files_created are all files that aren't located in .git/, created by the comparison `git fetch`
    expected_files_regex = re.compile('[.]git')
    worrysome_files_created = [
        file_path for file_path in result.files_created.keys()
        if not expected_files_regex.search(file_path)
    ]

    assert not worrysome_files_created, 'sb install sb-test-package upgraded when it should not have'
def test_correct_pip_version():
    """
    Check we are running proper version of pip in run_pip.
    """
    reset_env()

    # output is like:
    # pip PIPVERSION from PIPDIRECTORY (python PYVERSION)
    result = run_pip('--version')

    # compare the directory tree of the invoked pip with that of this source distribution
    dir = re.match(r'pip \d(\.[\d])+(\.(pre|post)\d+)? from (.*) \(python \d(.[\d])+\)$',
                   result.stdout).group(4)
    pip_folder = join(src_folder, 'pip')
    pip_folder_outputed = join(dir, 'pip')

    diffs = filecmp.dircmp(pip_folder, pip_folder_outputed)

    # If any non-matching .py files exist, we have a problem: run_pip
    # is picking up some other version!  N.B. if this project acquires
    # primary resources other than .py files, this code will need
    # maintenance
    mismatch_py = [x for x in diffs.left_only + diffs.right_only + diffs.diff_files if x.endswith('.py')]
    assert not mismatch_py, 'mismatched source files in %r and %r'% (pip_folder, pip_folder_outputed)
示例#55
0
def test_pip_second_command_line_interface_works():
    """
    Check if ``pip-<PYVERSION>`` commands behaves equally
    """
    e = reset_env()

    args = ['pip-%s' % pyversion]
    if not ssl:
        args.append('--insecure')
    args.extend(['install', 'INITools==0.2'])
    result = e.run(*args)
    egg_info_folder = e.site_packages / 'INITools-0.2-py%s.egg-info' % pyversion
    initools_folder = e.site_packages / 'initools'
    assert egg_info_folder in result.files_created, str(result)
    assert initools_folder in result.files_created, str(result)
示例#56
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)
示例#57
0
def test_get_branch_revs_should_ignore_no_branch():
    env = reset_env()
    version_pkg_path = _create_test_package(env)
    env.run('git', 'branch', 'branch0.1', cwd=version_pkg_path)
    commit = env.run('git', 'rev-parse', 'HEAD',
                     cwd=version_pkg_path).stdout.strip()
    # current branch here is "* (nobranch)"
    env.run('git',
            'checkout',
            commit,
            cwd=version_pkg_path,
            expect_stderr=True)
    git = Git()
    result = git.get_branch_revs(version_pkg_path)
    assert result == {'master': commit, 'branch0.1': commit}
示例#58
0
文件: test_basic.py 项目: qiemem/pip
def test_find_command_folder_in_path():
    """
    If a folder named e.g. 'git' is in PATH, and find_command is looking for
    the 'git' executable, it should not match the folder, but rather keep
    looking.
    """
    env = reset_env()
    mkdir('path_one')
    path_one = env.scratch_path / 'path_one'
    mkdir(path_one / 'foo')
    mkdir('path_two')
    path_two = env.scratch_path / 'path_two'
    write_file(path_two / 'foo', '# nothing')
    found_path = find_command('foo', map(str, [path_one, path_two]))
    assert found_path == path_two / 'foo'
示例#59
0
文件: test_basic.py 项目: qiemem/pip
def test_install_curdir():
    """
    Test installing current directory ('.').
    """
    env = reset_env()
    run_from = abspath(join(here, 'packages', 'FSPkg'))
    # Python 2.4 Windows balks if this exists already
    egg_info = join(run_from, "FSPkg.egg-info")
    if os.path.isdir(egg_info):
        rmtree(egg_info)
    result = run_pip('install', curdir, cwd=run_from, expect_error=False)
    fspkg_folder = env.site_packages / 'fspkg'
    egg_info_folder = env.site_packages / 'FSPkg-0.1dev-py%s.egg-info' % pyversion
    assert fspkg_folder in result.files_created, str(result.stdout)
    assert egg_info_folder in result.files_created, str(result)
def test_cleanup_after_install_editable_from_hg():
    """
    Test clean up after cloning from Mercurial.

    """
    env = reset_env()
    run_pip('install',
            '-e',
            '%s#egg=django-registration' % local_checkout(
                'hg+http://bitbucket.org/ubernostrum/django-registration'),
            expect_error=True)
    build = env.venv_path / 'build'
    src = env.venv_path / 'src'
    assert not exists(build), "build/ dir still exists: %s" % build
    assert exists(src), "expected src/ dir doesn't exist: %s" % src