Review fixes

This commit is contained in:
Michal Siedlaczek 2017-10-04 09:22:35 -04:00
parent 932e7a9ab9
commit 6a486058c5
10 changed files with 36 additions and 68 deletions

View File

@ -38,7 +38,6 @@ def installed_file(code):
if the dictionary is not installed. if the dictionary is not installed.
""" """
pathname = os.path.join(dictionary_dir(), '{}*.bdic'.format(code)) pathname = os.path.join(dictionary_dir(), '{}*.bdic'.format(code))
print(pathname)
matching_dicts = glob.glob(pathname) matching_dicts = glob.glob(pathname)
if matching_dicts: if matching_dicts:
with_extension = os.path.basename(matching_dicts[0]) with_extension = os.path.basename(matching_dicts[0])

View File

@ -27,9 +27,9 @@ Module attributes:
constants. constants.
""" """
import os
import ctypes import ctypes
import ctypes.util import ctypes.util
import os
from PyQt5.QtGui import QFont from PyQt5.QtGui import QFont
from PyQt5.QtWebEngineWidgets import (QWebEngineSettings, QWebEngineProfile, from PyQt5.QtWebEngineWidgets import (QWebEngineSettings, QWebEngineProfile,

View File

@ -1034,7 +1034,7 @@ spellcheck.languages:
- uk-UA: Ukrainian (Ukraine) - uk-UA: Ukrainian (Ukraine)
- vi-VN: Vietnamese (Viet Nam) - vi-VN: Vietnamese (Viet Nam)
none_ok: true none_ok: true
default: default: []
desc: >- desc: >-
Spell checking languages. Spell checking languages.

View File

@ -172,6 +172,9 @@ PERFECT_FILES = [
('tests/unit/completion/test_listcategory.py', ('tests/unit/completion/test_listcategory.py',
'completion/models/listcategory.py'), 'completion/models/listcategory.py'),
('tests/unit/browser/webengine/test_spell.py',
'browser/webengine/spell.py'),
] ]

View File

@ -29,6 +29,11 @@ import json
import os import os
import sys 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(): def get_latest_pdfjs_url():
"""Get the URL of the latest pdf.js prebuilt package. """Get the URL of the latest pdf.js prebuilt package.
@ -113,12 +118,9 @@ def update_ace():
def test_dicts(): def test_dicts():
"""Test available dictionaries.""" """Test available dictionaries."""
sys.path.insert(0, os.curdir)
from scripts import install_dict
from qutebrowser.config import configdata
configdata.init() configdata.init()
for lang in install_dict.available_languages(): 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) lang_url = urllib.parse.urljoin(install_dict.API_URL, lang.file_path)
request = urllib.request.Request(lang_url, method='HEAD') request = urllib.request.Request(lang_url, method='HEAD')
response = urllib.request.urlopen(request) response = urllib.request.urlopen(request)
@ -129,7 +131,7 @@ def test_dicts():
def run(ace=False, pdfjs=True, fancy_dmg=False, pdfjs_version=None, def run(ace=False, pdfjs=True, fancy_dmg=False, pdfjs_version=None,
dicts=None): dicts=False):
"""Update components based on the given arguments.""" """Update components based on the given arguments."""
if pdfjs: if pdfjs:
update_pdfjs(pdfjs_version) update_pdfjs(pdfjs_version)

View File

@ -40,6 +40,14 @@ from qutebrowser.config import configdata
API_URL = 'https://chromium.googlesource.com/chromium/deps/hunspell_dictionaries.git/+/master/' 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 @attr.s
class Language: class Language:
"""Dictionary language specs.""" """Dictionary language specs."""
@ -68,7 +76,7 @@ def get_argparser():
def print_list(languages): def print_list(languages):
for lang in languages: for lang in languages:
print('{1}\t{0}'.format(lang.name, lang.code)) print(lang.code, lang.name, sep='\t')
def valid_languages(): def valid_languages():
@ -118,9 +126,6 @@ def filter_languages(languages, selected):
Args: Args:
languages: a list of languages to filter languages: a list of languages to filter
selected: a list of keys to select 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 = [] filtered_languages = []
for language in languages: for language in languages:
@ -128,8 +133,7 @@ def filter_languages(languages, selected):
filtered_languages.append(language) filtered_languages.append(language)
selected.remove(language.code) selected.remove(language.code)
if selected: if selected:
unknown = ', '.join(selected) raise InvalidLanguageError(selected)
raise ValueError('unknown languages found: {}'.format(unknown))
return filtered_languages return filtered_languages
@ -170,7 +174,7 @@ def main():
else: else:
try: try:
install(filter_languages(languages, args.languages)) install(filter_languages(languages, args.languages))
except ValueError as e: except InvalidLanguageError as e:
print(e) print(e)

View File

@ -526,3 +526,15 @@ Feature: Various utility commands.
And I wait for "Renderer process was killed" in the log And I wait for "Renderer process was killed" in the log
And I open data/numbers/3.txt And I open data/numbers/3.txt
Then no crash should happen 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"]

View File

@ -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"]

View File

@ -1,22 +0,0 @@
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2017 Michał Siedlaczek <michal.siedlaczek@gmail.com>
#
# 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 <http://www.gnu.org/licenses/>.
import pytest_bdd as bdd
bdd.scenarios('spell.feature')

View File

@ -56,7 +56,7 @@ def test_filter_languages():
LANGUAGE_LIST, ['pl-PL', 'en-US']) LANGUAGE_LIST, ['pl-PL', 'en-US'])
assert filtered_langs == [ENGLISH, POLISH] 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']) install_dict.filter_languages(LANGUAGE_LIST, ['pl-PL', 'en-GB'])