Test the cache file opening and creation

This commit is contained in:
Luke Murphy 2019-07-20 12:29:35 +02:00
parent e027a188a9
commit 14a3d63453
No known key found for this signature in database
GPG key ID: 5E2EF5A63E3718CC
2 changed files with 14 additions and 1 deletions

View file

@ -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
View 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')