| 1 |
# Copyright 2015-2026 Facundo Batista, Nicolás Demarchi |
| 2 |
# |
| 3 |
# This program is free software: you can redistribute it and/or modify it |
| 4 |
# under the terms of the GNU General Public License version 3, as published |
| 5 |
# by the Free Software Foundation. |
| 6 |
# |
| 7 |
# This program is distributed in the hope that it will be useful, but |
| 8 |
# WITHOUT ANY WARRANTY; without even the implied warranties of |
| 9 |
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 10 |
# PURPOSE. See the GNU General Public License for more details. |
| 11 |
# |
| 12 |
# You should have received a copy of the GNU General Public License along |
| 13 |
# with this program. If not, see <http://www.gnu.org/licenses/>. |
| 14 |
# |
| 15 |
# For further info, check https://github.com/PyAr/fades |
| 16 |
|
| 17 |
import pytest |
| 18 |
|
| 19 |
from fades import parsing |
| 20 |
|
| 21 |
from tests import get_reqs |
| 22 |
from tests.test_cache import get_distrib |
| 23 |
|
| 24 |
|
| 25 |
@pytest.mark.parametrize("req,installed,expected", [ |
| 26 |
# Equal |
| 27 |
("==5", "5", "ok"), |
| 28 |
("==5", "2", None), |
| 29 |
# Greater than |
| 30 |
(">5", "4", None), |
| 31 |
(">5", "5", None), |
| 32 |
(">5", "6", "ok"), |
| 33 |
# Greater than or equal |
| 34 |
(">=5", "4", None), |
| 35 |
(">=5", "5", "ok"), |
| 36 |
(">=5", "6", "ok"), |
| 37 |
# Less than |
| 38 |
("<5", "4", "ok"), |
| 39 |
("<5", "5", None), |
| 40 |
("<5", "6", None), |
| 41 |
# Less than or equal |
| 42 |
("<=5", "4", "ok"), |
| 43 |
("<=5", "5", "ok"), |
| 44 |
("<=5", "6", None), |
| 45 |
# Complex cases |
| 46 |
("== 2.5", "2.5.0", "ok"), |
| 47 |
("> 2.7", "2.12", "ok"), |
| 48 |
("> 2.7a0", "2.7", "ok"), |
| 49 |
("> 2.7", "2.7a0", None), |
| 50 |
# Crazy picky |
| 51 |
(">1.6,<1.9,!=1.9.6", "1.5.0", None), |
| 52 |
(">1.6,<1.9,!=1.9.6", "1.6.7", "ok"), |
| 53 |
(">1.6,<1.9,!=1.8.6", "1.8.7", "ok"), |
| 54 |
(">1.6,<1.9,!=1.9.6", "1.9.6", None), |
| 55 |
]) |
| 56 |
def test_check_versions(venvscache, fake_venv, req, installed, expected): |
| 57 |
"""The comparison in the selection.""" |
| 58 |
reqs = {"pypi": get_reqs("dep" + req)} |
| 59 |
interpreter = "pythonX.Y" |
| 60 |
options = {"foo": "bar"} |
| 61 |
venv = fake_venv("ok", installed={"pypi": {"dep": installed}}) |
| 62 |
resp = venvscache._select([venv], reqs, interpreter, uuid="", options=options) |
| 63 |
if expected is None: |
| 64 |
assert resp is None |
| 65 |
else: |
| 66 |
assert resp["extra"] == expected |
| 67 |
|
| 68 |
|
| 69 |
@pytest.mark.parametrize("possible_venvs", [ |
| 70 |
[ |
| 71 |
(get_distrib(('dep', '3')), 'venv_best_fit'), |
| 72 |
], |
| 73 |
[ |
| 74 |
(get_distrib(('dep1', '3'), ('dep2', '3')), 'venv_best_fit'), |
| 75 |
], |
| 76 |
[ |
| 77 |
(get_distrib(('dep', '5')), 'venv_best_fit'), |
| 78 |
(get_distrib(('dep', '3')), 'venv_1'), |
| 79 |
], |
| 80 |
[ |
| 81 |
(get_distrib(('dep1', '5'), ('dep2', '7')), 'venv_best_fit'), |
| 82 |
(get_distrib(('dep1', '3'), ('dep2', '6')), 'venv_1'), |
| 83 |
], |
| 84 |
[ |
| 85 |
(get_distrib(('dep1', '3'), ('dep2', '9')), 'venv_1'), |
| 86 |
(get_distrib(('dep1', '5'), ('dep2', '7')), 'venv_best_fit'), |
| 87 |
], |
| 88 |
[ |
| 89 |
(get_distrib(('dep1', '5'), ('dep2', '7')), 'venv_1'), |
| 90 |
(get_distrib(('dep1', '3'), ('dep2', '9')), 'venv_best_fit'), |
| 91 |
], |
| 92 |
[ |
| 93 |
(get_distrib(('dep1', '3'), ('dep2', '9'), ('dep3', '4')), 'venv_best_fit'), |
| 94 |
(get_distrib(('dep1', '5'), ('dep2', '7'), ('dep3', '2')), 'venv_1'), |
| 95 |
], |
| 96 |
[ |
| 97 |
(get_distrib(('dep2', '3'), ('dep1', '2'), ('dep3', '8')), 'venv_best_fit'), |
| 98 |
(get_distrib(('dep1', '7'), ('dep3', '5'), ('dep2', '2')), 'venv_1'), |
| 99 |
], |
| 100 |
[ |
| 101 |
(get_distrib(('dep1', '3'), ('dep2', '2')), 'venv_1'), |
| 102 |
(get_distrib(('dep1', '4'), ('dep2', '2')), 'venv_2'), |
| 103 |
(get_distrib(('dep1', '5'), ('dep2', '7')), 'venv_best_fit'), |
| 104 |
(get_distrib(('dep1', '5'), ('dep2', '6')), 'venv_3'), |
| 105 |
], |
| 106 |
[ |
| 107 |
([parsing.VCSDependency('someurl')], 'venv_best_fit'), |
| 108 |
], |
| 109 |
[ |
| 110 |
([parsing.VCSDependency('someurl')] + get_distrib(('dep', '3')), 'venv_best_fit'), |
| 111 |
], |
| 112 |
[ |
| 113 |
([parsing.VCSDependency('someurl')] + get_distrib(('dep', '3')), 'venv_best_fit'), |
| 114 |
([parsing.VCSDependency('someurl')] + get_distrib(('dep', '1')), 'venv_1'), |
| 115 |
], |
| 116 |
]) |
| 117 |
def test_best_fit(venvscache, possible_venvs): |
| 118 |
"""Check the venv best fitting decissor.""" |
| 119 |
assert venvscache._select_better_fit(possible_venvs) == 'venv_best_fit' |