diff --git a/qutebrowser/browser/webengine/spell.py b/qutebrowser/browser/webengine/spell.py index aaf346a79..a915b1d52 100644 --- a/qutebrowser/browser/webengine/spell.py +++ b/qutebrowser/browser/webengine/spell.py @@ -38,7 +38,6 @@ def installed_file(code): if the dictionary is not installed. """ pathname = os.path.join(dictionary_dir(), '{}*.bdic'.format(code)) - print(pathname) matching_dicts = glob.glob(pathname) if matching_dicts: with_extension = os.path.basename(matching_dicts[0]) diff --git a/qutebrowser/browser/webengine/webenginesettings.py b/qutebrowser/browser/webengine/webenginesettings.py index 13743e0c8..c2ae7a018 100644 --- a/qutebrowser/browser/webengine/webenginesettings.py +++ b/qutebrowser/browser/webengine/webenginesettings.py @@ -27,9 +27,9 @@ Module attributes: constants. """ +import os import ctypes import ctypes.util -import os from PyQt5.QtGui import QFont from PyQt5.QtWebEngineWidgets import (QWebEngineSettings, QWebEngineProfile, diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index efc1d2cd4..d051b3e8a 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -1034,7 +1034,7 @@ spellcheck.languages: - uk-UA: Ukrainian (Ukraine) - vi-VN: Vietnamese (Viet Nam) none_ok: true - default: + default: [] desc: >- Spell checking languages. diff --git a/scripts/dev/check_coverage.py b/scripts/dev/check_coverage.py index aa5072536..e60ee78fd 100644 --- a/scripts/dev/check_coverage.py +++ b/scripts/dev/check_coverage.py @@ -172,6 +172,9 @@ PERFECT_FILES = [ ('tests/unit/completion/test_listcategory.py', 'completion/models/listcategory.py'), + ('tests/unit/browser/webengine/test_spell.py', + 'browser/webengine/spell.py'), + ] diff --git a/scripts/dev/update_3rdparty.py b/scripts/dev/update_3rdparty.py index 2dd65273a..a72e9368e 100755 --- a/scripts/dev/update_3rdparty.py +++ b/scripts/dev/update_3rdparty.py @@ -29,6 +29,11 @@ import json import os import sys +sys.path.insert( + 0, os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) +from scripts import install_dict +from qutebrowser.config import configdata + def get_latest_pdfjs_url(): """Get the URL of the latest pdf.js prebuilt package. @@ -113,12 +118,9 @@ def update_ace(): def test_dicts(): """Test available dictionaries.""" - sys.path.insert(0, os.curdir) - from scripts import install_dict - from qutebrowser.config import configdata configdata.init() for lang in install_dict.available_languages(): - sys.stdout.write('Testing dictionary {}... '.format(lang.code)) + print('Testing dictionary {}... '.format(lang.code), end='') lang_url = urllib.parse.urljoin(install_dict.API_URL, lang.file_path) request = urllib.request.Request(lang_url, method='HEAD') response = urllib.request.urlopen(request) @@ -129,7 +131,7 @@ def test_dicts(): def run(ace=False, pdfjs=True, fancy_dmg=False, pdfjs_version=None, - dicts=None): + dicts=False): """Update components based on the given arguments.""" if pdfjs: update_pdfjs(pdfjs_version) diff --git a/scripts/install_dict.py b/scripts/install_dict.py index a5fdabc80..13839d150 100755 --- a/scripts/install_dict.py +++ b/scripts/install_dict.py @@ -40,6 +40,14 @@ from qutebrowser.config import configdata API_URL = 'https://chromium.googlesource.com/chromium/deps/hunspell_dictionaries.git/+/master/' +class InvalidLanguageError(Exception): + """Raised when requested invalid languages.""" + + def __init__(self, invalid_langs): + msg = 'invalid languages: {}'.format(', '.join(invalid_langs)) + super(InvalidLanguageError, self).__init__(msg) + + @attr.s class Language: """Dictionary language specs.""" @@ -68,7 +76,7 @@ def get_argparser(): def print_list(languages): for lang in languages: - print('{1}\t{0}'.format(lang.name, lang.code)) + print(lang.code, lang.name, sep='\t') def valid_languages(): @@ -118,9 +126,6 @@ def filter_languages(languages, selected): Args: languages: a list of languages to filter selected: a list of keys to select - by: a function returning the selection key (code by default) - fail_on_unknown: whether to raise an error if there is an unknown - key in selected """ filtered_languages = [] for language in languages: @@ -128,8 +133,7 @@ def filter_languages(languages, selected): filtered_languages.append(language) selected.remove(language.code) if selected: - unknown = ', '.join(selected) - raise ValueError('unknown languages found: {}'.format(unknown)) + raise InvalidLanguageError(selected) return filtered_languages @@ -170,7 +174,7 @@ def main(): else: try: install(filter_languages(languages, args.languages)) - except ValueError as e: + except InvalidLanguageError as e: print(e) diff --git a/tests/end2end/features/misc.feature b/tests/end2end/features/misc.feature index 3d23033f5..110401048 100644 --- a/tests/end2end/features/misc.feature +++ b/tests/end2end/features/misc.feature @@ -526,3 +526,15 @@ Feature: Various utility commands. And I wait for "Renderer process was killed" in the log And I open data/numbers/3.txt Then no crash should happen + + ## 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"] diff --git a/tests/end2end/features/spell.feature b/tests/end2end/features/spell.feature deleted file mode 100644 index 9465951c9..000000000 --- a/tests/end2end/features/spell.feature +++ /dev/null @@ -1,30 +0,0 @@ -# vim: ft=cucumber fileencoding=utf-8 sts=4 sw=4 et: - -Feature: Setting spell checking for QtWebEngine - - @qtwebkit_skip @qt>=5.8 - Scenario: Turn spell check on - Given I set spellcheck.enabled to false - When I run :set spellcheck.enabled true - Then the option spellcheck.enabled should be set to true - - @qtwebkit_skip @qt>=5.8 - Scenario: Turn spell check off - Given I set spellcheck.enabled to true - When I run :set spellcheck.enabled false - Then the option spellcheck.enabled should be set to false - - @qtwebkit_skip @qt>=5.8 - Scenario: Set an invalid language - When I run :set spellcheck.languages ['invalid-language'] (invalid command) - Then the error "set: Invalid value 'invalid-language' *" should be shown - - @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"] diff --git a/tests/end2end/features/test_spell_bdd.py b/tests/end2end/features/test_spell_bdd.py deleted file mode 100644 index 58c3a3da8..000000000 --- a/tests/end2end/features/test_spell_bdd.py +++ /dev/null @@ -1,22 +0,0 @@ -# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: - -# Copyright 2017 MichaƂ Siedlaczek -# -# This file is part of qutebrowser. -# -# qutebrowser is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# qutebrowser is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# 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 . - -import pytest_bdd as bdd - -bdd.scenarios('spell.feature') diff --git a/tests/unit/scripts/test_install_dict.py b/tests/unit/scripts/test_install_dict.py index da96aacdd..4493d9e9a 100644 --- a/tests/unit/scripts/test_install_dict.py +++ b/tests/unit/scripts/test_install_dict.py @@ -56,7 +56,7 @@ def test_filter_languages(): LANGUAGE_LIST, ['pl-PL', 'en-US']) assert filtered_langs == [ENGLISH, POLISH] - with pytest.raises(ValueError): + with pytest.raises(install_dict.InvalidLanguageError): install_dict.filter_languages(LANGUAGE_LIST, ['pl-PL', 'en-GB'])