core/cachew: rely on ~/.cache for default cache path
- rely on appdirs for default cache path instead of hardcoded /var/tmp/cachew technically backwards incompatible, but no action needed you might want to clean /var/tmp/cachew after updating - use default cache path (e.g. ~/.cache) by default see https://github.com/ActiveState/appdirs#some-example-output for more info *warning*: things will be cached by default now (used to be uncached before) - treat cache_dir = None in the config *warning*: kind of backwards incompatible.. but again nothing disasterous
This commit is contained in:
parent
837ea16dc8
commit
da3c1c9b74
6 changed files with 87 additions and 34 deletions
|
@ -4,9 +4,11 @@ import gzip
|
|||
import lzma
|
||||
import io
|
||||
import zipfile
|
||||
from typing import List
|
||||
|
||||
from my.core.kompress import kopen, kexists, CPath
|
||||
|
||||
|
||||
def test_kopen(tmp_path: Path) -> None:
|
||||
"Plaintext handled transparently"
|
||||
assert kopen(tmp_path / 'file' ).read() == 'just plaintext'
|
||||
|
@ -95,3 +97,26 @@ def test_warn_iterable() -> None:
|
|||
|
||||
assert list(x2) == [1, 2, 3]
|
||||
assert len(w) == 0
|
||||
|
||||
|
||||
def test_cachew() -> None:
|
||||
from cachew import settings
|
||||
settings.ENABLE = True # by default it's off in tests (see conftest.py)
|
||||
|
||||
from my.core.cachew import cache_dir
|
||||
from my.core.common import mcachew
|
||||
|
||||
called = 0
|
||||
@mcachew
|
||||
def cf() -> List[int]:
|
||||
nonlocal called
|
||||
called += 1
|
||||
return [1, 2, 3]
|
||||
|
||||
list(cf())
|
||||
cc = called
|
||||
# todo ugh. how to clean cache?
|
||||
# assert called == 1 # precondition, to avoid turdes from previous tests
|
||||
|
||||
assert list(cf()) == [1, 2, 3]
|
||||
assert called == cc
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue