Migrate spell tests to unittests

This commit is contained in:
Florian Bruhin 2018-02-28 08:08:23 +01:00
parent 824825e67d
commit f3aaa1084a
3 changed files with 39 additions and 37 deletions

View File

@ -118,27 +118,6 @@ def _get_backend_tag(tag):
return pytest_marks[name](desc) return pytest_marks[name](desc)
def _get_dictionary_tag(tag):
"""Handle tags like must_have_dict=en-US for BDD tests."""
dict_re = re.compile(r"""
(?P<event>must_have_dict|cannot_have_dict)=(?P<dict>[a-z]{2}-[A-Z]{2})
""", re.VERBOSE)
match = dict_re.fullmatch(tag)
if not match:
return None
event = match.group('event')
dictionary = match.group('dict')
has_dict = spell.local_filename(dictionary) is not None
if event == 'must_have_dict':
return pytest.mark.skipif(not has_dict, reason=tag)
elif event == 'cannot_have_dict':
return pytest.mark.skipif(has_dict, reason=tag)
else:
return None
if not getattr(sys, 'frozen', False): if not getattr(sys, 'frozen', False):
def pytest_bdd_apply_tag(tag, function): def pytest_bdd_apply_tag(tag, function):
"""Handle custom tags for BDD tests. """Handle custom tags for BDD tests.
@ -146,7 +125,7 @@ if not getattr(sys, 'frozen', False):
This tries various functions, and if none knows how to handle this tag, This tries various functions, and if none knows how to handle this tag,
it returns None so it falls back to pytest-bdd's implementation. it returns None so it falls back to pytest-bdd's implementation.
""" """
funcs = [_get_version_tag, _get_backend_tag, _get_dictionary_tag] funcs = [_get_version_tag, _get_backend_tag]
for func in funcs: for func in funcs:
mark = func(tag) mark = func(tag)
if mark is not None: if mark is not None:

View File

@ -569,15 +569,3 @@ Feature: Various utility commands.
When I set up "simple" as block lists When I set up "simple" as block lists
And I run :adblock-update And I run :adblock-update
Then the message "adblock: Read 1 hosts from 1 sources." should be shown Then the message "adblock: Read 1 hosts from 1 sources." should be shown
## Spellcheck
@qtwebkit_skip @qt>=5.8 @cannot_have_dict=af-ZA
Scenario: Set valid but not installed language
When I run :set spellcheck.languages ['af-ZA']
Then the warning "Language af-ZA is not installed *" should be shown
@qtwebkit_skip @qt>=5.8 @must_have_dict=en-US
Scenario: Set valid and installed language
When I run :set spellcheck.languages ["en-US"]
Then the option spellcheck.languages should be set to ["en-US"]

View File

@ -17,16 +17,22 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>. # along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
import types
import logging
import pytest import pytest
pytest.importorskip('PyQt5.QtWebEngineWidgets') pytest.importorskip('PyQt5.QtWebEngineWidgets')
from qutebrowser.browser.webengine import webenginesettings from qutebrowser.browser.webengine import webenginesettings
from qutebrowser.utils import usertypes, qtutils
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def init_profiles(qapp, config_stub, cache_tmpdir, data_tmpdir): def init(qapp, config_stub, cache_tmpdir, data_tmpdir):
webenginesettings._init_profiles() init_args = types.SimpleNamespace(enable_webengine_inspector=False)
webenginesettings.init(init_args)
config_stub.changed.disconnect(webenginesettings._update_settings)
def test_big_cache_size(config_stub): def test_big_cache_size(config_stub):
@ -37,3 +43,32 @@ def test_big_cache_size(config_stub):
webenginesettings._set_http_cache_size(profile) webenginesettings._set_http_cache_size(profile)
assert profile.httpCacheMaximumSize() == 2 ** 31 - 1 assert profile.httpCacheMaximumSize() == 2 ** 31 - 1
@pytest.mark.skipif(
not qtutils.version_check('5.8'), reason="Needs Qt 5.8 or newer")
def test_non_existing_dict(config_stub, monkeypatch, message_mock, caplog):
monkeypatch.setattr(webenginesettings.spell, 'local_filename',
lambda _code: None)
config_stub.val.spellcheck.languages = ['af-ZA']
with caplog.at_level(logging.WARNING):
webenginesettings._update_settings('spellcheck.languages')
msg = message_mock.getmsg(usertypes.MessageLevel.warning)
expected = ("Language af-ZA is not installed - see scripts/dictcli.py in "
"qutebrowser's sources")
assert msg.text == expected
@pytest.mark.skipif(
not qtutils.version_check('5.8'), reason="Needs Qt 5.8 or newer")
def test_existing_dict(config_stub, monkeypatch):
monkeypatch.setattr(webenginesettings.spell, 'local_filename',
lambda _code: 'en-US-8-0')
config_stub.val.spellcheck.languages = ['en-US']
webenginesettings._update_settings('spellcheck.languages')
for profile in [webenginesettings.default_profile,
webenginesettings.private_profile]:
assert profile.isSpellCheckEnabled()
assert profile.spellCheckLanguages() == ['en-US-8-0']