summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2021-03-15 13:21:52 +0100
committerFlorian Bruhin <me@the-compiler.org>2021-03-17 18:51:46 +0100
commitc30a6c5e95974be7f30ab67a892d50b34fb13f17 (patch)
tree11c5dc92574e34b495df38753dc9beacd0f55c88
parentaa1801ecae2ce1d9d811bd33fd46359fc4d0c0e4 (diff)
downloadqutebrowser-c30a6c5e95974be7f30ab67a892d50b34fb13f17.tar.gz
qutebrowser-c30a6c5e95974be7f30ab67a892d50b34fb13f17.zip
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. (cherry picked from commit 23810876e408253aee8ba19082abd7f07ec7925d)
-rw-r--r--tests/unit/utils/test_standarddir.py26
1 files changed, 14 insertions, 12 deletions
diff --git a/tests/unit/utils/test_standarddir.py b/tests/unit/utils/test_standarddir.py
index 035ce87a3..5b24ed962 100644
--- a/tests/unit/utils/test_standarddir.py
+++ b/tests/unit/utils/test_standarddir.py
@@ -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