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 os.path
import operator import operator
from qutebrowser.browser.webengine.spell import get_installed_languages
import pytest import pytest
from PyQt5.QtCore import PYQT_VERSION from PyQt5.QtCore import PYQT_VERSION
@ -116,6 +118,28 @@ 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."""
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): 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.
@ -123,7 +147,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] funcs = [_get_version_tag, _get_backend_tag, _get_dictionary_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

@ -8,31 +8,31 @@ Feature: Setting spell checking for QtWebEngine
@qtwebkit_skip @qt>=5.8 @qtwebkit_skip @qt>=5.8
Scenario: Turn spell check on Scenario: Turn spell check on
Given spell check is off Given spell check is off
When I run :set ui spell true When I run :set spell true
Then ui -> spell should be true Then the option spell should be set to true
Then spell check is on Then spell check is on
@qtwebkit_skip @qt>=5.8 @qtwebkit_skip @qt>=5.8
Scenario: Turn spell check off Scenario: Turn spell check off
Given spell check is on Given spell check is on
When I run :set ui spell false When I run :set spell false
Then ui -> spell should be false Then the option spell should be set to false
Then spell check is off Then spell check is off
@qtwebkit_skip @qt>=5.8 @qtwebkit_skip @qt>=5.8
Scenario: Set an invalid language 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 the error "set: Invalid value 'invalid-language' *" should be shown
Then actual spell check languages are [] 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 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 the warning "Language af-ZA is not installed." should be shown
Then actual spell check languages are [] 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 Scenario: Set valid and installed language
When I run :set ui spell-languages en-US When I run :set spell_languages ["en-US"]
Then ui -> spell-languages should be en-US Then the option spell_languages should be set to ["en-US"]
Then actual spell check languages are ['en-US-7-1'] 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) 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(): #def test_available_langs():
# for lang in spell.get_available_languages(): # for lang in spell.get_available_languages():
# lang_url = urljoin(spell.repository_url, lang.file) # lang_url = urljoin(spell.repository_url, lang.file)