From cc85d6130345b6dbc41b5fd81be32419e44e2684 Mon Sep 17 00:00:00 2001 From: toofar Date: Sun, 18 Aug 2024 11:26:37 +1200 Subject: [PATCH] Teach sanity check in tests about temp dirs under HOME On GitHub the RUNNER_TEMP dir is inside the user's home directory. I think the spirit of the check is making sure you aren't touching stuff like ~/.config/qutebrowser/ in the tests, if it's within a specified tempdir it should be fine --- qutebrowser/utils/standarddir.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/qutebrowser/utils/standarddir.py b/qutebrowser/utils/standarddir.py index 026376dc2..1eb296e50 100644 --- a/qutebrowser/utils/standarddir.py +++ b/qutebrowser/utils/standarddir.py @@ -10,6 +10,7 @@ import sys import contextlib import enum import argparse +import tempfile from typing import Iterator, Optional, Dict from qutebrowser.qt.core import QStandardPaths @@ -311,14 +312,15 @@ def _create(path: str) -> None: 0700. If the destination directory exists already the permissions should not be changed. """ - if APPNAME == 'qute_test' and path.startswith('/home'): # pragma: no cover - for k, v in os.environ.items(): - if k == 'HOME' or k.startswith('XDG_'): - log.init.debug(f"{k} = {v}") - raise AssertionError( - "Trying to create directory inside /home during " - "tests, this should not happen." - ) + if APPNAME == 'qute_test': + if path.startswith('/home') and not path.startswith(tempfile.gettempdir()): # pragma: no cover + for k, v in os.environ.items(): + if k == 'HOME' or k.startswith('XDG_'): + log.init.debug(f"{k} = {v}") + raise AssertionError( + "Trying to create directory inside /home during " + "tests, this should not happen." + ) os.makedirs(path, 0o700, exist_ok=True)