summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2020-11-10 15:11:33 +0100
committerFlorian Bruhin <me@the-compiler.org>2020-11-25 18:02:16 +0100
commit1f10b070d1d6942791d16c8f60fe10812804c0f8 (patch)
treededeab52ad7ca0472c5acdd519f24c8619279d2e
parent5628d8309b329e686f03cf06d469fa1a5136b990 (diff)
downloadqutebrowser-1f10b070d1d6942791d16c8f60fe10812804c0f8.tar.gz
qutebrowser-1f10b070d1d6942791d16c8f60fe10812804c0f8.zip
tests: Fix pdfjs broken installation if bundled available
See #5752 (cherry picked from commit 5181b6084df972f2ba0484086119797797012e1f)
-rw-r--r--tests/unit/browser/test_pdfjs.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/tests/unit/browser/test_pdfjs.py b/tests/unit/browser/test_pdfjs.py
index d05ff1fc0..bf49098c4 100644
--- a/tests/unit/browser/test_pdfjs.py
+++ b/tests/unit/browser/test_pdfjs.py
@@ -52,15 +52,6 @@ def test_generate_pdfjs_page(available, snippet, monkeypatch):
assert snippet in content
-def test_broken_installation(data_tmpdir, monkeypatch):
- """Make sure we don't crash with a broken local installation."""
- monkeypatch.setattr(pdfjs, '_SYSTEM_PATHS', [])
- (data_tmpdir / 'pdfjs' / 'pdf.js').ensure() # But no viewer.html
-
- content = pdfjs.generate_pdfjs_page('example.pdf', QUrl())
- assert '<h1>No pdf.js installation found</h1>' in content
-
-
# Note that we got double protection, once because we use QUrl.FullyEncoded and
# because we use qutebrowser.utils.javascript.to_js. Characters like " are
# already replaced by QUrl.
@@ -166,6 +157,18 @@ class TestResources:
expected = 'OSError while reading PDF.js file: Message'
assert caplog.messages == [expected]
+ def test_broken_installation(self, data_tmpdir, tmpdir, monkeypatch,
+ read_file_mock):
+ """Make sure we don't crash with a broken local installation."""
+ monkeypatch.setattr(pdfjs, '_SYSTEM_PATHS', [])
+ monkeypatch.setattr(pdfjs.os.path, 'expanduser', lambda _in: tmpdir / 'fallback')
+ read_file_mock.side_effect = FileNotFoundError
+
+ (data_tmpdir / 'pdfjs' / 'pdf.js').ensure() # But no viewer.html
+
+ content = pdfjs.generate_pdfjs_page('example.pdf', QUrl())
+ assert '<h1>No pdf.js installation found</h1>' in content
+
@pytest.mark.parametrize('path, expected', [
('web/viewer.js', 'viewer.js'),