Skip end2end spell tests if a dictionary is/isn't installed

This commit is contained in:
Michal Siedlaczek 2017-09-21 16:31:37 -04:00
parent 396f82d474
commit 2150154350
3 changed files with 36 additions and 12 deletions

View File

@ -29,6 +29,8 @@ import pstats
import os.path
import operator
from qutebrowser.browser.webengine.spell import get_installed_languages
import pytest
from PyQt5.QtCore import PYQT_VERSION
@ -116,6 +118,28 @@ def _get_backend_tag(tag):
return pytest_marks[name](desc)
def _get_dictionary_tag(tag):
"""Handle tags like must_have_dict=en-US for BDD tests."""
version_re = re.compile(r"""
(?P<event>must_have_dict|cannot_have_dict)=(?P<dict>[a-z]{2}-[A-Z]{2})
""", re.VERBOSE)
match = version_re.match(tag)
if not match:
#return pytest.mark.skip
return None
event = match.group('event')
dict = match.group('dict')
has_dict = dict in [lang.code for lang in get_installed_languages()]
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):
def pytest_bdd_apply_tag(tag, function):
"""Handle custom tags for BDD tests.
@ -123,7 +147,7 @@ if not getattr(sys, 'frozen', False):
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.
"""
funcs = [_get_version_tag, _get_backend_tag]
funcs = [_get_version_tag, _get_backend_tag, _get_dictionary_tag]
for func in funcs:
mark = func(tag)
if mark is not None:

View File

@ -8,31 +8,31 @@ Feature: Setting spell checking for QtWebEngine
@qtwebkit_skip @qt>=5.8
Scenario: Turn spell check on
Given spell check is off
When I run :set ui spell true
Then ui -> spell should be true
When I run :set spell true
Then the option spell should be set to true
Then spell check is on
@qtwebkit_skip @qt>=5.8
Scenario: Turn spell check off
Given spell check is on
When I run :set ui spell false
Then ui -> spell should be false
When I run :set spell false
Then the option spell should be set to false
Then spell check is off
@qtwebkit_skip @qt>=5.8
Scenario: Set an invalid language
When I run :set ui spell-languages invalid-language (invalid command)
When I run :set spell_languages ['invalid-language'] (invalid command)
Then the error "set: Invalid value 'invalid-language' *" should be shown
Then actual spell check languages are []
@qtwebkit_skip @qt>=5.8
@qtwebkit_skip @qt>=5.8 @cannot_have_dict=af-ZA
Scenario: Set valid but not installed language
When I run :set ui spell-languages af-ZA
When I run :set spell_languages ['af-ZA']
Then the warning "Language af-ZA is not installed." should be shown
Then actual spell check languages are []
@qtwebkit_skip @qt>=5.8
@qtwebkit_skip @qt>=5.8 @must_have_dict=en-US
Scenario: Set valid and installed language
When I run :set ui spell-languages en-US
Then ui -> spell-languages should be en-US
When I run :set spell_languages ["en-US"]
Then the option spell_languages should be set to ["en-US"]
Then actual spell check languages are ['en-US-7-1']

View File

@ -87,7 +87,7 @@ def test_install(tmpdir, mocker):
assert sorted(installed_files) == sorted(expected_files)
# TODO: move to update_3rdparty.py
# TODO: move somewhere to be checked before a release
#def test_available_langs():
# for lang in spell.get_available_languages():
# lang_url = urljoin(spell.repository_url, lang.file)