| 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 |
from unittest.mock import patch |
| 18 |
|
| 19 |
from fades import cache |
| 20 |
|
| 21 |
|
| 22 |
def test_missing_file_pytest(tmp_file): |
| 23 |
venvscache = cache.VEnvsCache(tmp_file) |
| 24 |
with patch.object(venvscache, '_select', return_value=None) as mock: |
| 25 |
resp = venvscache.get_venv('requirements', 'interpreter', uuid='', options='options') |
| 26 |
mock.assert_called_with([], 'requirements', 'interpreter', uuid='', options='options') |
| 27 |
assert not resp |
| 28 |
|
| 29 |
|
| 30 |
def test_empty_file_pytest(tmp_file): |
| 31 |
open(tmp_file, 'wt', encoding='utf8').close() |
| 32 |
venvscache = cache.VEnvsCache(tmp_file) |
| 33 |
with patch.object(venvscache, '_select', return_value=None) as mock: |
| 34 |
resp = venvscache.get_venv('requirements', 'interpreter') |
| 35 |
mock.assert_called_with([], 'requirements', 'interpreter', uuid='', options=None) |
| 36 |
assert not resp |
| 37 |
|
| 38 |
|
| 39 |
def test_some_file_content_pytest(tmp_file): |
| 40 |
with open(tmp_file, 'wt', encoding='utf8') as fh: |
| 41 |
fh.write('foo\nbar\n') |
| 42 |
venvscache = cache.VEnvsCache(tmp_file) |
| 43 |
with patch.object(venvscache, '_select', return_value="resp") as mock: |
| 44 |
resp = venvscache.get_venv('requirements', 'interpreter', uuid='', options='options') |
| 45 |
mock.assert_called_with(['foo', 'bar'], 'requirements', 'interpreter', uuid='', |
| 46 |
options='options') |
| 47 |
assert resp == 'resp' |
| 48 |
|
| 49 |
|
| 50 |
def test_get_by_uuid_pytest(tmp_file): |
| 51 |
with open(tmp_file, 'wt', encoding='utf8') as fh: |
| 52 |
fh.write('foo\nbar\n') |
| 53 |
venvscache = cache.VEnvsCache(tmp_file) |
| 54 |
with patch.object(venvscache, '_select', return_value='resp') as mock: |
| 55 |
resp = venvscache.get_venv(uuid='uuid') |
| 56 |
mock.assert_called_with(['foo', 'bar'], None, '', uuid='uuid', options=None) |
| 57 |
assert resp == 'resp' |