summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2023-11-22 15:25:19 +0100
committerFlorian Bruhin <me@the-compiler.org>2023-11-22 18:02:18 +0100
commit51dace7152ecdff29c4a43325a2a7d5805c2643b (patch)
treeb374bd6114f7055cea8d5060cd74236a64f2077a
parent50db87664d78163a7f28f158318281e935691867 (diff)
downloadqutebrowser-51dace7152ecdff29c4a43325a2a7d5805c2643b.tar.gz
qutebrowser-51dace7152ecdff29c4a43325a2a7d5805c2643b.zip
pakjoy: Use more constants
-rw-r--r--qutebrowser/misc/pakjoy.py9
-rw-r--r--tests/unit/misc/test_pakjoy.py14
2 files changed, 13 insertions, 10 deletions
diff --git a/qutebrowser/misc/pakjoy.py b/qutebrowser/misc/pakjoy.py
index 6c681eb65..ca33245db 100644
--- a/qutebrowser/misc/pakjoy.py
+++ b/qutebrowser/misc/pakjoy.py
@@ -37,6 +37,9 @@ from qutebrowser.utils import qtutils, standarddir, version, utils, log
HANGOUTS_MARKER = b"// Extension ID: nkeimhogjdpnpccoofpliimaahmaaome"
HANGOUTS_ID = 36197 # as found by toofar
PAK_VERSION = 5
+RESOURCES_ENV_VAR = "QTWEBENGINE_RESOURCES_PATH"
+CACHE_DIR_NAME = "webengine_resources_pak_quirk"
+PAK_FILENAME = "qtwebengine_resources.pak"
TARGET_URL = b"https://*.google.com/*"
REPLACEMENT_URL = b"https://qute.invalid/*"
@@ -154,7 +157,7 @@ def copy_webengine_resources() -> Optional[pathlib.Path]:
resources_dir /= pathlib.Path("lib", "QtWebEngineCore.framework", "Resources")
else:
resources_dir /= "resources"
- work_dir = pathlib.Path(standarddir.cache()) / "webengine_resources_pak_quirk"
+ work_dir = pathlib.Path(standarddir.cache()) / CACHE_DIR_NAME
if work_dir.exists():
log.misc.debug(f"Removing existing {work_dir}")
@@ -172,7 +175,7 @@ def copy_webengine_resources() -> Optional[pathlib.Path]:
shutil.copytree(resources_dir, work_dir)
- os.environ["QTWEBENGINE_RESOURCES_PATH"] = str(work_dir)
+ os.environ[RESOURCES_ENV_VAR] = str(work_dir)
return work_dir
@@ -210,4 +213,4 @@ def patch_webengine() -> None:
if webengine_resources_path is None:
return
- _patch(webengine_resources_path / "qtwebengine_resources.pak")
+ _patch(webengine_resources_path / PAK_FILENAME)
diff --git a/tests/unit/misc/test_pakjoy.py b/tests/unit/misc/test_pakjoy.py
index d4bb37d41..645764328 100644
--- a/tests/unit/misc/test_pakjoy.py
+++ b/tests/unit/misc/test_pakjoy.py
@@ -36,8 +36,8 @@ def skipifneeded():
@pytest.fixture(autouse=True)
def clean_env():
yield
- if "QTWEBENGINE_RESOURCES_PATH" in os.environ:
- del os.environ["QTWEBENGINE_RESOURCES_PATH"]
+ if pakjoy.RESOURCES_ENV_VAR in os.environ:
+ del os.environ[pakjoy.RESOURCES_ENV_VAR]
def patch_version(monkeypatch, *args):
@@ -64,7 +64,7 @@ def affected_version(monkeypatch):
@pytest.mark.parametrize("workdir_exists", [True, False])
def test_version_gate(cache_tmpdir, unaffected_version, mocker, workdir_exists):
- workdir = cache_tmpdir / "webengine_resources_pak_quirk"
+ workdir = cache_tmpdir / pakjoy.CACHE_DIR_NAME
if workdir_exists:
workdir.mkdir()
(workdir / "some_patched_file.pak").ensure()
@@ -104,9 +104,9 @@ class TestWithRealResourcesFile:
# afterwards.
pakjoy.patch_webengine()
- patched_resources = pathlib.Path(os.environ["QTWEBENGINE_RESOURCES_PATH"])
+ patched_resources = pathlib.Path(os.environ[pakjoy.RESOURCES_ENV_VAR])
- with open(patched_resources / "qtwebengine_resources.pak", "rb") as fd:
+ with open(patched_resources / pakjoy.PAK_FILENAME, "rb") as fd:
reparsed = pakjoy.PakParser(fd)
json_manifest = json_without_comments(reparsed.manifest)
@@ -120,8 +120,8 @@ class TestWithRealResourcesFile:
work_dir = pakjoy.copy_webengine_resources()
assert work_dir.exists()
- assert work_dir == standarddir.cache() / "webengine_resources_pak_quirk"
- assert (work_dir / "qtwebengine_resources.pak").exists()
+ assert work_dir == standarddir.cache() / pakjoy.CACHE_DIR_NAME
+ assert (work_dir / pakjoy.PAK_FILENAME).exists()
assert len(list(work_dir.glob("*"))) > 1
def test_copying_resources_overwrites(self):