fix pdf.js detection in :version
Now that pdf.js could be shipped with either js or mjs file extensions we shouldn't hardcode the filename. Call the function for detecting the filename instead. And make it public.
This commit is contained in:
parent
6c937f6150
commit
0144ae3576
|
|
@ -50,7 +50,7 @@ def generate_pdfjs_page(filename, url):
|
|||
filename: The filename of the PDF to open.
|
||||
url: The URL being opened.
|
||||
"""
|
||||
pdfjs_name = _get_pdfjs_basename()
|
||||
pdfjs_name = get_pdfjs_basename()
|
||||
if pdfjs_name is None or not is_available():
|
||||
pdfjs_dir = os.path.join(standarddir.data(), 'pdfjs')
|
||||
return jinja.render('no_pdfjs.html',
|
||||
|
|
@ -204,7 +204,7 @@ def _read_from_system(system_path, names):
|
|||
return (None, None)
|
||||
|
||||
|
||||
def _get_pdfjs_basename():
|
||||
def get_pdfjs_basename():
|
||||
"""Checks for pdf.js main module availability and returns the basename if available."""
|
||||
exts = ['pdf.js', 'pdf.mjs']
|
||||
for ext in exts:
|
||||
|
|
|
|||
|
|
@ -480,7 +480,9 @@ def _pdfjs_version() -> str:
|
|||
A string with the version number.
|
||||
"""
|
||||
try:
|
||||
pdfjs_file, file_path = pdfjs.get_pdfjs_res_and_path('build/pdf.js')
|
||||
pdfjs_file, file_path = pdfjs.get_pdfjs_res_and_path(
|
||||
str(pathlib.Path("build") / pdfjs.get_pdfjs_basename())
|
||||
)
|
||||
except pdfjs.PDFJSNotFound:
|
||||
return 'no'
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -849,11 +849,13 @@ 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):
|
||||
def test_unknown(self, monkeypatch, mocker):
|
||||
mocker.patch('qutebrowser.utils.version.pdfjs.get_pdfjs_basename')
|
||||
monkeypatch.setattr(
|
||||
'qutebrowser.utils.version.pdfjs.get_pdfjs_res_and_path',
|
||||
lambda path: (b'foobar', None))
|
||||
|
|
@ -864,7 +866,7 @@ class TestPDFJSVersion:
|
|||
'var pdfjsVersion', # v2.0.943
|
||||
'const pdfjsVersion', # v2.5.207
|
||||
])
|
||||
def test_known(self, monkeypatch, varname):
|
||||
def test_known(self, monkeypatch, mocker, varname):
|
||||
pdfjs_code = textwrap.dedent("""
|
||||
// Initializing PDFJS global object (if still undefined)
|
||||
if (typeof PDFJS === 'undefined') {
|
||||
|
|
@ -878,6 +880,7 @@ 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'))
|
||||
|
|
@ -886,7 +889,9 @@ class TestPDFJSVersion:
|
|||
def test_real_file(self, data_tmpdir):
|
||||
"""Test against the real file if pdfjs was found."""
|
||||
try:
|
||||
pdfjs.get_pdfjs_res_and_path('build/pdf.js')
|
||||
pdfjs_file, file_path = pdfjs.get_pdfjs_res_and_path(
|
||||
str(pathlib.Path("build") / pdfjs.get_pdfjs_basename())
|
||||
)
|
||||
except pdfjs.PDFJSNotFound:
|
||||
pytest.skip("No pdfjs found")
|
||||
ver = version._pdfjs_version()
|
||||
|
|
|
|||
Loading…
Reference in New Issue