Example #1
0
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])+(\.?(rc|dev|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: %r' % (
        pip_folder, pip_folder_outputed, mismatch_py)
Example #2
0
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
Example #3
0
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
Example #4
0
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
Example #5
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
Example #6
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)
Example #7
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 = pip_install_local('simple')
    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)
Example #8
0
def test_freeze_mercurial_clone():
    """
    Test freezing a Mercurial clone.

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

    result = run_pip('freeze', '-f',
                     '%s#egg=pip_test_package' % local_checkout('hg+http://bitbucket.org/pypa/pip-test-package'),
                     expect_stderr=True)
    expected = textwrap.dedent("""\
        Script result: ...pip freeze -f %(repo)s#egg=pip_test_package
        -- stdout: --------------------
        -f %(repo)s#egg=pip_test_package
        ...-e %(repo)s@...#egg=pip_test_package-dev
        ...""" % {'repo': local_checkout('hg+http://bitbucket.org/pypa/pip-test-package')})
    _check_output(result, expected)
Example #9
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)
Example #10
0
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
Example #11
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)
Example #12
0
def test_install_with_pax_header():
    """
    test installing from a tarball with pax header for python<2.6
    """
    reset_env()
    run_from = abspath(join(tests_data, 'packages'))
    run_pip('install', 'paxpkg.tar.bz2', cwd=run_from)
Example #13
0
def test_editable_no_install_followed_by_no_download():
    """
    Test installing an editable in two steps (first with --no-install, then with --no-download).
    """
    reset_env()

    result = run_pip(
        'install',
        '-e',
        '%s#egg=initools-dev' %
        local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'),
        '--no-install',
        expect_error=True)
    result.assert_installed('INITools',
                            without_egg_link=True,
                            with_files=['.svn'])

    result = run_pip(
        'install',
        '-e',
        '%s#egg=initools-dev' %
        local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'),
        '--no-download',
        expect_error=True)
    result.assert_installed('INITools', without_files=[curdir, '.svn'])
Example #14
0
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
Example #15
0
def test_install_with_pax_header():
    """
    test installing from a tarball with pax header for python<2.6
    """
    reset_env()
    run_from = abspath(join(tests_data, 'packages'))
    run_pip('install', 'paxpkg.tar.bz2', cwd=run_from)
Example #16
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
Example #17
0
 def test_reset_env_system_site_packages(self):
     """
     Test using system_site_packages with reset_env resets the venv cache
     """
     env = reset_env(system_site_packages=True)
     env = reset_env()
     assert not os.path.isfile(self.env.backup_path / self.env.venv / 'test_file')
Example #18
0
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
Example #19
0
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
Example #20
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
Example #21
0
def test_completion_for_unknown_shell():
    """
    Test getting completion for an unknown shell
    """
    reset_env()
    error_msg = 'no such option: --myfooshell'
    result = run_pip('completion', '--myfooshell', expect_error=True)
    assert error_msg in result.stderr, 'tests for an unknown shell failed'
Example #22
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
Example #23
0
 def test_reset_env_system_site_packages(self):
     """
     Test using system_site_packages with reset_env resets the venv cache
     """
     env = reset_env(system_site_packages=True)
     env = reset_env()
     assert not os.path.isfile(
         self.env.backup_path / self.env.venv / 'test_file')
Example #24
0
def test_install_with_hacked_egg_info():
    """
    test installing a package which defines its own egg_info class
    """
    reset_env()
    run_from = abspath(join(tests_data, 'packages', 'HackedEggInfo'))
    result = run_pip('install', '.', cwd=run_from)
    assert 'Successfully installed hackedegginfo\n' in result.stdout
Example #25
0
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
Example #26
0
def test_install_with_hacked_egg_info():
    """
    test installing a package which defines its own egg_info class
    """
    reset_env()
    run_from = abspath(join(tests_data, 'packages', 'HackedEggInfo'))
    result = run_pip('install', '.', cwd=run_from)
    assert 'Successfully installed hackedegginfo\n' in result.stdout
Example #27
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
Example #28
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
Example #29
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
Example #30
0
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
Example #31
0
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
Example #32
0
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
Example #33
0
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
Example #34
0
def test_no_upgrade_unless_requested():
    """
    No upgrade if not specifically requested.

    """
    reset_env()
    run_pip('install', 'INITools==0.1', expect_error=True)
    result = run_pip('install', 'INITools', expect_error=True)
    assert not result.files_created, 'pip install INITools upgraded when it should not have'
Example #35
0
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
Example #36
0
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', tests_data, 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
Example #37
0
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', tests_data, 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
Example #38
0
def test_no_upgrade_unless_requested():
    """
    No upgrade if not specifically requested.

    """
    reset_env()
    run_pip('install', 'INITools==0.1', expect_error=True)
    result = run_pip('install', 'INITools', expect_error=True)
    assert not result.files_created, 'pip install INITools upgraded when it should not have'
Example #39
0
def test_setup_py_with_dos_line_endings():
    """
    It doesn't choke on a setup.py file that uses DOS line endings (\\r\\n).

    Refs https://github.com/pypa/pip/issues/237
    """
    reset_env()
    to_install = os.path.abspath(os.path.join(tests_data, 'packages', 'LineEndings'))
    run_pip('install', to_install, expect_error=False)
Example #40
0
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
Example #41
0
def test_install_editable_from_svn():
    """
    Test checking out from svn.
    """
    reset_env()
    result = run_pip(
        'install', '-e', '%s#egg=initools-dev' %
        local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'))
    result.assert_installed('INITools', with_files=['.svn'])
Example #42
0
def test_show_with_all_files():
    """
    Test listing all files in the show command.

    """
    reset_env()
    result = run_pip('install', 'initools==0.2')
    result = run_pip('show', '--files', 'initools')
    assert re.search(r"Files:\n(  .+\n)+", result.stdout)
Example #43
0
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
Example #44
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"])
Example #45
0
def test_multiple_search():
    """
    Test searching for multiple packages at once.

    """
    reset_env()
    output = run_pip('search', 'pip', 'INITools')
    assert 'A tool for installing and managing Python packages' in output.stdout
    assert 'Tools for parsing and using INI-style files' in output.stdout
Example #46
0
def test_install_editable_from_svn():
    """
    Test checking out from svn.
    """
    reset_env()
    result = run_pip('install',
                     '-e',
                     '%s#egg=initools-dev' %
                     local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'))
    result.assert_installed('INITools', with_files=['.svn'])
Example #47
0
def test_editables_flag():
    """
    Test the behavior of --editables flag in the list command
    """
    reset_env()
    run_pip('install', '-f', find_links, '--no-index', 'simple==1.0')
    result = run_pip('install', '-e', 'git+https://github.com/pypa/pip-test-package.git#egg=pip-test-package')
    result = run_pip('list', '--editable')
    assert 'simple (1.0)' not in result.stdout, str(result)
    assert os.path.join('src', 'pip-test-package') in result.stdout, str(result)
Example #48
0
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)
Example #49
0
def test_setup_py_with_dos_line_endings():
    """
    It doesn't choke on a setup.py file that uses DOS line endings (\\r\\n).

    Refs https://github.com/pypa/pip/issues/237
    """
    reset_env()
    to_install = os.path.abspath(
        os.path.join(tests_data, 'packages', 'LineEndings'))
    run_pip('install', to_install, expect_error=False)
Example #50
0
def test_install_editable_from_bazaar():
    """
    Test checking out from Bazaar.
    """
    reset_env()
    result = run_pip('install', '-e',
                     '%s/@174#egg=django-wikiapp' %
                     local_checkout('bzr+http://bazaar.launchpad.net/%7Edjango-wikiapp/django-wikiapp/release-0.1'),
                     expect_error=True)
    result.assert_installed('django-wikiapp', with_files=['.bzr'])
Example #51
0
def test_vcs_url_urlquote_normalization():
    """
    Test that urlquoted characters are normalized for repo URL comparison.
    """
    reset_env()
    result = run_pip('install', '-e',
                     '%s/#egg=django-wikiapp' %
                     local_checkout('bzr+http://bazaar.launchpad.net/%7Edjango-wikiapp/django-wikiapp/release-0.1'),
                     expect_error=True)
    assert 'pip-log.txt' not in result.files_created, result.files_created['pip-log.txt'].bytes
Example #52
0
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
Example #53
0
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
Example #54
0
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)
Example #55
0
def test_options_from_env_vars():
    """
    Test if ConfigOptionParser reads env vars (e.g. not using PyPI here)

    """
    environ = clear_environ(os.environ.copy())
    environ['PIP_NO_INDEX'] = '1'
    reset_env(environ)
    result = run_pip('install', '-vvv', 'INITools', expect_error=True)
    assert "Ignoring indexes:" in result.stdout, str(result)
    assert "DistributionNotFound: No distributions at all found for INITools" in result.stdout
Example #56
0
def test_install_editable_from_hg():
    """
    Test cloning from Mercurial.
    """
    reset_env()
    result = run_pip(
        'install',
        '-e',
        '%s#egg=ScriptTest' %
        local_checkout('hg+https://bitbucket.org/ianb/scripttest'),
        expect_error=True)
    result.assert_installed('ScriptTest', with_files=['.hg'])