2015-08-31 22:52:01 +02:00
|
|
|
import pytest
|
2017-05-16 12:16:30 +02:00
|
|
|
from mock import Mock
|
2017-06-13 14:17:00 +02:00
|
|
|
from pip._vendor.packaging.version import parse as parse_version
|
|
|
|
|
2017-10-02 00:21:11 +02:00
|
|
|
from pip._internal.vcs import RevOptions, VersionControl
|
2017-08-31 17:48:18 +02:00
|
|
|
from pip._internal.vcs.bazaar import Bazaar
|
2017-10-05 00:16:10 +02:00
|
|
|
from pip._internal.vcs.git import Git, looks_like_hash
|
2017-10-02 00:21:11 +02:00
|
|
|
from pip._internal.vcs.mercurial import Mercurial
|
2017-08-31 17:48:18 +02:00
|
|
|
from pip._internal.vcs.subversion import Subversion
|
2017-05-16 12:16:30 +02:00
|
|
|
from tests.lib import pyversion
|
2011-04-20 12:42:37 +02:00
|
|
|
|
|
|
|
if pyversion >= '3':
|
|
|
|
VERBOSE_FALSE = False
|
|
|
|
else:
|
|
|
|
VERBOSE_FALSE = 0
|
|
|
|
|
|
|
|
|
2017-10-02 00:21:11 +02:00
|
|
|
def test_rev_options_repr():
|
|
|
|
rev_options = RevOptions(Git(), 'develop')
|
|
|
|
assert repr(rev_options) == "<RevOptions git: rev='develop'>"
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(('vcs', 'expected1', 'expected2', 'kwargs'), [
|
|
|
|
# First check VCS-specific RevOptions behavior.
|
|
|
|
(Bazaar(), [], ['-r', '123'], {}),
|
2017-10-02 01:35:50 +02:00
|
|
|
(Git(), ['HEAD'], ['123'], {}),
|
2017-10-02 00:21:11 +02:00
|
|
|
(Mercurial(), [], ['123'], {}),
|
|
|
|
(Subversion(), [], ['-r', '123'], {}),
|
|
|
|
# Test extra_args. For this, test using a single VersionControl class.
|
2017-10-02 01:35:50 +02:00
|
|
|
(Git(), ['HEAD', 'opt1', 'opt2'], ['123', 'opt1', 'opt2'],
|
2017-10-02 00:21:11 +02:00
|
|
|
dict(extra_args=['opt1', 'opt2'])),
|
|
|
|
])
|
|
|
|
def test_rev_options_to_args(vcs, expected1, expected2, kwargs):
|
|
|
|
"""
|
|
|
|
Test RevOptions.to_args().
|
|
|
|
"""
|
|
|
|
assert RevOptions(vcs, **kwargs).to_args() == expected1
|
|
|
|
assert RevOptions(vcs, '123', **kwargs).to_args() == expected2
|
|
|
|
|
|
|
|
|
|
|
|
def test_rev_options_to_display():
|
|
|
|
"""
|
|
|
|
Test RevOptions.to_display().
|
|
|
|
"""
|
|
|
|
# The choice of VersionControl class doesn't matter here since
|
|
|
|
# the implementation is the same for all of them.
|
|
|
|
vcs = Git()
|
|
|
|
|
|
|
|
rev_options = RevOptions(vcs)
|
|
|
|
assert rev_options.to_display() == ''
|
|
|
|
|
|
|
|
rev_options = RevOptions(vcs, 'master')
|
|
|
|
assert rev_options.to_display() == ' (to revision master)'
|
|
|
|
|
|
|
|
|
|
|
|
def test_rev_options_make_new():
|
|
|
|
"""
|
|
|
|
Test RevOptions.make_new().
|
|
|
|
"""
|
|
|
|
# The choice of VersionControl class doesn't matter here since
|
|
|
|
# the implementation is the same for all of them.
|
|
|
|
vcs = Git()
|
|
|
|
|
|
|
|
rev_options = RevOptions(vcs, 'master', extra_args=['foo', 'bar'])
|
|
|
|
new_options = rev_options.make_new('develop')
|
|
|
|
|
|
|
|
assert new_options is not rev_options
|
|
|
|
assert new_options.extra_args == ['foo', 'bar']
|
|
|
|
assert new_options.rev == 'develop'
|
|
|
|
assert new_options.vcs is vcs
|
|
|
|
|
|
|
|
|
2015-08-31 22:52:01 +02:00
|
|
|
@pytest.fixture
|
|
|
|
def git():
|
2017-11-20 20:23:22 +01:00
|
|
|
git_url = 'https://github.com/pypa/pip-test-package'
|
2017-08-22 00:56:53 +02:00
|
|
|
sha = '5547fa909e83df8bd743d3978d6667497983a4b7'
|
2014-09-27 23:12:19 +02:00
|
|
|
git = Git()
|
|
|
|
git.get_url = Mock(return_value=git_url)
|
|
|
|
git.get_revision = Mock(return_value=sha)
|
2015-08-31 22:52:01 +02:00
|
|
|
return git
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def dist():
|
2014-09-27 23:12:19 +02:00
|
|
|
dist = Mock()
|
|
|
|
dist.egg_name = Mock(return_value='pip_test_package')
|
2015-08-31 22:52:01 +02:00
|
|
|
return dist
|
|
|
|
|
|
|
|
|
2017-10-05 00:16:10 +02:00
|
|
|
def test_looks_like_hash():
|
|
|
|
assert looks_like_hash(40 * 'a')
|
|
|
|
assert looks_like_hash(40 * 'A')
|
|
|
|
# Test a string containing all valid characters.
|
|
|
|
assert looks_like_hash(18 * 'a' + '0123456789abcdefABCDEF')
|
|
|
|
assert not looks_like_hash(40 * 'g')
|
|
|
|
assert not looks_like_hash(39 * 'a')
|
|
|
|
|
|
|
|
|
2018-05-30 19:33:13 +02:00
|
|
|
@pytest.mark.network
|
2015-08-31 22:52:01 +02:00
|
|
|
def test_git_get_src_requirements(git, dist):
|
2016-01-07 23:24:13 +01:00
|
|
|
ret = git.get_src_requirement(dist, location='.')
|
2014-09-27 23:12:19 +02:00
|
|
|
|
|
|
|
assert ret == ''.join([
|
2017-11-20 20:23:22 +01:00
|
|
|
'git+https://github.com/pypa/pip-test-package',
|
2014-09-27 23:12:19 +02:00
|
|
|
'@5547fa909e83df8bd743d3978d6667497983a4b7',
|
2015-12-18 22:48:12 +01:00
|
|
|
'#egg=pip_test_package'
|
2014-09-27 23:12:19 +02:00
|
|
|
])
|
|
|
|
|
|
|
|
|
2017-08-13 22:38:39 +02:00
|
|
|
@pytest.mark.parametrize('rev_name,result', (
|
2015-08-31 22:52:01 +02:00
|
|
|
('5547fa909e83df8bd743d3978d6667497983a4b7', True),
|
2017-08-13 22:21:05 +02:00
|
|
|
('5547fa909', False),
|
2017-08-13 22:14:26 +02:00
|
|
|
('5678', False),
|
2015-08-31 22:52:01 +02:00
|
|
|
('abc123', False),
|
|
|
|
('foo', False),
|
2017-08-13 22:38:39 +02:00
|
|
|
(None, False),
|
2015-08-31 22:52:01 +02:00
|
|
|
))
|
2017-10-03 10:21:55 +02:00
|
|
|
def test_git_is_commit_id_equal(git, rev_name, result):
|
2017-08-13 22:38:39 +02:00
|
|
|
"""
|
2017-10-03 10:21:55 +02:00
|
|
|
Test Git.is_commit_id_equal().
|
2017-08-13 22:38:39 +02:00
|
|
|
"""
|
2017-10-03 10:21:55 +02:00
|
|
|
assert git.is_commit_id_equal('/path', rev_name) is result
|
2015-08-31 22:52:01 +02:00
|
|
|
|
|
|
|
|
2014-09-25 08:27:22 +02:00
|
|
|
def test_translate_egg_surname():
|
2014-09-25 07:21:36 +02:00
|
|
|
vc = VersionControl()
|
2014-09-25 08:27:22 +02:00
|
|
|
assert vc.translate_egg_surname("foo") == "foo"
|
|
|
|
assert vc.translate_egg_surname("foo/bar") == "foo_bar"
|
|
|
|
assert vc.translate_egg_surname("foo/1.2.3") == "foo_1.2.3"
|
2014-09-25 07:21:36 +02:00
|
|
|
|
|
|
|
|
2018-07-15 19:39:06 +02:00
|
|
|
# The non-SVN backends all use the same parse_netloc(), so only test
|
|
|
|
# Git as a representative.
|
|
|
|
@pytest.mark.parametrize('netloc, expected', [
|
|
|
|
# Test a basic case.
|
|
|
|
('example.com', ('example.com', None, None)),
|
|
|
|
# Test with username and password.
|
|
|
|
('user:pass@example.com', ('user:pass@example.com', None, None)),
|
|
|
|
])
|
|
|
|
def test_git__parse_netloc(netloc, expected):
|
|
|
|
"""
|
|
|
|
Test VersionControl.parse_netloc().
|
|
|
|
"""
|
|
|
|
actual = Git().parse_netloc(netloc)
|
|
|
|
assert actual == expected
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('netloc, expected', [
|
|
|
|
# Test a basic case.
|
|
|
|
('example.com', ('example.com', None, None)),
|
|
|
|
# Test with username and no password.
|
|
|
|
('user@example.com', ('example.com', 'user', None)),
|
|
|
|
# Test with username and password.
|
|
|
|
('user:pass@example.com', ('example.com', 'user', 'pass')),
|
|
|
|
# Test the password containing an @ symbol.
|
|
|
|
('user:pass@word@example.com', ('example.com', 'user', 'pass@word')),
|
|
|
|
# Test the password containing a : symbol.
|
|
|
|
('user:pass:word@example.com', ('example.com', 'user', 'pass:word')),
|
|
|
|
])
|
|
|
|
def test_subversion__parse_netloc(netloc, expected):
|
|
|
|
"""
|
|
|
|
Test Subversion.parse_netloc().
|
|
|
|
"""
|
|
|
|
actual = Subversion().parse_netloc(netloc)
|
|
|
|
assert actual == expected
|
|
|
|
|
|
|
|
|
2018-07-10 09:31:57 +02:00
|
|
|
def test_git__get_url_rev__idempotent():
|
|
|
|
"""
|
|
|
|
Check that Git.get_url_rev() is idempotent for what the code calls
|
|
|
|
"stub URLs" (i.e. URLs that don't contain "://").
|
2018-07-11 09:51:38 +02:00
|
|
|
|
|
|
|
Also check that it doesn't change self.url.
|
2018-07-10 09:31:57 +02:00
|
|
|
"""
|
2018-07-11 09:51:38 +02:00
|
|
|
url = 'git+git@git.example.com:MyProject#egg=MyProject'
|
|
|
|
vcs = Git(url)
|
|
|
|
result1 = vcs.get_url_rev(url)
|
|
|
|
assert vcs.url == url
|
|
|
|
result2 = vcs.get_url_rev(url)
|
2018-07-15 19:39:06 +02:00
|
|
|
expected = ('git@git.example.com:MyProject', None, (None, None))
|
|
|
|
assert result1 == expected
|
|
|
|
assert result2 == expected
|
2018-07-10 09:31:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_bazaar__get_url_rev():
|
2011-04-20 12:42:37 +02:00
|
|
|
"""
|
|
|
|
Test bzr url support.
|
|
|
|
|
|
|
|
SSH and launchpad have special handling.
|
|
|
|
"""
|
2014-01-28 15:17:51 +01:00
|
|
|
http_bzr_repo = Bazaar(
|
|
|
|
url='bzr+http://bzr.myproject.org/MyProject/trunk/#egg=MyProject'
|
|
|
|
)
|
|
|
|
https_bzr_repo = Bazaar(
|
|
|
|
url='bzr+https://bzr.myproject.org/MyProject/trunk/#egg=MyProject'
|
|
|
|
)
|
|
|
|
ssh_bzr_repo = Bazaar(
|
|
|
|
url='bzr+ssh://bzr.myproject.org/MyProject/trunk/#egg=MyProject'
|
|
|
|
)
|
|
|
|
ftp_bzr_repo = Bazaar(
|
|
|
|
url='bzr+ftp://bzr.myproject.org/MyProject/trunk/#egg=MyProject'
|
|
|
|
)
|
|
|
|
sftp_bzr_repo = Bazaar(
|
|
|
|
url='bzr+sftp://bzr.myproject.org/MyProject/trunk/#egg=MyProject'
|
|
|
|
)
|
|
|
|
launchpad_bzr_repo = Bazaar(
|
|
|
|
url='bzr+lp:MyLaunchpadProject#egg=MyLaunchpadProject'
|
|
|
|
)
|
2011-04-20 12:42:37 +02:00
|
|
|
|
2018-07-11 09:51:38 +02:00
|
|
|
assert http_bzr_repo.get_url_rev(http_bzr_repo.url) == (
|
2018-07-15 19:39:06 +02:00
|
|
|
'http://bzr.myproject.org/MyProject/trunk/', None, (None, None),
|
2014-01-28 15:17:51 +01:00
|
|
|
)
|
2018-07-11 09:51:38 +02:00
|
|
|
assert https_bzr_repo.get_url_rev(https_bzr_repo.url) == (
|
2018-07-15 19:39:06 +02:00
|
|
|
'https://bzr.myproject.org/MyProject/trunk/', None, (None, None),
|
2014-01-28 15:17:51 +01:00
|
|
|
)
|
2018-07-11 09:51:38 +02:00
|
|
|
assert ssh_bzr_repo.get_url_rev(ssh_bzr_repo.url) == (
|
2018-07-15 19:39:06 +02:00
|
|
|
'bzr+ssh://bzr.myproject.org/MyProject/trunk/', None, (None, None),
|
2014-01-28 15:17:51 +01:00
|
|
|
)
|
2018-07-11 09:51:38 +02:00
|
|
|
assert ftp_bzr_repo.get_url_rev(ftp_bzr_repo.url) == (
|
2018-07-15 19:39:06 +02:00
|
|
|
'ftp://bzr.myproject.org/MyProject/trunk/', None, (None, None),
|
2014-01-28 15:17:51 +01:00
|
|
|
)
|
2018-07-11 09:51:38 +02:00
|
|
|
assert sftp_bzr_repo.get_url_rev(sftp_bzr_repo.url) == (
|
2018-07-15 19:39:06 +02:00
|
|
|
'sftp://bzr.myproject.org/MyProject/trunk/', None, (None, None),
|
2014-01-28 15:17:51 +01:00
|
|
|
)
|
2018-07-11 09:51:38 +02:00
|
|
|
assert launchpad_bzr_repo.get_url_rev(launchpad_bzr_repo.url) == (
|
2018-07-15 19:39:06 +02:00
|
|
|
'lp:MyLaunchpadProject', None, (None, None),
|
2014-01-28 15:17:51 +01:00
|
|
|
)
|
2016-05-26 12:43:26 +02:00
|
|
|
|
|
|
|
|
2018-07-15 19:39:06 +02:00
|
|
|
# The non-SVN backends all use the same make_rev_args(), so only test
|
|
|
|
# Git as a representative.
|
|
|
|
@pytest.mark.parametrize('username, password, expected', [
|
|
|
|
(None, None, []),
|
|
|
|
('user', None, []),
|
|
|
|
('user', 'pass', []),
|
2018-07-10 08:08:27 +02:00
|
|
|
])
|
2018-07-15 19:39:06 +02:00
|
|
|
def test_git__make_rev_args(username, password, expected):
|
2018-07-10 08:08:27 +02:00
|
|
|
"""
|
2018-07-15 19:39:06 +02:00
|
|
|
Test VersionControl.make_rev_args().
|
2018-07-10 08:08:27 +02:00
|
|
|
"""
|
2018-07-15 19:39:06 +02:00
|
|
|
actual = Git().make_rev_args(username, password)
|
2018-07-10 08:08:27 +02:00
|
|
|
assert actual == expected
|
|
|
|
|
|
|
|
|
2018-07-15 19:39:06 +02:00
|
|
|
@pytest.mark.parametrize('username, password, expected', [
|
|
|
|
(None, None, []),
|
|
|
|
('user', None, ['--username', 'user']),
|
|
|
|
('user', 'pass', ['--username', 'user', '--password', 'pass']),
|
2018-07-08 13:21:00 +02:00
|
|
|
])
|
2018-07-15 19:39:06 +02:00
|
|
|
def test_subversion__make_rev_args(username, password, expected):
|
2018-07-08 13:21:00 +02:00
|
|
|
"""
|
2018-07-15 19:39:06 +02:00
|
|
|
Test Subversion.make_rev_args().
|
2018-07-08 13:21:00 +02:00
|
|
|
"""
|
2018-07-15 19:39:06 +02:00
|
|
|
actual = Subversion().make_rev_args(username, password)
|
2018-07-08 13:21:00 +02:00
|
|
|
assert actual == expected
|
2018-07-15 19:39:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_subversion__get_url_rev_options():
|
|
|
|
"""
|
|
|
|
Test Subversion.get_url_rev_options().
|
|
|
|
"""
|
|
|
|
url = 'svn+https://user:pass@svn.example.com/MyProject@v1.0#egg=MyProject'
|
|
|
|
url, rev_options = Subversion().get_url_rev_options(url)
|
|
|
|
assert url == 'https://svn.example.com/MyProject'
|
|
|
|
assert rev_options.rev == 'v1.0'
|
|
|
|
assert rev_options.extra_args == (
|
|
|
|
['--username', 'user', '--password', 'pass']
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_git_version():
|
|
|
|
git_version = Git().get_git_version()
|
|
|
|
assert git_version >= parse_version('1.0.0')
|