| 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 json |
| 18 |
|
| 19 |
from fades import cache |
| 20 |
|
| 21 |
|
| 22 |
def test_missing_file(tmp_file): |
| 23 |
venvscache = cache.VEnvsCache(tmp_file) |
| 24 |
metadata = {"env_path": "some/path", "env_bin_path": "other/path", "extra": "foobar"} |
| 25 |
venvscache.store('installed', metadata, 'interpreter', 'options') |
| 26 |
|
| 27 |
with open(tmp_file, 'rt', encoding='utf8') as fh: |
| 28 |
data = json.loads(fh.readline()) |
| 29 |
assert 'timestamp' in data |
| 30 |
assert data['installed'] == 'installed' |
| 31 |
assert data['metadata'] == metadata |
| 32 |
assert data['interpreter'] == 'interpreter' |
| 33 |
assert data['options'] == 'options' |
| 34 |
|
| 35 |
|
| 36 |
def test_with_previous_content(tmp_file): |
| 37 |
with open(tmp_file, 'wt', encoding='utf8') as fh: |
| 38 |
fh.write(json.dumps({'foo': 'bar'}) + '\n') |
| 39 |
|
| 40 |
venvscache = cache.VEnvsCache(tmp_file) |
| 41 |
metadata = {"env_path": "some/path", "env_bin_path": "other/path", "extra": "foobar"} |
| 42 |
venvscache.store('installed', metadata, 'interpreter', 'options') |
| 43 |
|
| 44 |
with open(tmp_file, 'rt', encoding='utf8') as fh: |
| 45 |
data = json.loads(fh.readline()) |
| 46 |
assert data, {'foo': 'bar'} |
| 47 |
|
| 48 |
data = json.loads(fh.readline()) |
| 49 |
assert 'timestamp' in data |
| 50 |
assert data['installed'] == 'installed' |
| 51 |
assert data['metadata'] == metadata |
| 52 |
assert data['interpreter'] == 'interpreter' |
| 53 |
assert data['options'] == 'options' |