pdfjs: Fix :version crash with no pdf.js
pdfjs.get_pdf_basename() returned None, causing in a TypeError. Instead of
throwing mocker.patch at it, fix the underlying issue.
Given we made the same mistake in three places:
- :version
- test_real_file for PDF.js
- is_available() in pdfjs.py (calls the function but doesn't use the result, so
is a nop now, even if PDF.js wasn't found)
...evidently we need to change the API so it still raises an exception if no
PDF.js is available.
Amends 0144ae3576.
This commit is contained in:
parent
0c3c131074
commit
eabbdb8ea3
|
|
@ -212,7 +212,8 @@ def get_pdfjs_basename():
|
|||
pass
|
||||
else:
|
||||
return ext
|
||||
return None
|
||||
|
||||
raise PDFJSNotFound(" or ".join(f"'build/{ext}'" for ext in exts))
|
||||
|
||||
|
||||
def is_available():
|
||||
|
|
|
|||
|
|
@ -849,13 +849,11 @@ class TestPDFJSVersion:
|
|||
"""Tests for _pdfjs_version."""
|
||||
|
||||
def test_not_found(self, mocker):
|
||||
mocker.patch('qutebrowser.utils.version.pdfjs.get_pdfjs_basename')
|
||||
mocker.patch('qutebrowser.utils.version.pdfjs.get_pdfjs_res_and_path',
|
||||
side_effect=pdfjs.PDFJSNotFound('/build/pdf.js'))
|
||||
assert version._pdfjs_version() == 'no'
|
||||
|
||||
def test_unknown(self, monkeypatch, mocker):
|
||||
mocker.patch('qutebrowser.utils.version.pdfjs.get_pdfjs_basename')
|
||||
def test_unknown(self, monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
'qutebrowser.utils.version.pdfjs.get_pdfjs_res_and_path',
|
||||
lambda path: (b'foobar', None))
|
||||
|
|
@ -880,7 +878,6 @@ class TestPDFJSVersion:
|
|||
// Use strict in our context only - users might not want it
|
||||
'use strict';
|
||||
""".replace('VARNAME', varname)).strip().encode('utf-8')
|
||||
mocker.patch('qutebrowser.utils.version.pdfjs.get_pdfjs_basename')
|
||||
monkeypatch.setattr(
|
||||
'qutebrowser.utils.version.pdfjs.get_pdfjs_res_and_path',
|
||||
lambda path: (pdfjs_code, '/foo/bar/pdf.js'))
|
||||
|
|
|
|||
Loading…
Reference in New Issue