|
8 | 8 | from mock import Mock, patch, mock_open
|
9 | 9 | from pip.exceptions import (
|
10 | 10 | PreviousBuildDirError, InvalidWheelFilename, UnsupportedWheel,
|
| 11 | + BestVersionAlreadyInstalled, |
11 | 12 | )
|
12 | 13 | from pip.download import PipSession
|
13 | 14 | from pip.index import PackageFinder
|
@@ -54,6 +55,60 @@ def test_no_reuse_existing_build_dir(self, data):
|
54 | 55 | finder,
|
55 | 56 | )
|
56 | 57 |
|
| 58 | + @patch( |
| 59 | + 'pip.req.req_install.pkg_resources.get_distribution', |
| 60 | + lambda x: pkg_resources.Distribution( |
| 61 | + project_name='Pygments', |
| 62 | + version='2.0.2', |
| 63 | + location='/python', |
| 64 | + ) |
| 65 | + ) |
| 66 | + def test_upgrade_no_look_at_pypi_if_exact_version_installed( |
| 67 | + self, data): |
| 68 | + """ |
| 69 | + If an exact version is specified for install, and that version is |
| 70 | + already installed, then there is no point going to pypi as no install |
| 71 | + is needed. |
| 72 | + """ |
| 73 | + reqset = self.basic_reqset() |
| 74 | + reqset.upgrade = True |
| 75 | + req = InstallRequirement.from_line('pygments==2.0.2') |
| 76 | + req.url = None |
| 77 | + reqset.add_requirement(req) |
| 78 | + finder = PackageFinder([data.find_links], [], session=PipSession()) |
| 79 | + with patch.object(finder, 'find_requirement') as find_requirement: |
| 80 | + find_requirement.side_effect = AssertionError( |
| 81 | + 'find_requirement should NOT be called') |
| 82 | + reqset.prepare_files(finder) |
| 83 | + |
| 84 | + @patch( |
| 85 | + 'pip.req.req_install.pkg_resources.get_distribution', |
| 86 | + lambda x: pkg_resources.Distribution( |
| 87 | + project_name='Pygments', |
| 88 | + version='2.0.2', |
| 89 | + location='/python', |
| 90 | + ) |
| 91 | + ) |
| 92 | + def test_upgrade_look_at_pypi_if_exact_version_installed_and_force( |
| 93 | + self, data): |
| 94 | + """ |
| 95 | + If an exact version is specified for install, and that version is |
| 96 | + already installed, but --force-reinstall was provided, we should hit |
| 97 | + PyPI. |
| 98 | + """ |
| 99 | + reqset = self.basic_reqset() |
| 100 | + reqset.upgrade = True |
| 101 | + reqset.force_reinstall = True |
| 102 | + req = InstallRequirement.from_line('pygments==2.0.2') |
| 103 | + req.url = None |
| 104 | + reqset.add_requirement(req) |
| 105 | + finder = PackageFinder([data.find_links], [], session=PipSession()) |
| 106 | + with patch.object(finder, 'find_requirement') as find_requirement: |
| 107 | + find_requirement.side_effect = BestVersionAlreadyInstalled |
| 108 | + with pytest.raises(BestVersionAlreadyInstalled): |
| 109 | + reqset.prepare_files(finder) |
| 110 | + find_requirement.assert_called_once() |
| 111 | + |
57 | 112 | def test_environment_marker_extras(self, data):
|
58 | 113 | """
|
59 | 114 | Test that the environment marker extras are used with
|
|
0 commit comments