Fix pylint/coverage errors.
Ensure 100% coverage for sqlcategory and history, and fix some linter errors
This commit is contained in:
parent
f06880c6e2
commit
6ac940fa32
@ -21,7 +21,6 @@
|
||||
|
||||
import re
|
||||
|
||||
from PyQt5.QtCore import QModelIndex
|
||||
from PyQt5.QtSql import QSqlQueryModel
|
||||
|
||||
from qutebrowser.misc import sql
|
||||
|
@ -22,7 +22,7 @@
|
||||
from qutebrowser.completion.models import (completionmodel, listcategory,
|
||||
sqlcategory)
|
||||
from qutebrowser.config import config
|
||||
from qutebrowser.utils import qtutils, log, objreg
|
||||
from qutebrowser.utils import log, objreg
|
||||
|
||||
|
||||
_URLCOL = 0
|
||||
|
@ -125,6 +125,17 @@ def test_clear_force(qtbot, tmpdir, hist):
|
||||
assert not len(hist)
|
||||
|
||||
|
||||
def test_delete_url(hist):
|
||||
hist.add_url(QUrl('http://example.com/'), atime=0)
|
||||
hist.add_url(QUrl('http://example.com/1'), atime=0)
|
||||
hist.add_url(QUrl('http://example.com/2'), atime=0)
|
||||
|
||||
before = set(hist)
|
||||
hist.delete_url(QUrl('http://example.com/1'))
|
||||
diff = before.difference(set(hist))
|
||||
assert diff == set([('http://example.com/1', '', 0, False)])
|
||||
|
||||
|
||||
@pytest.mark.parametrize('url, atime, title, redirect', [
|
||||
('http://www.example.com', 12346, 'the title', False),
|
||||
('http://www.example.com', 12346, 'the title', True)
|
||||
|
@ -233,4 +233,4 @@ def test_completion_item_del_no_selection(completionview):
|
||||
completionview.set_model(model)
|
||||
with pytest.raises(cmdexc.CommandError, match='No item selected!'):
|
||||
completionview.completion_item_del()
|
||||
func.assert_not_called
|
||||
func.assert_not_called()
|
||||
|
@ -20,16 +20,13 @@
|
||||
"""Tests for completion models."""
|
||||
|
||||
import collections
|
||||
import unittest.mock
|
||||
from datetime import datetime
|
||||
|
||||
import pytest
|
||||
from PyQt5.QtCore import QUrl
|
||||
from PyQt5.QtWidgets import QTreeView
|
||||
|
||||
from qutebrowser.completion.models import miscmodels, urlmodel, configmodel
|
||||
from qutebrowser.config import sections, value
|
||||
from qutebrowser.utils import objreg
|
||||
from qutebrowser.misc import sql
|
||||
|
||||
|
||||
|
@ -19,11 +19,14 @@
|
||||
|
||||
"""Test SQL-based completions."""
|
||||
|
||||
import unittest.mock
|
||||
|
||||
import pytest
|
||||
|
||||
from helpers import utils
|
||||
from qutebrowser.misc import sql
|
||||
from qutebrowser.completion.models import sqlcategory
|
||||
from qutebrowser.commands import cmdexc
|
||||
|
||||
|
||||
pytestmark = pytest.mark.usefixtures('init_sql')
|
||||
@ -151,3 +154,24 @@ def test_group():
|
||||
select='a, max(b)', group_by='a')
|
||||
cat.set_pattern('')
|
||||
utils.validate_model(cat, [('bar', 3), ('foo', 2)])
|
||||
|
||||
|
||||
def test_delete_cur_item():
|
||||
table = sql.SqlTable('Foo', ['a', 'b'])
|
||||
table.insert({'a': 'foo', 'b': 1})
|
||||
table.insert({'a': 'bar', 'b': 2})
|
||||
func = unittest.mock.MagicMock()
|
||||
cat = sqlcategory.SqlCategory('Foo', filter_fields=['a'], delete_func=func)
|
||||
cat.set_pattern('')
|
||||
cat.delete_cur_item(cat.index(0, 0))
|
||||
func.assert_called_with(['foo', 1])
|
||||
|
||||
|
||||
def test_delete_cur_item_no_func():
|
||||
table = sql.SqlTable('Foo', ['a', 'b'])
|
||||
table.insert({'a': 'foo', 'b': 1})
|
||||
table.insert({'a': 'bar', 'b': 2})
|
||||
cat = sqlcategory.SqlCategory('Foo', filter_fields=['a'])
|
||||
cat.set_pattern('')
|
||||
with pytest.raises(cmdexc.CommandError, match='Cannot delete this item'):
|
||||
cat.delete_cur_item(cat.index(0, 0))
|
||||
|
@ -811,7 +811,6 @@ def test_chromium_version_unpatched(qapp):
|
||||
def test_version_output(git_commit, frozen, style, with_webkit,
|
||||
known_distribution, stubs, monkeypatch, init_sql):
|
||||
"""Test version.version()."""
|
||||
# pylint: disable=too-many-locals
|
||||
class FakeWebEngineProfile:
|
||||
def httpUserAgent(self):
|
||||
return 'Toaster/4.0.4 Chrome/CHROMIUMVERSION Teapot/4.1.8'
|
||||
|
Loading…
Reference in New Issue
Block a user