From a78644a19922bb48e680a11ab21765ca16081edb Mon Sep 17 00:00:00 2001 From: Clayton Craft Date: Wed, 23 Mar 2016 22:14:16 -0700 Subject: [PATCH 1/7] Implement statusbar.url test --- scripts/dev/check_coverage.py | 2 + tests/unit/mainwindow/statusbar/test_url.py | 126 ++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 tests/unit/mainwindow/statusbar/test_url.py diff --git a/scripts/dev/check_coverage.py b/scripts/dev/check_coverage.py index ff5bc01f5..18f7758b7 100644 --- a/scripts/dev/check_coverage.py +++ b/scripts/dev/check_coverage.py @@ -102,6 +102,8 @@ PERFECT_FILES = [ 'qutebrowser/mainwindow/statusbar/textbase.py'), ('tests/unit/mainwindow/statusbar/test_prompt.py', 'qutebrowser/mainwindow/statusbar/prompt.py'), + ('tests/unit/mainwindow/statusbar/test_url.py', + 'qutebrowser/mainwindow/statusbar/url.py'), ('tests/unit/config/test_configtypes.py', 'qutebrowser/config/configtypes.py'), diff --git a/tests/unit/mainwindow/statusbar/test_url.py b/tests/unit/mainwindow/statusbar/test_url.py new file mode 100644 index 000000000..15cff07b0 --- /dev/null +++ b/tests/unit/mainwindow/statusbar/test_url.py @@ -0,0 +1,126 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2014-2016 Florian Bruhin (The Compiler) +# +# 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 . + + +"""Test Statusbar url.""" + +import pytest + +from collections import namedtuple +from qutebrowser.mainwindow.statusbar.url import UrlText +from qutebrowser.utils import usertypes + + +UrlType = usertypes.enum('UrlType', ['success', 'success_https', 'error', + 'warn', 'hover', 'normal']) + + +@pytest.fixture +def tab_widget(): + """Fixture providing a fake tab widget.""" + tab = namedtuple('Tab', 'cur_url load_status') + tab.load_status = namedtuple('load_status', 'name') + tab.cur_url = namedtuple('cur_url', 'toDisplayString') + return tab + + +@pytest.fixture +def url_widget(qtbot, monkeypatch, config_stub): + """Fixture providing a Url widget.""" + config_stub.data = { + 'colors': { + 'statusbar.url.bg': 'white', + 'statusbar.url.fg': 'black', + 'statusbar.url.fg.success': 'yellow', + 'statusbar.url.fg.success.https': 'green', + 'statusbar.url.fg.error': 'red', + 'statusbar.url.fg.warn': 'orange', + 'statusbar.url.fg.hover': 'blue'}, + 'fonts': {}, + } + monkeypatch.setattr( + 'qutebrowser.mainwindow.statusbar.url.style.config', config_stub) + widget = UrlText() + qtbot.add_widget(widget) + assert not widget.isVisible() + return widget + + +@pytest.mark.parametrize('url', [ + ('http://abc123.com/this/awesome/url.html'), + ('https://supersecret.gov/nsa/files.txt'), + ('Th1$ i$ n0t @ n0rm@L uRL! P@n1c! <-->'), + (None) +]) +def test_set_url(url_widget, url): + """Test text displayed by the widget.""" + url_widget.set_url(url) + if url is not None: + assert url_widget.text() == url + else: + assert url_widget.text() == "" + + +@pytest.mark.parametrize('url, title, text', [ + ('http://abc123.com/this/awesome/url.html', 'Awesome site', 'click me!'), + ('https://supersecret.gov/nsa/files.txt', 'Secret area', None), + ('Th1$ i$ n0t @ n0rm@L uRL! P@n1c! <-->', 'Probably spam', 'definitely'), + (None, None, 'did I break?!') +]) +def test_set_hover_url(url_widget, url, title, text): + """Test text when hovering over a link.""" + url_widget.set_hover_url(url, title, text) + if url is not None: + assert url_widget.text() == url + else: + assert url_widget.text() == '' + + +@pytest.mark.parametrize('status, expected', [ + ('success', 'success'), + ('success_https', 'success_https'), + ('error', 'error'), + ('warn', 'warn') +]) +def test_on_load_status_changed(url_widget, status, expected): + """Test text when status is changed.""" + url_widget.set_url('www.example.com') + url_widget.on_load_status_changed(status) + assert url_widget._urltype.name == expected + + +@pytest.mark.parametrize('load_status, url', [ + ('success', 'http://abc123.com/this/awesome/url.html'), + ('success', 'http://reddit.com/r/linux'), + ('success_https', 'www.google.com'), + ('success_https', 'https://supersecret.gov/nsa/files.txt'), + ('warn', 'www.shadysite.org/some/path/to/a/file/that/has/issues.htm'), + ('error', 'Th1$ i$ n0t @ n0rm@L uRL! P@n1c! <-->'), + ('error', None) +]) +def test_on_tab_changed(url_widget, tab_widget, load_status, url): + tab_widget.load_status.name = load_status + tab_widget.cur_url.toDisplayString = lambda: url + url_widget.on_tab_changed(tab_widget) + if url is not None: + assert url_widget._urltype.name == load_status + assert url_widget.text() == url + else: + assert url_widget._urltype.name == 'normal' + assert url_widget.text() == '' From 4778ff6f9c96d447b0c6de50f8628f0151f82d00 Mon Sep 17 00:00:00 2001 From: Clayton Craft Date: Fri, 25 Mar 2016 15:56:39 -0700 Subject: [PATCH 2/7] Cleaned up url test and improved coveraged based on feedback --- tests/unit/mainwindow/statusbar/test_url.py | 92 ++++++++++----------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/tests/unit/mainwindow/statusbar/test_url.py b/tests/unit/mainwindow/statusbar/test_url.py index 15cff07b0..6587c6afa 100644 --- a/tests/unit/mainwindow/statusbar/test_url.py +++ b/tests/unit/mainwindow/statusbar/test_url.py @@ -1,6 +1,6 @@ # vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: -# Copyright 2014-2016 Florian Bruhin (The Compiler) +# Copyright 2016 Clayton Craft (craftyguy) # # This file is part of qutebrowser. # @@ -21,22 +21,18 @@ """Test Statusbar url.""" import pytest +import collections -from collections import namedtuple -from qutebrowser.mainwindow.statusbar.url import UrlText +from qutebrowser.browser import webview +from qutebrowser.mainwindow.statusbar import url from qutebrowser.utils import usertypes -UrlType = usertypes.enum('UrlType', ['success', 'success_https', 'error', - 'warn', 'hover', 'normal']) - - @pytest.fixture def tab_widget(): """Fixture providing a fake tab widget.""" - tab = namedtuple('Tab', 'cur_url load_status') - tab.load_status = namedtuple('load_status', 'name') - tab.cur_url = namedtuple('cur_url', 'toDisplayString') + tab = collections.namedtuple('Tab', 'cur_url load_status') + tab.cur_url = collections.namedtuple('cur_url', 'toDisplayString') return tab @@ -56,71 +52,75 @@ def url_widget(qtbot, monkeypatch, config_stub): } monkeypatch.setattr( 'qutebrowser.mainwindow.statusbar.url.style.config', config_stub) - widget = UrlText() + widget = url.UrlText() qtbot.add_widget(widget) assert not widget.isVisible() return widget -@pytest.mark.parametrize('url', [ - ('http://abc123.com/this/awesome/url.html'), - ('https://supersecret.gov/nsa/files.txt'), - ('Th1$ i$ n0t @ n0rm@L uRL! P@n1c! <-->'), - (None) +@pytest.mark.parametrize('url_text', [ + 'http://abc123.com/this/awesome/url.html', + 'https://supersecret.gov/nsa/files.txt', + 'Th1$ i$ n0t @ n0rm@L uRL! P@n1c! <-->', + None ]) -def test_set_url(url_widget, url): +def test_set_url(url_widget, url_text): """Test text displayed by the widget.""" - url_widget.set_url(url) - if url is not None: - assert url_widget.text() == url + url_widget.set_url(url_text) + if url_text is not None: + assert url_widget.text() == url_text else: assert url_widget.text() == "" -@pytest.mark.parametrize('url, title, text', [ +@pytest.mark.parametrize('url_text, title, text', [ ('http://abc123.com/this/awesome/url.html', 'Awesome site', 'click me!'), ('https://supersecret.gov/nsa/files.txt', 'Secret area', None), ('Th1$ i$ n0t @ n0rm@L uRL! P@n1c! <-->', 'Probably spam', 'definitely'), (None, None, 'did I break?!') ]) -def test_set_hover_url(url_widget, url, title, text): +def test_set_hover_url(url_widget, url_text, title, text): """Test text when hovering over a link.""" - url_widget.set_hover_url(url, title, text) - if url is not None: - assert url_widget.text() == url + url_widget.set_hover_url(url_text, title, text) + if url_text is not None: + assert url_widget.text() == url_text + assert url_widget._urltype == url.UrlType.hover else: assert url_widget.text() == '' + assert url_widget._urltype == url.UrlType.normal @pytest.mark.parametrize('status, expected', [ - ('success', 'success'), - ('success_https', 'success_https'), - ('error', 'error'), - ('warn', 'warn') + (webview.LoadStatus.success, url.UrlType.success), + (webview.LoadStatus.success_https, url.UrlType.success_https), + (webview.LoadStatus.error, url.UrlType.error), + (webview.LoadStatus.warn, url.UrlType.warn), + (webview.LoadStatus.loading, url.UrlType.normal), + (webview.LoadStatus.none, url.UrlType.normal) ]) def test_on_load_status_changed(url_widget, status, expected): """Test text when status is changed.""" url_widget.set_url('www.example.com') - url_widget.on_load_status_changed(status) - assert url_widget._urltype.name == expected + url_widget.on_load_status_changed(status.name) + assert url_widget._urltype == expected -@pytest.mark.parametrize('load_status, url', [ - ('success', 'http://abc123.com/this/awesome/url.html'), - ('success', 'http://reddit.com/r/linux'), - ('success_https', 'www.google.com'), - ('success_https', 'https://supersecret.gov/nsa/files.txt'), - ('warn', 'www.shadysite.org/some/path/to/a/file/that/has/issues.htm'), - ('error', 'Th1$ i$ n0t @ n0rm@L uRL! P@n1c! <-->'), - ('error', None) +@pytest.mark.parametrize('load_status, url_text', [ + (url.UrlType.success, 'http://abc123.com/this/awesome/url.html'), + (url.UrlType.success, 'http://reddit.com/r/linux'), + (url.UrlType.success_https, 'www.google.com'), + (url.UrlType.success_https, 'https://supersecret.gov/nsa/files.txt'), + (url.UrlType.warn, 'www.shadysite.org/some/path/to/a/file/that/has/issues.htm'), + (url.UrlType.error, 'Th1$ i$ n0t @ n0rm@L uRL! P@n1c! <-->'), + (url.UrlType.error, None) ]) -def test_on_tab_changed(url_widget, tab_widget, load_status, url): - tab_widget.load_status.name = load_status - tab_widget.cur_url.toDisplayString = lambda: url +def test_on_tab_changed(url_widget, tab_widget, load_status, url_text): + tab_widget.load_status = load_status + tab_widget.cur_url.toDisplayString = lambda: url_text url_widget.on_tab_changed(tab_widget) - if url is not None: - assert url_widget._urltype.name == load_status - assert url_widget.text() == url + if url_text is not None: + assert url_widget._urltype == load_status + assert url_widget.text() == url_text else: - assert url_widget._urltype.name == 'normal' + assert url_widget._urltype == url.UrlType.normal assert url_widget.text() == '' From 32304f36dd53aff487b466b4685f9f9cac7ece96 Mon Sep 17 00:00:00 2001 From: Clayton Craft Date: Fri, 25 Mar 2016 16:35:49 -0700 Subject: [PATCH 3/7] fix pylint failure --- tests/unit/mainwindow/statusbar/test_url.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/mainwindow/statusbar/test_url.py b/tests/unit/mainwindow/statusbar/test_url.py index 6587c6afa..530c67965 100644 --- a/tests/unit/mainwindow/statusbar/test_url.py +++ b/tests/unit/mainwindow/statusbar/test_url.py @@ -110,7 +110,7 @@ def test_on_load_status_changed(url_widget, status, expected): (url.UrlType.success, 'http://reddit.com/r/linux'), (url.UrlType.success_https, 'www.google.com'), (url.UrlType.success_https, 'https://supersecret.gov/nsa/files.txt'), - (url.UrlType.warn, 'www.shadysite.org/some/path/to/a/file/that/has/issues.htm'), + (url.UrlType.warn, 'www.shadysite.org/some/path/to/file/with/issues.htm'), (url.UrlType.error, 'Th1$ i$ n0t @ n0rm@L uRL! P@n1c! <-->'), (url.UrlType.error, None) ]) From e0c0613db6abf752c2c1c262a073758ce3bed08b Mon Sep 17 00:00:00 2001 From: Clayton Craft Date: Mon, 28 Mar 2016 15:12:16 -0700 Subject: [PATCH 4/7] Added new test for simulating loading page and hover/unhover URL --- tests/unit/mainwindow/statusbar/test_url.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/unit/mainwindow/statusbar/test_url.py b/tests/unit/mainwindow/statusbar/test_url.py index 530c67965..d9115b28e 100644 --- a/tests/unit/mainwindow/statusbar/test_url.py +++ b/tests/unit/mainwindow/statusbar/test_url.py @@ -124,3 +124,23 @@ def test_on_tab_changed(url_widget, tab_widget, load_status, url_text): else: assert url_widget._urltype == url.UrlType.normal assert url_widget.text() == '' + + +@pytest.mark.parametrize('url_text, load_status, expected_status', [ + ('http://abc123.com/this/awesome/url.html', webview.LoadStatus.success, + url.UrlType.success), + ('https://supersecret.gov/nsa/files.txt', webview.LoadStatus.success_https, + url.UrlType.success_https), + ('Th1$ i$ n0t @ n0rm@L uRL! P@n1c! <-->', webview.LoadStatus.error, + url.UrlType.error), + ('http://www.qutebrowser.org/CONTRIBUTING.html', webview.LoadStatus.loading, + url.UrlType.normal), + ('www.whatisthisurl.com', webview.LoadStatus.warn, url.UrlType.warn) +]) +def test_normal_url(url_widget, url_text, load_status, expected_status): + url_widget.set_url(url_text) + url_widget.on_load_status_changed(load_status.name) + url_widget.set_hover_url(url_text, "", "") + url_widget.set_hover_url("", "", "") + assert url_widget.text() == url_text + assert url_widget._urltype == expected_status From c811db5424ba7ae34af3e9ddd41ecfa2a6e3f191 Mon Sep 17 00:00:00 2001 From: Clayton Craft Date: Mon, 28 Mar 2016 15:31:28 -0700 Subject: [PATCH 5/7] remove unused import --- tests/unit/mainwindow/statusbar/test_url.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unit/mainwindow/statusbar/test_url.py b/tests/unit/mainwindow/statusbar/test_url.py index d9115b28e..5ac0600d5 100644 --- a/tests/unit/mainwindow/statusbar/test_url.py +++ b/tests/unit/mainwindow/statusbar/test_url.py @@ -25,7 +25,6 @@ import collections from qutebrowser.browser import webview from qutebrowser.mainwindow.statusbar import url -from qutebrowser.utils import usertypes @pytest.fixture From cce1747e3e65cd33af0b1a5ac1633c342e3bdc47 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 29 Mar 2016 07:08:48 +0200 Subject: [PATCH 6/7] Regenerate authors --- README.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.asciidoc b/README.asciidoc index c1ac5ff6f..fe93da6df 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -169,6 +169,7 @@ Contributors, sorted by the number of commits in descending order: * Milan Svoboda * John ShaggyTwoDope Jenkins * Peter Vilim +* Clayton Craft * Oliver Caldwell * Philipp Hansch * Jonas Schürmann @@ -182,7 +183,6 @@ Contributors, sorted by the number of commits in descending order: * rikn00 * Michael Ilsaas * Martin Zimmermann -* Clayton Craft * Brian Jackson * sbinix * neeasade From f15fb16ad4db371321c973f2790d4a2205ea599d Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 29 Mar 2016 07:09:17 +0200 Subject: [PATCH 7/7] Fix small nitpick --- tests/unit/mainwindow/statusbar/test_url.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/unit/mainwindow/statusbar/test_url.py b/tests/unit/mainwindow/statusbar/test_url.py index 5ac0600d5..1d5878a01 100644 --- a/tests/unit/mainwindow/statusbar/test_url.py +++ b/tests/unit/mainwindow/statusbar/test_url.py @@ -46,7 +46,8 @@ def url_widget(qtbot, monkeypatch, config_stub): 'statusbar.url.fg.success.https': 'green', 'statusbar.url.fg.error': 'red', 'statusbar.url.fg.warn': 'orange', - 'statusbar.url.fg.hover': 'blue'}, + 'statusbar.url.fg.hover': 'blue' + }, 'fonts': {}, } monkeypatch.setattr(