test_install_vcs_git.py 3.7 KB
Newer Older
1 2
import pytest

3
from mock import patch
4

5
from pip.vcs.git import Git
6
from tests.lib import _create_test_package
7
from tests.lib.git_submodule_helpers import (
8 9 10
    _change_test_package_submodule,
    _pull_in_submodule_changes_to_module,
    _create_test_package_with_submodule,
D
Donald Stufft 已提交
11
)
12 13


14
@pytest.mark.network
15
def test_get_refs_should_return_tag_name_and_commit_pair(script):
D
Donald Stufft 已提交
16 17 18
    version_pkg_path = _create_test_package(script)
    script.run('git', 'tag', '0.1', cwd=version_pkg_path)
    script.run('git', 'tag', '0.2', cwd=version_pkg_path)
19 20 21 22
    commit = script.run(
        'git', 'rev-parse', 'HEAD',
        cwd=version_pkg_path
    ).stdout.strip()
23
    git = Git()
24 25 26
    result = git.get_refs(version_pkg_path)
    assert result['0.1'] == commit, result
    assert result['0.2'] == commit, result
27 28


29
@pytest.mark.network
30
def test_get_refs_should_return_branch_name_and_commit_pair(script):
D
Donald Stufft 已提交
31 32
    version_pkg_path = _create_test_package(script)
    script.run('git', 'branch', 'branch0.1', cwd=version_pkg_path)
33 34 35 36
    commit = script.run(
        'git', 'rev-parse', 'HEAD',
        cwd=version_pkg_path
    ).stdout.strip()
37
    git = Git()
38 39 40
    result = git.get_refs(version_pkg_path)
    assert result['master'] == commit, result
    assert result['branch0.1'] == commit, result
41 42


43
@pytest.mark.network
44
def test_get_refs_should_ignore_no_branch(script):
D
Donald Stufft 已提交
45 46
    version_pkg_path = _create_test_package(script)
    script.run('git', 'branch', 'branch0.1', cwd=version_pkg_path)
47 48 49 50
    commit = script.run(
        'git', 'rev-parse', 'HEAD',
        cwd=version_pkg_path
    ).stdout.strip()
51
    # current branch here is "* (nobranch)"
52 53 54 55 56
    script.run(
        'git', 'checkout', commit,
        cwd=version_pkg_path,
        expect_stderr=True,
    )
57
    git = Git()
58 59 60
    result = git.get_refs(version_pkg_path)
    assert result['master'] == commit, result
    assert result['branch0.1'] == commit, result
61 62


63 64 65
@patch('pip.vcs.git.Git.get_refs')
def test_check_rev_options_should_handle_branch_name(get_refs_mock):
    get_refs_mock.return_value = {'master': '123456', '0.1': '123456'}
66 67 68 69 70 71
    git = Git()

    result = git.check_rev_options('master', '.', [])
    assert result == ['123456']


72 73 74
@patch('pip.vcs.git.Git.get_refs')
def test_check_rev_options_should_handle_tag_name(get_refs_mock):
    get_refs_mock.return_value = {'master': '123456', '0.1': '123456'}
75 76 77 78 79 80
    git = Git()

    result = git.check_rev_options('0.1', '.', [])
    assert result == ['123456']


81 82 83
@patch('pip.vcs.git.Git.get_refs')
def test_check_rev_options_should_handle_ambiguous_commit(get_refs_mock):
    get_refs_mock.return_value = {'master': '123456', '0.1': '123456'}
84 85 86 87
    git = Git()

    result = git.check_rev_options('0.1', '.', [])
    assert result == ['123456'], result
F
fin 已提交
88 89


90 91
# TODO(pnasrat) fix all helpers to do right things with paths on windows.
@pytest.mark.skipif("sys.platform == 'win32'")
92
@pytest.mark.network
93
def test_check_submodule_addition(script):
F
fin 已提交
94
    """
95
    Submodules are pulled in on install and updated on upgrade.
F
fin 已提交
96
    """
D
Donald Stufft 已提交
97
    module_path, submodule_path = _create_test_package_with_submodule(script)
F
fin 已提交
98

99
    install_result = script.pip(
D
Donald Stufft 已提交
100
        'install', '-e', 'git+' + module_path + '#egg=version_pkg'
101 102
    )
    assert (
D
Donald Stufft 已提交
103
        script.venv / 'src/version-pkg/testpkg/static/testfile'
104 105
        in install_result.files_created
    )
F
fin 已提交
106

D
Donald Stufft 已提交
107 108
    _change_test_package_submodule(script, submodule_path)
    _pull_in_submodule_changes_to_module(script, module_path)
F
fin 已提交
109

110
    # expect error because git may write to stderr
111
    update_result = script.pip(
D
Donald Stufft 已提交
112 113
        'install', '-e', 'git+' + module_path + '#egg=version_pkg',
        '--upgrade',
114 115
        expect_error=True,
    )
F
fin 已提交
116

117
    assert (
D
Donald Stufft 已提交
118
        script.venv / 'src/version-pkg/testpkg/static/testfile2'
119 120
        in update_result.files_created
    )