Changeset - 8fa9a0ffe6f7
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-04-13 02:24:34
brettcsmith@brettcsmith.org
tests: Set XDG_CONFIG_HOME for safety.
2 files changed with 4 insertions and 2 deletions:
0 comments (0 inline, 0 general)
tests/conftest.py
Show inline comments
 
import os
 

	
 
import pytest
 

	
 
from . import testutil
 

	
 
@pytest.fixture(scope='session', autouse=True)
 
def clean_environment(tmpdir_factory):
 
    config_path_s = str(testutil.test_path('userconfig'))
 
    os.environ.pop('RTAUTH', None)
 
    os.environ.pop('RTPASSWD', None)
 
    os.environ.pop('RTSERVER', None)
 
    os.environ.pop('RTUSER', None)
 
    os.environ['CONSERVANCY_REPOSITORY'] = str(testutil.test_path('repository'))
 
    os.environ['HOME'] = str(testutil.test_path('userconfig'))
 
    os.environ['HOME'] = config_path_s
 
    os.environ['XDG_CACHE_HOME'] = str(tmpdir_factory.mktemp('.cache'))
 
    os.environ['XDG_CONFIG_HOME'] = config_path_s
tests/test_config.py
Show inline comments
...
 
@@ -269,51 +269,51 @@ def test_cache_mkdir_exists_ok(tmp_path):
 
        config = config_mod.Config()
 
        cache_path = config.cache_dir_path(expected.name)
 
    assert cache_path == expected
 

	
 
def test_cache_path_conflict(tmp_path):
 
    extant_path = tmp_path / 'TESTcache'
 
    extant_path.touch()
 
    with update_environ(XDG_CACHE_HOME=tmp_path):
 
        config = config_mod.Config()
 
        cache_path = config.cache_dir_path(extant_path.name)
 
    assert cache_path is None
 
    assert extant_path.is_file()
 

	
 
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))
 

	
 
@pytest.mark.parametrize('config_path', [
 
    None,
 
    '',
 
    'nonexistent/relative/path',
 
])
 
def test_config_file_path(config_path):
 
    expected = Path('~/.config/conservancy_beancount/config.ini').expanduser()
 
    with update_environ(XDG_CONFIG_HOME=config_path):
 
        config = config_mod.Config()
 
        assert config.config_file_path() == expected
 

	
 
def test_config_file_path_respects_xdg_config_home():
 
    with update_environ(XDG_CONFIG_HOME='/etc'):
 
        config = config_mod.Config()
 
        assert config.config_file_path() == Path('/etc/conservancy_beancount/config.ini')
 

	
 
def test_config_file_path_with_subdir():
 
    expected = Path('~/.config/conftest/config.ini').expanduser()
 
    expected = testutil.test_path('userconfig/conftest/config.ini')
 
    config = config_mod.Config()
 
    assert config.config_file_path('conftest') == expected
0 comments (0 inline, 0 general)