mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Test the cache file opening and creation
This commit is contained in:
parent
e027a188a9
commit
14a3d63453
2 changed files with 14 additions and 1 deletions
|
@ -42,4 +42,6 @@ def open_cachefile(filename, mode='r', **kwargs):
|
||||||
# Set make_dir if not given
|
# Set make_dir if not given
|
||||||
kwargs['make_dir'] = kwargs.get('make_dir',
|
kwargs['make_dir'] = kwargs.get('make_dir',
|
||||||
True if mode[0] == 'w' else False)
|
True if mode[0] == 'w' else False)
|
||||||
return open('%s/%s' % (get_cachedir(**kwargs), filename), mode)
|
cache_dir = get_cachedir(**kwargs)
|
||||||
|
file_path = os.path.join(cache_dir, filename)
|
||||||
|
return open(file_path, mode)
|
||||||
|
|
11
test/test_cache.py
Normal file
11
test/test_cache.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import os.path
|
||||||
|
|
||||||
|
def test_open_cachefile_creates(monkeypatch, tmp_path):
|
||||||
|
monkeypatch.setenv('MOULINETTE_CACHE_DIR', str(tmp_path))
|
||||||
|
|
||||||
|
from moulinette.cache import open_cachefile
|
||||||
|
|
||||||
|
handle = open_cachefile('foo.cache', mode='w')
|
||||||
|
|
||||||
|
assert handle.mode == 'w'
|
||||||
|
assert handle.name == os.path.join(str(tmp_path), 'foo.cache')
|
Loading…
Reference in a new issue