Exemple #1
0
def test_is_available(available, mocker):
    mock = mocker.patch.object(pdfjs, 'get_pdfjs_res', autospec=True)
    if available:
        mock.return_value = b'foo'
    else:
        mock.side_effect = pdfjs.PDFJSNotFound('build/pdf.js')

    assert pdfjs.is_available() == available
Exemple #2
0
def test_is_available(available, mocker):
    mock = mocker.patch.object(pdfjs, 'get_pdfjs_res', autospec=True)
    if available:
        mock.return_value = b'foo'
    else:
        mock.side_effect = pdfjs.PDFJSNotFound('build/pdf.js')

    assert pdfjs.is_available() == available
Exemple #3
0
def test_generate_pdfjs_page(available, snippet, monkeypatch):
    if available == 'force':
        monkeypatch.setattr(pdfjs, 'is_available', lambda: True)
        monkeypatch.setattr(pdfjs, 'get_pdfjs_res',
                            lambda filename: b'fake PDF.js')
    elif available:
        if not pdfjs.is_available():
            pytest.skip("PDF.js unavailable")
        monkeypatch.setattr(pdfjs, 'is_available', lambda: True)
    else:
        monkeypatch.setattr(pdfjs, 'is_available', lambda: False)

    content = pdfjs.generate_pdfjs_page('example.pdf', QUrl())
    print(content)
    assert snippet in content
Exemple #4
0
def test_generate_pdfjs_page(available, snippet, monkeypatch):
    if available == 'force':
        monkeypatch.setattr(pdfjs, 'is_available', lambda: True)
        monkeypatch.setattr(pdfjs, 'get_pdfjs_res',
                            lambda filename: b'fake PDF.js')
    elif available:
        if not pdfjs.is_available():
            pytest.skip("PDF.js unavailable")
        monkeypatch.setattr(pdfjs, 'is_available', lambda: True)
    else:
        monkeypatch.setattr(pdfjs, 'is_available', lambda: False)

    content = pdfjs.generate_pdfjs_page('example.pdf', QUrl())
    print(content)
    assert snippet in content
Exemple #5
0
def pdfjs_available():
    if not pdfjs.is_available():
        pytest.skip("No pdfjs installation found.")
Exemple #6
0
def pdfjs_available():
    if not pdfjs.is_available():
        pytest.skip("No pdfjs installation found.")
Exemple #7
0
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with qutebrowser.  If not, see <http://www.gnu.org/licenses/>.

import pytest
from PyQt5.QtCore import QUrl

from qutebrowser.browser import pdfjs
from qutebrowser.utils import usertypes, utils


@pytest.mark.parametrize('available, snippet', [
    pytest.param(True,
                 '<title>PDF.js viewer</title>',
                 marks=pytest.mark.skipif(not pdfjs.is_available(),
                                          reason='PDF.js unavailable')),
    (False, '<h1>No pdf.js installation found</h1>'),
    ('force', 'fake PDF.js'),
])
def test_generate_pdfjs_page(available, snippet, monkeypatch):
    if available == 'force':
        monkeypatch.setattr(pdfjs, 'is_available', lambda: True)
        monkeypatch.setattr(pdfjs, 'get_pdfjs_res',
                            lambda filename: b'fake PDF.js')
    else:
        monkeypatch.setattr(pdfjs, 'is_available', lambda: available)

    content = pdfjs.generate_pdfjs_page('example.pdf', QUrl())
    print(content)
    assert snippet in content