Skip to content

Commit

Permalink
Fix test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
elshize committed Mar 28, 2018
1 parent f9e702b commit 7c1de99
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/unit/browser/webengine/test_spell.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import logging

from PyQt5.QtCore import QLibraryInfo
from qutebrowser.browser.webengine import spell
from qutebrowser.utils import usertypes

Expand All @@ -33,6 +34,11 @@ def test_version(message_mock, caplog):
assert msg.text == expected


def test_dictionary_dir(monkeypatch):
monkeypatch.setattr(QLibraryInfo, 'location', lambda _: 'datapath')
assert spell.dictionary_dir() == 'datapath/qtwebengine_dictionaries'


def test_local_filename_dictionary_does_not_exist(tmpdir, monkeypatch):
monkeypatch.setattr(
spell, 'dictionary_dir', lambda: '/some-non-existing-dir')
Expand All @@ -44,9 +50,24 @@ def test_local_filename_dictionary_not_installed(tmpdir, monkeypatch):
assert not spell.local_filename('en-US')


def test_local_filename_dictionary_not_installed_with_malformed(tmpdir, monkeypatch, caplog):
monkeypatch.setattr(spell, 'dictionary_dir', lambda: str(tmpdir))
(tmpdir / 'en-US.bdic').ensure()
with caplog.at_level(logging.WARNING):
assert not spell.local_filename('en-US')


def test_local_filename_dictionary_installed(tmpdir, monkeypatch):
monkeypatch.setattr(spell, 'dictionary_dir', lambda: str(tmpdir))
for lang_file in ['en-US-11-0.bdic', 'en-US-7-1.bdic', 'pl-PL-3-0.bdic']:
(tmpdir / lang_file).ensure()
assert spell.local_filename('en-US') == 'en-US-11-0'
assert spell.local_filename('pl-PL') == 'pl-PL-3-0'


def test_local_filename_dictionary_installed_with_malformed(tmpdir, monkeypatch, caplog):
monkeypatch.setattr(spell, 'dictionary_dir', lambda: str(tmpdir))
for lang_file in ['en-US-11-0.bdic', 'en-US-7-1.bdic', 'en-US.bdic']:
(tmpdir / lang_file).ensure()
with caplog.at_level(logging.WARNING):
assert spell.local_filename('en-US') == 'en-US-11-0'

0 comments on commit 7c1de99

Please sign in to comment.