Changeset - 24813a9b81de
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-04-10 12:34:55
brettcsmith@brettcsmith.org
config: Ignore non-absolute XDG_CACHE_HOME.

Per the spec.
2 files changed with 12 insertions and 0 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/config.py
Show inline comments
...
 
@@ -78,12 +78,17 @@ class Config:
 
            return path
 

	
 
    def cache_dir_path(self, name: str='conservancy_beancount') -> Optional[Path]:
 
        try:
 
            cache_root = Path(os.environ['XDG_CACHE_HOME'])
 
        except (KeyError, ValueError):
 
            ok = False
 
        else:
 
            # Per the spec, non-absolute paths should be ignored.
 
            ok = cache_root.is_absolute()
 
        if not ok:
 
            cache_root = Path.home() / '.cache'
 
        return (
 
            self._dir_or_none(cache_root)
 
            and self._dir_or_none(cache_root / name)
 
        )
 

	
tests/test_config.py
Show inline comments
...
 
@@ -280,10 +280,17 @@ def test_cache_path_conflict(tmp_path):
 
def test_cache_path_parent_conflict(tmp_path):
 
    (tmp_path / '.cache').touch()
 
    with update_environ(HOME=tmp_path, XDG_CACHE_HOME=None):
 
        config = config_mod.Config()
 
        assert config.cache_dir_path('TESTcache') is None
 

	
 
def test_relative_xdg_cache_home_ignored(tmp_path):
 
    with update_environ(HOME=tmp_path,
 
                        XDG_CACHE_HOME='nonexistent/test/cache/directory/tree'):
 
        config = config_mod.Config()
 
        cache_dir_path = config.cache_dir_path('TESTcache')
 
    assert cache_dir_path == tmp_path / '.cache/TESTcache'
 

	
 
def test_payment_threshold():
 
    threshold = config_mod.Config().payment_threshold()
 
    assert threshold == 0
 
    assert isinstance(threshold, (int, decimal.Decimal))
0 comments (0 inline, 0 general)