tests: Handle XDG_*_HOME standarddir tests
For some reason, a recent change on GitHub's runners seems to explicitly set XDG_CONFIG_HOME. That breaks our tests, however, because we can't simply override HOME to control where the directories are created. Thus, make sure that XDG_*_HOME is always unset.
This commit is contained in:
parent
e1b4c1d58c
commit
23810876e4
|
|
@ -42,6 +42,14 @@ APPNAME = 'qute_test'
|
|||
pytestmark = pytest.mark.usefixtures('qapp')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fake_home_envvar(monkeypatch, tmp_path):
|
||||
"""Fake a different HOME via environment variables."""
|
||||
for k in ['XDG_DATA_HOME', 'XDG_CONFIG_HOME', 'XDG_DATA_HOME']:
|
||||
monkeypatch.delenv(k, raising=False)
|
||||
monkeypatch.setenv('HOME', str(tmp_path))
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def clear_standarddir_cache_and_patch(qapp, monkeypatch):
|
||||
"""Make sure the standarddir cache is cleared before/after each test.
|
||||
|
|
@ -79,10 +87,9 @@ def test_unset_organization_no_qapp(monkeypatch):
|
|||
|
||||
@pytest.mark.fake_os('mac')
|
||||
@pytest.mark.posix
|
||||
def test_fake_mac_config(tmpdir, monkeypatch):
|
||||
def test_fake_mac_config(tmp_path, fake_home_envvar):
|
||||
"""Test standardir.config on a fake Mac."""
|
||||
monkeypatch.setenv('HOME', str(tmpdir))
|
||||
expected = str(tmpdir) + '/.qute_test' # always with /
|
||||
expected = str(tmp_path) + '/.qute_test' # always with /
|
||||
standarddir._init_config(args=None)
|
||||
assert standarddir.config() == expected
|
||||
|
||||
|
|
@ -175,13 +182,10 @@ class TestStandardDir:
|
|||
(standarddir.download, ['Downloads']),
|
||||
])
|
||||
@pytest.mark.linux
|
||||
def test_linux_normal(self, monkeypatch, tmpdir, func, subdirs):
|
||||
def test_linux_normal(self, fake_home_envvar, tmp_path, func, subdirs):
|
||||
"""Test dirs with XDG_*_HOME not set."""
|
||||
monkeypatch.setenv('HOME', str(tmpdir))
|
||||
for var in ['DATA', 'CONFIG', 'CACHE']:
|
||||
monkeypatch.delenv('XDG_{}_HOME'.format(var), raising=False)
|
||||
standarddir._init_dirs()
|
||||
assert func() == str(tmpdir.join(*subdirs))
|
||||
assert func() == str(tmp_path.joinpath(*subdirs))
|
||||
|
||||
@pytest.mark.linux
|
||||
@pytest.mark.qt_log_ignore(r'^QStandardPaths: ')
|
||||
|
|
@ -397,19 +401,17 @@ class TestSystemData:
|
|||
|
||||
|
||||
@pytest.mark.parametrize('args_kind', ['basedir', 'normal', 'none'])
|
||||
def test_init(tmpdir, monkeypatch, args_kind):
|
||||
def test_init(tmp_path, args_kind, fake_home_envvar):
|
||||
"""Do some sanity checks for standarddir.init().
|
||||
|
||||
Things like _init_cachedir_tag() are tested in more detail in other tests.
|
||||
"""
|
||||
assert standarddir._locations == {}
|
||||
|
||||
monkeypatch.setenv('HOME', str(tmpdir))
|
||||
|
||||
if args_kind == 'normal':
|
||||
args = types.SimpleNamespace(basedir=None)
|
||||
elif args_kind == 'basedir':
|
||||
args = types.SimpleNamespace(basedir=str(tmpdir))
|
||||
args = types.SimpleNamespace(basedir=str(tmp_path))
|
||||
else:
|
||||
assert args_kind == 'none'
|
||||
args = None
|
||||
|
|
|
|||
Loading…
Reference in New Issue