|
22 | 22 | from pip._internal.operations.prepare import RequirementPreparer
|
23 | 23 | from pip._internal.req import InstallRequirement, RequirementSet
|
24 | 24 | from pip._internal.req.constructors import (
|
| 25 | + _get_url_from_path, |
| 26 | + _looks_like_path, |
25 | 27 | install_req_from_editable,
|
26 | 28 | install_req_from_line,
|
27 | 29 | install_req_from_req_string,
|
@@ -343,6 +345,33 @@ def test_url_with_query(self):
|
343 | 345 | req = install_req_from_line(url + fragment)
|
344 | 346 | assert req.link.url == url + fragment, req.link
|
345 | 347 |
|
| 348 | + def test_pep440_wheel_link_requirement(self): |
| 349 | + url = 'https://whatever.com/test-0.4-py2.py3-bogus-any.whl' |
| 350 | + line = 'test @ https://whatever.com/test-0.4-py2.py3-bogus-any.whl' |
| 351 | + req = install_req_from_line(line) |
| 352 | + parts = str(req.req).split('@', 1) |
| 353 | + assert len(parts) == 2 |
| 354 | + assert parts[0].strip() == 'test' |
| 355 | + assert parts[1].strip() == url |
| 356 | + |
| 357 | + def test_pep440_url_link_requirement(self): |
| 358 | + url = 'git+http://foo.com@ref#egg=foo' |
| 359 | + line = 'foo @ git+http://foo.com@ref#egg=foo' |
| 360 | + req = install_req_from_line(line) |
| 361 | + parts = str(req.req).split('@', 1) |
| 362 | + assert len(parts) == 2 |
| 363 | + assert parts[0].strip() == 'foo' |
| 364 | + assert parts[1].strip() == url |
| 365 | + |
| 366 | + def test_url_with_authentication_link_requirement(self): |
| 367 | + url = 'https://[email protected]/test-0.4-py2.py3-bogus-any.whl' |
| 368 | + line = 'https://[email protected]/test-0.4-py2.py3-bogus-any.whl' |
| 369 | + req = install_req_from_line(line) |
| 370 | + assert req.link is not None |
| 371 | + assert req.link.is_wheel |
| 372 | + assert req.link.scheme == "https" |
| 373 | + assert req.link.url == url |
| 374 | + |
346 | 375 | def test_unsupported_wheel_link_requirement_raises(self):
|
347 | 376 | reqset = RequirementSet()
|
348 | 377 | req = install_req_from_line(
|
@@ -634,3 +663,95 @@ def test_mismatched_versions(caplog, tmpdir):
|
634 | 663 | 'Requested simplewheel==2.0, '
|
635 | 664 | 'but installing version 1.0'
|
636 | 665 | )
|
| 666 | + |
| 667 | + |
| 668 | +@pytest.mark.parametrize('args, expected', [ |
| 669 | + # Test UNIX-like paths |
| 670 | + (('/path/to/installable'), True), |
| 671 | + # Test relative paths |
| 672 | + (('./path/to/installable'), True), |
| 673 | + # Test current path |
| 674 | + (('.'), True), |
| 675 | + # Test url paths |
| 676 | + (('https://whatever.com/test-0.4-py2.py3-bogus-any.whl'), True), |
| 677 | + # Test pep440 paths |
| 678 | + (('test @ https://whatever.com/test-0.4-py2.py3-bogus-any.whl'), True), |
| 679 | + # Test wheel |
| 680 | + (('simple-0.1-py2.py3-none-any.whl'), False), |
| 681 | +]) |
| 682 | +def test_looks_like_path(args, expected): |
| 683 | + assert _looks_like_path(args) == expected |
| 684 | + |
| 685 | + |
| 686 | +@pytest.mark.skipif( |
| 687 | + not sys.platform.startswith("win"), |
| 688 | + reason='Test only available on Windows' |
| 689 | +) |
| 690 | +@pytest.mark.parametrize('args, expected', [ |
| 691 | + # Test relative paths |
| 692 | + (('.\\path\\to\\installable'), True), |
| 693 | + (('relative\\path'), True), |
| 694 | + # Test absolute paths |
| 695 | + (('C:\\absolute\\path'), True), |
| 696 | +]) |
| 697 | +def test_looks_like_path_win(args, expected): |
| 698 | + assert _looks_like_path(args) == expected |
| 699 | + |
| 700 | + |
| 701 | +@pytest.mark.parametrize('args, mock_returns, expected', [ |
| 702 | + # Test pep440 urls |
| 703 | + (('/path/to/foo @ git+http://foo.com@ref#egg=foo', |
| 704 | + 'foo @ git+http://foo.com@ref#egg=foo'), (False, False), None), |
| 705 | + # Test pep440 urls without spaces |
| 706 | + (('/path/to/foo@git+http://foo.com@ref#egg=foo', |
| 707 | + 'foo @ git+http://foo.com@ref#egg=foo'), (False, False), None), |
| 708 | + # Test pep440 wheel |
| 709 | + (('/path/to/test @ https://whatever.com/test-0.4-py2.py3-bogus-any.whl', |
| 710 | + 'test @ https://whatever.com/test-0.4-py2.py3-bogus-any.whl'), |
| 711 | + (False, False), None), |
| 712 | + # Test name is not a file |
| 713 | + (('/path/to/simple==0.1', |
| 714 | + 'simple==0.1'), |
| 715 | + (False, False), None), |
| 716 | +]) |
| 717 | +@patch('pip._internal.req.req_install.os.path.isdir') |
| 718 | +@patch('pip._internal.req.req_install.os.path.isfile') |
| 719 | +def test_get_url_from_path( |
| 720 | + isdir_mock, isfile_mock, args, mock_returns, expected |
| 721 | +): |
| 722 | + isdir_mock.return_value = mock_returns[0] |
| 723 | + isfile_mock.return_value = mock_returns[1] |
| 724 | + assert _get_url_from_path(*args) is expected |
| 725 | + |
| 726 | + |
| 727 | +@patch('pip._internal.req.req_install.os.path.isdir') |
| 728 | +@patch('pip._internal.req.req_install.os.path.isfile') |
| 729 | +def test_get_url_from_path__archive_file(isdir_mock, isfile_mock): |
| 730 | + isdir_mock.return_value = False |
| 731 | + isfile_mock.return_value = True |
| 732 | + name = 'simple-0.1-py2.py3-none-any.whl' |
| 733 | + path = os.path.join('/path/to/' + name) |
| 734 | + url = path_to_url(path) |
| 735 | + assert _get_url_from_path(path, name) == url |
| 736 | + |
| 737 | + |
| 738 | +@patch('pip._internal.req.req_install.os.path.isdir') |
| 739 | +@patch('pip._internal.req.req_install.os.path.isfile') |
| 740 | +def test_get_url_from_path__installable_dir(isdir_mock, isfile_mock): |
| 741 | + isdir_mock.return_value = True |
| 742 | + isfile_mock.return_value = True |
| 743 | + name = 'some/setuptools/project' |
| 744 | + path = os.path.join('/path/to/' + name) |
| 745 | + url = path_to_url(path) |
| 746 | + assert _get_url_from_path(path, name) == url |
| 747 | + |
| 748 | + |
| 749 | +@patch('pip._internal.req.req_install.os.path.isdir') |
| 750 | +def test_get_url_from_path__installable_error(isdir_mock): |
| 751 | + isdir_mock.return_value = True |
| 752 | + name = 'some/setuptools/project' |
| 753 | + path = os.path.join('/path/to/' + name) |
| 754 | + with pytest.raises(InstallationError) as e: |
| 755 | + _get_url_from_path(path, name) |
| 756 | + err_msg = e.value.args[0] |
| 757 | + assert "Neither 'setup.py' nor 'pyproject.toml' found" in err_msg |
0 commit comments