summaryrefslogtreecommitdiff
path: root/tests/unit/utils/test_standarddir.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/utils/test_standarddir.py')
-rw-r--r--tests/unit/utils/test_standarddir.py42
1 files changed, 30 insertions, 12 deletions
diff --git a/tests/unit/utils/test_standarddir.py b/tests/unit/utils/test_standarddir.py
index 035ce87a3..1a9107995 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: ')
@@ -198,6 +202,22 @@ class TestStandardDir:
standarddir._init_runtime(args=None)
assert standarddir.runtime() == str(tmpdir_env / APPNAME)
+ @pytest.mark.linux
+ def test_flatpak_runtimedir(self, monkeypatch, tmp_path):
+ runtime_path = tmp_path / 'runtime'
+ runtime_path.mkdir()
+ runtime_path.chmod(0o0700)
+
+ app_id = 'org.qutebrowser.qutebrowser'
+ expected = runtime_path / 'app' / app_id
+
+ monkeypatch.setattr(standarddir.version, 'is_flatpak', lambda: True)
+ monkeypatch.setenv('XDG_RUNTIME_DIR', str(runtime_path))
+ monkeypatch.setenv('FLATPAK_ID', app_id)
+
+ standarddir._init_runtime(args=None)
+ assert standarddir.runtime() == str(expected)
+
@pytest.mark.fake_os('windows')
def test_runtimedir_empty_tempdir(self, monkeypatch, tmpdir):
"""With an empty tempdir on non-Linux, we should raise."""
@@ -397,19 +417,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