From 8be433f5f6830f91889a49464dd47ed8c7e01239 Mon Sep 17 00:00:00 2001 From: Alexander Cogneau Date: Tue, 11 Aug 2015 09:17:46 +0200 Subject: [PATCH] Add tests: - sum of column widths equals 100 - column widths tuple has 3 elements --- qutebrowser/completion/models/configmodel.py | 12 ++--- tests/completion/test_column_widths.py | 51 ++++++++++++++++++++ 2 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 tests/completion/test_column_widths.py diff --git a/qutebrowser/completion/models/configmodel.py b/qutebrowser/completion/models/configmodel.py index 734b68e90..0c45d817b 100644 --- a/qutebrowser/completion/models/configmodel.py +++ b/qutebrowser/completion/models/configmodel.py @@ -28,12 +28,12 @@ from qutebrowser.completion.models import base class SettingSectionCompletionModel(base.BaseCompletionModel): - COLUMN_WIDTHS = (20, 70, 10) - """A CompletionModel filled with settings sections.""" # pylint: disable=abstract-method + COLUMN_WIDTHS = (20, 70, 10) + def __init__(self, parent=None): super().__init__(parent) cat = self.new_category("Sections") @@ -44,8 +44,6 @@ class SettingSectionCompletionModel(base.BaseCompletionModel): class SettingOptionCompletionModel(base.BaseCompletionModel): - COLUMN_WIDTHS = (20, 70, 10) - """A CompletionModel filled with settings and their descriptions. Attributes: @@ -55,6 +53,8 @@ class SettingOptionCompletionModel(base.BaseCompletionModel): # pylint: disable=abstract-method + COLUMN_WIDTHS = (20, 70, 10) + def __init__(self, section, parent=None): super().__init__(parent) cat = self.new_category(section) @@ -99,8 +99,6 @@ class SettingOptionCompletionModel(base.BaseCompletionModel): class SettingValueCompletionModel(base.BaseCompletionModel): - COLUMN_WIDTHS = (20, 70, 10) - """A CompletionModel filled with setting values. Attributes: @@ -110,6 +108,8 @@ class SettingValueCompletionModel(base.BaseCompletionModel): # pylint: disable=abstract-method + COLUMN_WIDTHS = (20, 70, 10) + def __init__(self, section, option, parent=None): super().__init__(parent) self._section = section diff --git a/tests/completion/test_column_widths.py b/tests/completion/test_column_widths.py new file mode 100644 index 000000000..d67bd2247 --- /dev/null +++ b/tests/completion/test_column_widths.py @@ -0,0 +1,51 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2015 Alexander Cogneau +# +# 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 . + +"""Tests for qutebrowser.completion.models column widths""" + +from qutebrowser.completion.models.base import BaseCompletionModel +from qutebrowser.completion.models.configmodel import ( + SettingOptionCompletionModel, SettingSectionCompletionModel, + SettingValueCompletionModel) +from qutebrowser.completion.models.miscmodels import ( + CommandCompletionModel, HelpCompletionModel, QuickmarkCompletionModel, + BookmarkCompletionModel, SessionCompletionModel) +from qutebrowser.completion.models.urlmodel import UrlCompletionModel + + +class TestColumnWidths: + + """Tests for the column widths of the completion models""" + + CLASSES = [BaseCompletionModel, SettingOptionCompletionModel, + SettingOptionCompletionModel, SettingSectionCompletionModel, + SettingValueCompletionModel, CommandCompletionModel, + HelpCompletionModel, QuickmarkCompletionModel, + BookmarkCompletionModel, SessionCompletionModel, + UrlCompletionModel] + + def test_list_size(self): + """Test if there are 3 items in the COLUMN_WIDTHS property""" + for model in self.CLASSES: + assert model.COLUMN_WIDTHS.__len__() == 3 + + def test_column_width_sum(self): + """Test if the sum of the widths asserts to 100""" + for model in self.CLASSES: + assert sum(model.COLUMN_WIDTHS) == 100