summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2023-12-04 10:46:30 +0100
committerFlorian Bruhin <me@the-compiler.org>2023-12-04 10:46:30 +0100
commit1d29cf641ba25556ca148dc0a20abe0b90469874 (patch)
tree84c2f5d3f3a931ba2ed80b7e2a3245a7572a40e0 /tests
parent23a168926262f2304652baee57b7793c87ffe359 (diff)
downloadqutebrowser-1d29cf641ba25556ca148dc0a20abe0b90469874.tar.gz
qutebrowser-1d29cf641ba25556ca148dc0a20abe0b90469874.zip
Simplify get_pdfjs test
Given that the two branches share rather little, it seems simpler to separate the two tests. Also use monkeypatch, since we don't use any of unittest.mock's complexity
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/browser/test_pdfjs.py33
1 files changed, 17 insertions, 16 deletions
diff --git a/tests/unit/browser/test_pdfjs.py b/tests/unit/browser/test_pdfjs.py
index 7bd9588b4..cb5c26229 100644
--- a/tests/unit/browser/test_pdfjs.py
+++ b/tests/unit/browser/test_pdfjs.py
@@ -196,27 +196,28 @@ def test_is_available(available, mocker):
@pytest.mark.parametrize('found_file', [
"build/pdf.js",
"build/pdf.mjs",
- None,
])
-def test_get_pdfjs_js_path(found_file, mocker):
-
- def side_effect(requested):
- if found_file and requested.endswith(found_file):
+def test_get_pdfjs_js_path(found_file: str, monkeypatch: pytest.MonkeyPatch):
+ def fake_pdfjs_res(requested):
+ if requested.endswith(found_file):
return
+ raise pdfjs.PDFJSNotFound(requested)
+
+ monkeypatch.setattr(pdfjs, 'get_pdfjs_res', fake_pdfjs_res)
+ assert pdfjs.get_pdfjs_js_path() == found_file
+
+def test_get_pdfjs_js_path_none(monkeypatch: pytest.MonkeyPatch):
+ def fake_pdfjs_res(requested):
raise pdfjs.PDFJSNotFound(requested)
- mock = mocker.patch.object(pdfjs, 'get_pdfjs_res', autospec=True)
- mock.side_effect = side_effect
-
- if found_file is None:
- with pytest.raises(
- pdfjs.PDFJSNotFound,
- match="Path 'build/pdf.js or build/pdf.mjs' not found"
- ):
- pdfjs.get_pdfjs_js_path()
- else:
- assert pdfjs.get_pdfjs_js_path() == found_file
+ monkeypatch.setattr(pdfjs, 'get_pdfjs_res', fake_pdfjs_res)
+
+ with pytest.raises(
+ pdfjs.PDFJSNotFound,
+ match="Path 'build/pdf.js or build/pdf.mjs' not found"
+ ):
+ pdfjs.get_pdfjs_js_path()
@pytest.mark.parametrize('mimetype, url, enabled, expected', [