diff --git a/qutebrowser/completion/models/completionmodel.py b/qutebrowser/completion/models/completionmodel.py index 778e0cac9..3e48076e5 100644 --- a/qutebrowser/completion/models/completionmodel.py +++ b/qutebrowser/completion/models/completionmodel.py @@ -59,6 +59,7 @@ class CompletionModel(QAbstractItemModel): def add_category(self, cat): """Add a completion category to the model.""" self._categories.append(cat) + cat.layoutAboutToBeChanged.connect(self.layoutAboutToBeChanged) cat.layoutChanged.connect(self.layoutChanged) def data(self, index, role=Qt.DisplayRole): diff --git a/qutebrowser/completion/models/sqlcategory.py b/qutebrowser/completion/models/sqlcategory.py index 4819e940b..2664edbfe 100644 --- a/qutebrowser/completion/models/sqlcategory.py +++ b/qutebrowser/completion/models/sqlcategory.py @@ -59,6 +59,8 @@ class SqlCategory(QSqlQueryModel): if sort_by: assert sort_order in ['asc', 'desc'], sort_order querystr += ' order by {} {}'.format(sort_by, sort_order) + else: + assert sort_order is None, sort_order self._query = sql.Query(querystr, forward_only=False) diff --git a/qutebrowser/misc/sql.py b/qutebrowser/misc/sql.py index 4ae37f01f..a288df475 100644 --- a/qutebrowser/misc/sql.py +++ b/qutebrowser/misc/sql.py @@ -38,7 +38,8 @@ def init(db_path): """Initialize the SQL database connection.""" database = QSqlDatabase.addDatabase('QSQLITE') if not database.isValid(): - raise SqlException('Failed to add database. Is sqlite installed?') + raise SqlException('Failed to add database. ' + 'Are sqlite and Qt sqlite support installed?') database.setDatabaseName(db_path) if not database.open(): raise SqlException("Failed to open sqlite database at {}: {}" diff --git a/tests/unit/completion/test_completionmodel.py b/tests/unit/completion/test_completionmodel.py index ce0fe3765..4d1d3f123 100644 --- a/tests/unit/completion/test_completionmodel.py +++ b/tests/unit/completion/test_completionmodel.py @@ -36,7 +36,7 @@ def test_first_last_item(counts): """Test that first() and last() index to the first and last items.""" model = completionmodel.CompletionModel() for c in counts: - cat = mock.Mock(spec=['layoutChanged']) + cat = mock.Mock(spec=['layoutChanged', 'layoutAboutToBeChanged']) cat.rowCount = mock.Mock(return_value=c, spec=[]) model.add_category(cat) data = [i for i, rowCount in enumerate(counts) if rowCount > 0] @@ -60,7 +60,8 @@ def test_first_last_item(counts): def test_count(counts): model = completionmodel.CompletionModel() for c in counts: - cat = mock.Mock(spec=['rowCount', 'layoutChanged']) + cat = mock.Mock(spec=['rowCount', 'layoutChanged', + 'layoutAboutToBeChanged']) cat.rowCount = mock.Mock(return_value=c, spec=[]) model.add_category(cat) assert model.count() == sum(counts) @@ -70,7 +71,9 @@ def test_count(counts): def test_set_pattern(pat): """Validate the filtering and sorting results of set_pattern.""" model = completionmodel.CompletionModel() - cats = [mock.Mock(spec=['set_pattern', 'layoutChanged']) for _ in range(3)] + cats = [mock.Mock(spec=['set_pattern', 'layoutChanged', + 'layoutAboutToBeChanged']) + for _ in range(3)] for c in cats: c.set_pattern = mock.Mock(spec=[]) model.add_category(c) diff --git a/tests/unit/completion/test_sqlcategory.py b/tests/unit/completion/test_sqlcategory.py index 851bad257..a9321e33e 100644 --- a/tests/unit/completion/test_sqlcategory.py +++ b/tests/unit/completion/test_sqlcategory.py @@ -32,7 +32,7 @@ pytestmark = pytest.mark.usefixtures('init_sql') @pytest.mark.parametrize('sort_by, sort_order, data, expected', [ - (None, 'asc', + (None, None, [('B', 'C', 'D'), ('A', 'F', 'C'), ('C', 'A', 'G')], [('B', 'C', 'D'), ('A', 'F', 'C'), ('C', 'A', 'G')]),