Fix lint.
This commit is contained in:
parent
d3a92d505c
commit
9d44f777c0
@ -40,6 +40,7 @@ argument-rgx=[a-z_][a-z0-9_]{0,30}$
|
|||||||
variable-rgx=[a-z_][a-z0-9_]{0,30}$
|
variable-rgx=[a-z_][a-z0-9_]{0,30}$
|
||||||
class-attribute-rgx=[A-Za-z_][A-Za-z0-9_]{1,30}$
|
class-attribute-rgx=[A-Za-z_][A-Za-z0-9_]{1,30}$
|
||||||
inlinevar-rgx=[a-z_][a-z0-9_]*$
|
inlinevar-rgx=[a-z_][a-z0-9_]*$
|
||||||
|
docstring-min-length=2
|
||||||
|
|
||||||
[FORMAT]
|
[FORMAT]
|
||||||
max-line-length=79
|
max-line-length=79
|
||||||
|
@ -76,7 +76,7 @@ def check_spelling(target):
|
|||||||
# Words which look better when splitted, but might need some fine tuning.
|
# Words which look better when splitted, but might need some fine tuning.
|
||||||
words |= {'keystrings', 'webelements', 'mouseevent', 'keysequence',
|
words |= {'keystrings', 'webelements', 'mouseevent', 'keysequence',
|
||||||
'normalmode', 'eventloops', 'sizehint', 'statemachine',
|
'normalmode', 'eventloops', 'sizehint', 'statemachine',
|
||||||
'metaobject', 'logrecord', 'monkeypatch', 'filetype'}
|
'metaobject', 'logrecord', 'filetype'}
|
||||||
|
|
||||||
seen = collections.defaultdict(list)
|
seen = collections.defaultdict(list)
|
||||||
try:
|
try:
|
||||||
|
@ -105,8 +105,8 @@ class TestInline:
|
|||||||
|
|
||||||
Some UAs use this filename in a subsequent "save" operation.
|
Some UAs use this filename in a subsequent "save" operation.
|
||||||
"""
|
"""
|
||||||
header_checker.check_filename('inline; filename="foo.html"', 'foo.html',
|
header_checker.check_filename('inline; filename="foo.html"',
|
||||||
expected_inline=True)
|
'foo.html', expected_inline=True)
|
||||||
|
|
||||||
def test_inlwithfnattach(self, header_checker):
|
def test_inlwithfnattach(self, header_checker):
|
||||||
"""'inline', specifying a filename of "Not an attachment!".
|
"""'inline', specifying a filename of "Not an attachment!".
|
||||||
@ -851,7 +851,7 @@ class TestEncodingFallback:
|
|||||||
"filename=\"foo-ae.html\"", 'foo-ä.html')
|
"filename=\"foo-ae.html\"", 'foo-ä.html')
|
||||||
|
|
||||||
def test_attfnboth3(self, header_checker):
|
def test_attfnboth3(self, header_checker):
|
||||||
"""'attachment', specifying an ambigious filename.
|
"""'attachment', specifying an ambiguous filename.
|
||||||
|
|
||||||
currency-sign=¤ in the simple RFC2231/5987 format, and euro-sign=€ in
|
currency-sign=¤ in the simple RFC2231/5987 format, and euro-sign=€ in
|
||||||
RFC2231-with-continuations format.
|
RFC2231-with-continuations format.
|
||||||
@ -859,9 +859,9 @@ class TestEncodingFallback:
|
|||||||
A UA that supports could pick either, or ignore both because of the
|
A UA that supports could pick either, or ignore both because of the
|
||||||
ambiguity.
|
ambiguity.
|
||||||
"""
|
"""
|
||||||
header_checker.check_ignored("attachment; "
|
header_checker.check_ignored(
|
||||||
"filename*0*=ISO-8859-15''euro-sign%3d%a4; "
|
"attachment; filename*0*=ISO-8859-15''euro-sign%3d%a4; "
|
||||||
"filename*=ISO-8859-1''currency-sign%3d%a4")
|
"filename*=ISO-8859-1''currency-sign%3d%a4")
|
||||||
|
|
||||||
def test_attnewandfn(self, header_checker):
|
def test_attnewandfn(self, header_checker):
|
||||||
"""'attachment', specifying a new parameter "foobar".
|
"""'attachment', specifying a new parameter "foobar".
|
||||||
@ -918,5 +918,3 @@ class TestOur:
|
|||||||
"""'attachment' with double space in the filename."""
|
"""'attachment' with double space in the filename."""
|
||||||
header_checker.check_filename('attachment; filename="foo bar.html"',
|
header_checker.check_filename('attachment; filename="foo bar.html"',
|
||||||
'foo bar.html')
|
'foo bar.html')
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,4 +59,3 @@ class TestParseContentType:
|
|||||||
mimetype, rest = http.parse_content_type(reply)
|
mimetype, rest = http.parse_content_type(reply)
|
||||||
assert mimetype == 'image/example'
|
assert mimetype == 'image/example'
|
||||||
assert rest == ' encoding=UTF-8'
|
assert rest == ' encoding=UTF-8'
|
||||||
|
|
||||||
|
@ -40,18 +40,20 @@ class TestSerializeHistory:
|
|||||||
QUrl('http://original.url.example.com/'), 'arg',
|
QUrl('http://original.url.example.com/'), 'arg',
|
||||||
user_data={'foo': 23, 'bar': 42}),
|
user_data={'foo': 23, 'bar': 42}),
|
||||||
# From https://github.com/OtterBrowser/otter-browser/issues/709#issuecomment-74749471
|
# From https://github.com/OtterBrowser/otter-browser/issues/709#issuecomment-74749471
|
||||||
Item(QUrl(
|
Item(
|
||||||
'http://github.com/OtterBrowser/24/134/2344/otter-browser/issues/709/'),
|
QUrl('http://github.com/OtterBrowser/24/134/2344/otter-browser/'
|
||||||
QUrl(
|
'issues/709/'),
|
||||||
'http://github.com/OtterBrowser/24/134/2344/otter-browser/issues/709/'),
|
QUrl('http://github.com/OtterBrowser/24/134/2344/otter-browser/'
|
||||||
'Page not found | github',
|
'issues/709/'),
|
||||||
user_data={'zoom': 149, 'scroll-pos': QPoint(0, 0)}),
|
'Page not found | github',
|
||||||
Item(QUrl(
|
user_data={'zoom': 149, 'scroll-pos': QPoint(0, 0)}),
|
||||||
'https://mail.google.com/mail/u/0/#label/some+label/234lkjsd0932lkjf884jqwerdf4'),
|
Item(
|
||||||
QUrl(
|
QUrl('https://mail.google.com/mail/u/0/#label/some+label/'
|
||||||
'https://mail.google.com/mail/u/0/#label/some+label/234lkjsd0932lkjf884jqwerdf4'),
|
'234lkjsd0932lkjf884jqwerdf4'),
|
||||||
'"some label" - email@gmail.com - Gmail"',
|
QUrl('https://mail.google.com/mail/u/0/#label/some+label/'
|
||||||
user_data={'zoom': 120, 'scroll-pos': QPoint(0, 0)}),
|
'234lkjsd0932lkjf884jqwerdf4'),
|
||||||
|
'"some label" - email@gmail.com - Gmail"',
|
||||||
|
user_data={'zoom': 120, 'scroll-pos': QPoint(0, 0)}),
|
||||||
]
|
]
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
@ -104,10 +106,11 @@ class TestSerializeHistory:
|
|||||||
|
|
||||||
class TestSerializeHistorySpecial:
|
class TestSerializeHistorySpecial:
|
||||||
|
|
||||||
"""Tests for serialize() without items set up in setUp."""
|
"""Tests for serialize() without items set up in setup."""
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def setUp(self, webpage):
|
def setup(self, webpage):
|
||||||
|
"""Set up the initial QWebPage for each test."""
|
||||||
self.page = webpage
|
self.page = webpage
|
||||||
self.history = self.page.history()
|
self.history = self.page.history()
|
||||||
assert self.history.count() == 0
|
assert self.history.count() == 0
|
||||||
@ -134,5 +137,3 @@ class TestSerializeHistorySpecial:
|
|||||||
assert self.history.count() == 0
|
assert self.history.count() == 0
|
||||||
assert self.history.currentItemIndex() == 0
|
assert self.history.currentItemIndex() == 0
|
||||||
assert not user_data
|
assert not user_data
|
||||||
|
|
||||||
|
|
||||||
|
@ -379,6 +379,7 @@ class TestIsEditable:
|
|||||||
|
|
||||||
@pytest.yield_fixture
|
@pytest.yield_fixture
|
||||||
def stub_config(self, stubs):
|
def stub_config(self, stubs):
|
||||||
|
"""Fixture to create a config stub with an input section."""
|
||||||
config = stubs.ConfigStub({'input': {}})
|
config = stubs.ConfigStub({'input': {}})
|
||||||
with mock.patch('qutebrowser.browser.webelem.config', new=config):
|
with mock.patch('qutebrowser.browser.webelem.config', new=config):
|
||||||
yield config
|
yield config
|
||||||
@ -557,5 +558,3 @@ class TestIsEditable:
|
|||||||
"""Test div-element with codemirror class."""
|
"""Test div-element with codemirror class."""
|
||||||
elem = get_webelem(tagname='div', classes='foo CodeMirror-foo')
|
elem = get_webelem(tagname='div', classes='foo CodeMirror-foo')
|
||||||
assert elem.is_editable()
|
assert elem.is_editable()
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,21 +66,19 @@ class TestConfigParser:
|
|||||||
|
|
||||||
def test_transformed_option_old(self):
|
def test_transformed_option_old(self):
|
||||||
"""Test a transformed option with the old name."""
|
"""Test a transformed option with the old name."""
|
||||||
# WORKAROUND for unknown PyQt bug
|
|
||||||
# Instance of 'str' has no 'name' member
|
|
||||||
self.cp.read_dict({'colors': {'tab.fg.odd': 'pink'}})
|
self.cp.read_dict({'colors': {'tab.fg.odd': 'pink'}})
|
||||||
self.cfg._from_cp(self.cp)
|
self.cfg._from_cp(self.cp)
|
||||||
assert self.cfg.get('colors', 'tabs.fg.odd').name() == \
|
actual = self.cfg.get('colors', 'tabs.fg.odd').name()
|
||||||
QColor('pink').name()
|
expected = QColor('pink').name()
|
||||||
|
assert actual == expected
|
||||||
|
|
||||||
def test_transformed_option_new(self):
|
def test_transformed_option_new(self):
|
||||||
"""Test a transformed section with the new name."""
|
"""Test a transformed section with the new name."""
|
||||||
# WORKAROUND for unknown PyQt bug
|
|
||||||
# Instance of 'str' has no 'name' member
|
|
||||||
self.cp.read_dict({'colors': {'tabs.fg.odd': 'pink'}})
|
self.cp.read_dict({'colors': {'tabs.fg.odd': 'pink'}})
|
||||||
self.cfg._from_cp(self.cp)
|
self.cfg._from_cp(self.cp)
|
||||||
assert self.cfg.get('colors', 'tabs.fg.odd').name() == \
|
actual = self.cfg.get('colors', 'tabs.fg.odd').name()
|
||||||
QColor('pink').name()
|
expected = QColor('pink').name()
|
||||||
|
assert actual == expected
|
||||||
|
|
||||||
def test_invalid_value(self):
|
def test_invalid_value(self):
|
||||||
"""Test setting an invalid value."""
|
"""Test setting an invalid value."""
|
||||||
|
@ -34,6 +34,7 @@ from qutebrowser.utils import debug, utils
|
|||||||
|
|
||||||
|
|
||||||
class Font(QFont):
|
class Font(QFont):
|
||||||
|
|
||||||
"""A QFont with a nicer repr()."""
|
"""A QFont with a nicer repr()."""
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@ -59,6 +60,7 @@ class Font(QFont):
|
|||||||
|
|
||||||
|
|
||||||
class NetworkProxy(QNetworkProxy):
|
class NetworkProxy(QNetworkProxy):
|
||||||
|
|
||||||
"""A QNetworkProxy with a nicer repr()."""
|
"""A QNetworkProxy with a nicer repr()."""
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@ -69,11 +71,13 @@ class NetworkProxy(QNetworkProxy):
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def os_path(mocker):
|
def os_path(mocker):
|
||||||
"""Fixture that mocks and returns os.path from the configtypes module"""
|
"""Fixture that mocks and returns os.path from the configtypes module."""
|
||||||
return mocker.patch('qutebrowser.config.configtypes.os.path', autospec=True)
|
return mocker.patch('qutebrowser.config.configtypes.os.path',
|
||||||
|
autospec=True)
|
||||||
|
|
||||||
|
|
||||||
class TestValidValues:
|
class TestValidValues:
|
||||||
|
|
||||||
"""Test ValidValues."""
|
"""Test ValidValues."""
|
||||||
|
|
||||||
def test_contains_without_desc(self):
|
def test_contains_without_desc(self):
|
||||||
@ -121,6 +125,7 @@ class TestValidValues:
|
|||||||
|
|
||||||
|
|
||||||
class TestBaseType:
|
class TestBaseType:
|
||||||
|
|
||||||
"""Test BaseType."""
|
"""Test BaseType."""
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
@ -175,6 +180,7 @@ class TestBaseType:
|
|||||||
|
|
||||||
|
|
||||||
class TestString:
|
class TestString:
|
||||||
|
|
||||||
"""Test String."""
|
"""Test String."""
|
||||||
|
|
||||||
def test_minlen_toosmall(self):
|
def test_minlen_toosmall(self):
|
||||||
@ -269,6 +275,7 @@ class TestString:
|
|||||||
|
|
||||||
|
|
||||||
class TestList:
|
class TestList:
|
||||||
|
|
||||||
"""Test List."""
|
"""Test List."""
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
@ -318,6 +325,7 @@ class TestList:
|
|||||||
|
|
||||||
|
|
||||||
class TestBool:
|
class TestBool:
|
||||||
|
|
||||||
"""Test Bool."""
|
"""Test Bool."""
|
||||||
|
|
||||||
TESTS = {True: ['1', 'yes', 'YES', 'true', 'TrUe', 'on'],
|
TESTS = {True: ['1', 'yes', 'YES', 'true', 'TrUe', 'on'],
|
||||||
@ -367,6 +375,7 @@ class TestBool:
|
|||||||
|
|
||||||
|
|
||||||
class TestInt:
|
class TestInt:
|
||||||
|
|
||||||
"""Test Int."""
|
"""Test Int."""
|
||||||
|
|
||||||
def test_minval_gt_maxval(self):
|
def test_minval_gt_maxval(self):
|
||||||
@ -444,6 +453,7 @@ class TestInt:
|
|||||||
|
|
||||||
|
|
||||||
class TestIntList:
|
class TestIntList:
|
||||||
|
|
||||||
"""Test IntList."""
|
"""Test IntList."""
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
@ -483,6 +493,7 @@ class TestIntList:
|
|||||||
|
|
||||||
|
|
||||||
class TestFloat:
|
class TestFloat:
|
||||||
|
|
||||||
"""Test Float."""
|
"""Test Float."""
|
||||||
|
|
||||||
def test_minval_gt_maxval(self):
|
def test_minval_gt_maxval(self):
|
||||||
@ -570,6 +581,7 @@ class TestFloat:
|
|||||||
|
|
||||||
|
|
||||||
class TestPerc:
|
class TestPerc:
|
||||||
|
|
||||||
"""Test Perc."""
|
"""Test Perc."""
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
@ -651,6 +663,7 @@ class TestPerc:
|
|||||||
|
|
||||||
|
|
||||||
class TestPercList:
|
class TestPercList:
|
||||||
|
|
||||||
"""Test PercList."""
|
"""Test PercList."""
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
@ -731,6 +744,7 @@ class TestPercList:
|
|||||||
|
|
||||||
|
|
||||||
class TestPercOrInt:
|
class TestPercOrInt:
|
||||||
|
|
||||||
"""Test PercOrInt."""
|
"""Test PercOrInt."""
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
@ -868,6 +882,7 @@ class TestPercOrInt:
|
|||||||
|
|
||||||
|
|
||||||
class TestCommand:
|
class TestCommand:
|
||||||
|
|
||||||
"""Test Command."""
|
"""Test Command."""
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
@ -924,8 +939,12 @@ class TestCommand:
|
|||||||
|
|
||||||
|
|
||||||
class TestColorSystem:
|
class TestColorSystem:
|
||||||
|
|
||||||
"""Test ColorSystem."""
|
"""Test ColorSystem."""
|
||||||
|
|
||||||
|
# https://bitbucket.org/logilab/pylint/issue/511/
|
||||||
|
# pylint: disable=undefined-variable
|
||||||
|
|
||||||
TESTS = {
|
TESTS = {
|
||||||
'RGB': QColor.Rgb,
|
'RGB': QColor.Rgb,
|
||||||
'rgb': QColor.Rgb,
|
'rgb': QColor.Rgb,
|
||||||
@ -972,6 +991,7 @@ class TestColorSystem:
|
|||||||
|
|
||||||
|
|
||||||
class TestQtColor:
|
class TestQtColor:
|
||||||
|
|
||||||
"""Test QtColor."""
|
"""Test QtColor."""
|
||||||
|
|
||||||
VALID = ['#123', '#112233', '#111222333', '#111122223333', 'red']
|
VALID = ['#123', '#112233', '#111222333', '#111122223333', 'red']
|
||||||
@ -1014,6 +1034,7 @@ class TestQtColor:
|
|||||||
|
|
||||||
|
|
||||||
class TestCssColor(TestQtColor):
|
class TestCssColor(TestQtColor):
|
||||||
|
|
||||||
"""Test CssColor."""
|
"""Test CssColor."""
|
||||||
|
|
||||||
VALID = TestQtColor.VALID + ['-foobar(42)']
|
VALID = TestQtColor.VALID + ['-foobar(42)']
|
||||||
@ -1039,6 +1060,7 @@ class TestCssColor(TestQtColor):
|
|||||||
|
|
||||||
|
|
||||||
class TestQssColor(TestQtColor):
|
class TestQssColor(TestQtColor):
|
||||||
|
|
||||||
"""Test QssColor."""
|
"""Test QssColor."""
|
||||||
|
|
||||||
VALID = TestQtColor.VALID + [
|
VALID = TestQtColor.VALID + [
|
||||||
@ -1084,8 +1106,12 @@ FontDesc = collections.namedtuple('FontDesc',
|
|||||||
|
|
||||||
|
|
||||||
class TestFont:
|
class TestFont:
|
||||||
|
|
||||||
"""Test Font/QtFont."""
|
"""Test Font/QtFont."""
|
||||||
|
|
||||||
|
# https://bitbucket.org/logilab/pylint/issue/511/
|
||||||
|
# pylint: disable=undefined-variable
|
||||||
|
|
||||||
TESTS = {
|
TESTS = {
|
||||||
# (style, weight, pointsize, pixelsize, family
|
# (style, weight, pointsize, pixelsize, family
|
||||||
'"Foobar Neue"':
|
'"Foobar Neue"':
|
||||||
@ -1144,7 +1170,8 @@ class TestFont:
|
|||||||
t.validate('')
|
t.validate('')
|
||||||
t2.validate('')
|
t2.validate('')
|
||||||
|
|
||||||
@pytest.mark.parametrize('val, attr', itertools.product(TESTS, ['t', 't2']))
|
@pytest.mark.parametrize('val, attr',
|
||||||
|
itertools.product(TESTS, ['t', 't2']))
|
||||||
def test_validate_valid(self, val, attr):
|
def test_validate_valid(self, val, attr):
|
||||||
"""Test validate with valid values."""
|
"""Test validate with valid values."""
|
||||||
getattr(self, attr).validate(val)
|
getattr(self, attr).validate(val)
|
||||||
@ -1183,6 +1210,7 @@ class TestFont:
|
|||||||
|
|
||||||
|
|
||||||
class TestFontFamily:
|
class TestFontFamily:
|
||||||
|
|
||||||
"""Test FontFamily."""
|
"""Test FontFamily."""
|
||||||
|
|
||||||
TESTS = ['"Foobar Neue"', 'inconsolatazi4', 'Foobar']
|
TESTS = ['"Foobar Neue"', 'inconsolatazi4', 'Foobar']
|
||||||
@ -1234,6 +1262,7 @@ class TestFontFamily:
|
|||||||
|
|
||||||
|
|
||||||
class TestRegex:
|
class TestRegex:
|
||||||
|
|
||||||
"""Test Regex."""
|
"""Test Regex."""
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
@ -1269,6 +1298,7 @@ class TestRegex:
|
|||||||
|
|
||||||
|
|
||||||
class TestRegexList:
|
class TestRegexList:
|
||||||
|
|
||||||
"""Test RegexList."""
|
"""Test RegexList."""
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
@ -1310,13 +1340,13 @@ class TestRegexList:
|
|||||||
|
|
||||||
|
|
||||||
class TestFile:
|
class TestFile:
|
||||||
|
|
||||||
"""Test File."""
|
"""Test File."""
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def setup(self):
|
def setup(self):
|
||||||
self.t = configtypes.File()
|
self.t = configtypes.File()
|
||||||
|
|
||||||
|
|
||||||
def test_validate_empty(self):
|
def test_validate_empty(self):
|
||||||
"""Test validate with empty string and none_ok = False."""
|
"""Test validate with empty string and none_ok = False."""
|
||||||
with pytest.raises(configexc.ValidationError):
|
with pytest.raises(configexc.ValidationError):
|
||||||
@ -1376,6 +1406,7 @@ class TestFile:
|
|||||||
|
|
||||||
|
|
||||||
class TestDirectory:
|
class TestDirectory:
|
||||||
|
|
||||||
"""Test Directory."""
|
"""Test Directory."""
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
@ -1454,6 +1485,7 @@ class TestDirectory:
|
|||||||
|
|
||||||
|
|
||||||
class TestWebKitByte:
|
class TestWebKitByte:
|
||||||
|
|
||||||
"""Test WebKitBytes."""
|
"""Test WebKitBytes."""
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
@ -1528,6 +1560,7 @@ class TestWebKitByte:
|
|||||||
|
|
||||||
|
|
||||||
class TestWebKitBytesList:
|
class TestWebKitBytesList:
|
||||||
|
|
||||||
"""Test WebKitBytesList."""
|
"""Test WebKitBytesList."""
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
@ -1599,6 +1632,7 @@ class TestWebKitBytesList:
|
|||||||
|
|
||||||
|
|
||||||
class TestShellCommand:
|
class TestShellCommand:
|
||||||
|
|
||||||
"""Test ShellCommand."""
|
"""Test ShellCommand."""
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
@ -1649,6 +1683,7 @@ class TestShellCommand:
|
|||||||
|
|
||||||
|
|
||||||
class TestProxy:
|
class TestProxy:
|
||||||
|
|
||||||
"""Test Proxy."""
|
"""Test Proxy."""
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
@ -1697,11 +1732,12 @@ class TestProxy:
|
|||||||
|
|
||||||
def test_complete(self):
|
def test_complete(self):
|
||||||
"""Test complete."""
|
"""Test complete."""
|
||||||
assert self.t.complete() == \
|
actual = self.t.complete()
|
||||||
[('system', "Use the system wide proxy."),
|
expected = [('system', "Use the system wide proxy."),
|
||||||
('none', "Don't use any proxy"),
|
('none', "Don't use any proxy"),
|
||||||
('http://', 'HTTP proxy URL'),
|
('http://', 'HTTP proxy URL'),
|
||||||
('socks://', 'SOCKS proxy URL')]
|
('socks://', 'SOCKS proxy URL')]
|
||||||
|
assert actual == expected
|
||||||
|
|
||||||
def test_transform_empty(self):
|
def test_transform_empty(self):
|
||||||
"""Test transform with an empty value."""
|
"""Test transform with an empty value."""
|
||||||
@ -1713,51 +1749,53 @@ class TestProxy:
|
|||||||
|
|
||||||
def test_transform_none(self):
|
def test_transform_none(self):
|
||||||
"""Test transform with no proxy."""
|
"""Test transform with no proxy."""
|
||||||
assert NetworkProxy(self.t.transform('none')) == \
|
actual = NetworkProxy(self.t.transform('none'))
|
||||||
NetworkProxy(QNetworkProxy.NoProxy)
|
expected = NetworkProxy(QNetworkProxy.NoProxy)
|
||||||
|
assert actual == expected
|
||||||
|
|
||||||
def test_transform_socks(self):
|
def test_transform_socks(self):
|
||||||
"""Test transform with a socks proxy."""
|
"""Test transform with a socks proxy."""
|
||||||
proxy = NetworkProxy(QNetworkProxy.Socks5Proxy, 'example.com')
|
actual = NetworkProxy(self.t.transform('socks://example.com/'))
|
||||||
val = NetworkProxy(self.t.transform('socks://example.com/'))
|
expected = NetworkProxy(QNetworkProxy.Socks5Proxy, 'example.com')
|
||||||
assert proxy == val
|
assert actual == expected
|
||||||
|
|
||||||
def test_transform_socks5(self):
|
def test_transform_socks5(self):
|
||||||
"""Test transform with a socks5 proxy."""
|
"""Test transform with a socks5 proxy."""
|
||||||
proxy = NetworkProxy(QNetworkProxy.Socks5Proxy, 'example.com')
|
actual = NetworkProxy(self.t.transform('socks5://example.com'))
|
||||||
val = NetworkProxy(self.t.transform('socks5://example.com'))
|
expected = NetworkProxy(QNetworkProxy.Socks5Proxy, 'example.com')
|
||||||
assert proxy == val
|
assert actual == expected
|
||||||
|
|
||||||
def test_transform_http_port(self):
|
def test_transform_http_port(self):
|
||||||
"""Test transform with a http proxy with set port."""
|
"""Test transform with a http proxy with set port."""
|
||||||
proxy = NetworkProxy(QNetworkProxy.Socks5Proxy, 'example.com', 2342)
|
actual = NetworkProxy(self.t.transform('socks5://example.com:2342'))
|
||||||
val = NetworkProxy(self.t.transform('socks5://example.com:2342'))
|
expected = NetworkProxy(QNetworkProxy.Socks5Proxy, 'example.com', 2342)
|
||||||
assert proxy == val
|
assert actual == expected
|
||||||
|
|
||||||
def test_transform_socks_user(self):
|
def test_transform_socks_user(self):
|
||||||
"""Test transform with a socks proxy with set user."""
|
"""Test transform with a socks proxy with set user."""
|
||||||
proxy = NetworkProxy(
|
actual = NetworkProxy(self.t.transform('socks5://foo@example.com'))
|
||||||
|
expected = NetworkProxy(
|
||||||
QNetworkProxy.Socks5Proxy, 'example.com', 0, 'foo')
|
QNetworkProxy.Socks5Proxy, 'example.com', 0, 'foo')
|
||||||
val = NetworkProxy(self.t.transform('socks5://foo@example.com'))
|
assert actual == expected
|
||||||
assert proxy == val
|
|
||||||
|
|
||||||
def test_transform_socks_user_password(self):
|
def test_transform_socks_user_password(self):
|
||||||
"""Test transform with a socks proxy with set user/password."""
|
"""Test transform with a socks proxy with set user/password."""
|
||||||
proxy = NetworkProxy(QNetworkProxy.Socks5Proxy, 'example.com', 0,
|
actual = NetworkProxy(self.t.transform('socks5://foo:bar@example.com'))
|
||||||
'foo', 'bar')
|
expected = NetworkProxy(QNetworkProxy.Socks5Proxy, 'example.com', 0,
|
||||||
val = NetworkProxy(self.t.transform('socks5://foo:bar@example.com'))
|
'foo', 'bar')
|
||||||
assert proxy == val
|
assert actual == expected
|
||||||
|
|
||||||
def test_transform_socks_user_password_port(self):
|
def test_transform_socks_user_password_port(self):
|
||||||
"""Test transform with a socks proxy with set port/user/password."""
|
"""Test transform with a socks proxy with set port/user/password."""
|
||||||
proxy = NetworkProxy(QNetworkProxy.Socks5Proxy, 'example.com', 2323,
|
actual = NetworkProxy(
|
||||||
'foo', 'bar')
|
|
||||||
val = NetworkProxy(
|
|
||||||
self.t.transform('socks5://foo:bar@example.com:2323'))
|
self.t.transform('socks5://foo:bar@example.com:2323'))
|
||||||
assert proxy == val
|
expected = NetworkProxy(QNetworkProxy.Socks5Proxy, 'example.com', 2323,
|
||||||
|
'foo', 'bar')
|
||||||
|
assert actual == expected
|
||||||
|
|
||||||
|
|
||||||
class TestSearchEngineName:
|
class TestSearchEngineName:
|
||||||
|
|
||||||
"""Test SearchEngineName."""
|
"""Test SearchEngineName."""
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
@ -1784,6 +1822,7 @@ class TestSearchEngineName:
|
|||||||
|
|
||||||
|
|
||||||
class TestSearchEngineUrl:
|
class TestSearchEngineUrl:
|
||||||
|
|
||||||
"""Test SearchEngineUrl."""
|
"""Test SearchEngineUrl."""
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
@ -1824,6 +1863,7 @@ class TestSearchEngineUrl:
|
|||||||
|
|
||||||
|
|
||||||
class TestFuzzyUrl:
|
class TestFuzzyUrl:
|
||||||
|
|
||||||
"""Test FuzzyUrl."""
|
"""Test FuzzyUrl."""
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
@ -1868,6 +1908,7 @@ class TestFuzzyUrl:
|
|||||||
|
|
||||||
|
|
||||||
class TestUserStyleSheet:
|
class TestUserStyleSheet:
|
||||||
|
|
||||||
"""Test UserStyleSheet."""
|
"""Test UserStyleSheet."""
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
@ -1906,8 +1947,12 @@ class TestUserStyleSheet:
|
|||||||
|
|
||||||
|
|
||||||
class TestAutoSearch:
|
class TestAutoSearch:
|
||||||
|
|
||||||
"""Test AutoSearch."""
|
"""Test AutoSearch."""
|
||||||
|
|
||||||
|
# https://bitbucket.org/logilab/pylint/issue/511/
|
||||||
|
# pylint: disable=undefined-variable
|
||||||
|
|
||||||
TESTS = {
|
TESTS = {
|
||||||
'naive': ['naive', 'NAIVE'] + TestBool.TESTS[True],
|
'naive': ['naive', 'NAIVE'] + TestBool.TESTS[True],
|
||||||
'dns': ['dns', 'DNS'],
|
'dns': ['dns', 'DNS'],
|
||||||
@ -1929,9 +1974,8 @@ class TestAutoSearch:
|
|||||||
t = configtypes.AutoSearch(none_ok=True)
|
t = configtypes.AutoSearch(none_ok=True)
|
||||||
t.validate('')
|
t.validate('')
|
||||||
|
|
||||||
@pytest.mark.parametrize('val',
|
@pytest.mark.parametrize('val', [val for vallist in TESTS.values()
|
||||||
[val for vallist in TESTS.values() for val in
|
for val in vallist])
|
||||||
vallist])
|
|
||||||
def test_validate_valid(self, val):
|
def test_validate_valid(self, val):
|
||||||
"""Test validate with valid values."""
|
"""Test validate with valid values."""
|
||||||
self.t.validate(val)
|
self.t.validate(val)
|
||||||
@ -1943,9 +1987,8 @@ class TestAutoSearch:
|
|||||||
self.t.validate(val)
|
self.t.validate(val)
|
||||||
|
|
||||||
@pytest.mark.parametrize('out, inp',
|
@pytest.mark.parametrize('out, inp',
|
||||||
[(out, inp) for (out, inputs) in TESTS.items() for
|
[(out, inp) for (out, inputs) in TESTS.items()
|
||||||
inp in inputs]
|
for inp in inputs])
|
||||||
)
|
|
||||||
def test_transform(self, out, inp):
|
def test_transform(self, out, inp):
|
||||||
"""Test transform with all values."""
|
"""Test transform with all values."""
|
||||||
assert self.t.transform(inp) == out
|
assert self.t.transform(inp) == out
|
||||||
@ -1956,8 +1999,12 @@ class TestAutoSearch:
|
|||||||
|
|
||||||
|
|
||||||
class TestIgnoreCase:
|
class TestIgnoreCase:
|
||||||
|
|
||||||
"""Test IgnoreCase."""
|
"""Test IgnoreCase."""
|
||||||
|
|
||||||
|
# https://bitbucket.org/logilab/pylint/issue/511/
|
||||||
|
# pylint: disable=undefined-variable
|
||||||
|
|
||||||
TESTS = {
|
TESTS = {
|
||||||
'smart': ['smart', 'SMART'],
|
'smart': ['smart', 'SMART'],
|
||||||
True: TestBool.TESTS[True],
|
True: TestBool.TESTS[True],
|
||||||
@ -1993,9 +2040,8 @@ class TestIgnoreCase:
|
|||||||
self.t.validate(val)
|
self.t.validate(val)
|
||||||
|
|
||||||
@pytest.mark.parametrize('out, inp',
|
@pytest.mark.parametrize('out, inp',
|
||||||
[(out, inp) for (out, inputs) in TESTS.items() for
|
[(out, inp) for (out, inputs) in TESTS.items()
|
||||||
inp in inputs]
|
for inp in inputs])
|
||||||
)
|
|
||||||
def test_transform(self, out, inp):
|
def test_transform(self, out, inp):
|
||||||
"""Test transform with all values."""
|
"""Test transform with all values."""
|
||||||
assert self.t.transform(inp) == out
|
assert self.t.transform(inp) == out
|
||||||
@ -2006,6 +2052,7 @@ class TestIgnoreCase:
|
|||||||
|
|
||||||
|
|
||||||
class TestEncoding:
|
class TestEncoding:
|
||||||
|
|
||||||
"""Test Encoding."""
|
"""Test Encoding."""
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
@ -2042,6 +2089,7 @@ class TestEncoding:
|
|||||||
|
|
||||||
|
|
||||||
class TestUrlList:
|
class TestUrlList:
|
||||||
|
|
||||||
"""Test UrlList."""
|
"""Test UrlList."""
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
@ -2079,14 +2127,15 @@ class TestUrlList:
|
|||||||
|
|
||||||
def test_transform_single(self):
|
def test_transform_single(self):
|
||||||
"""Test transform with a single value."""
|
"""Test transform with a single value."""
|
||||||
|
actual = self.t.transform('http://qutebrowser.org/')
|
||||||
expected = [QUrl('http://qutebrowser.org/')]
|
expected = [QUrl('http://qutebrowser.org/')]
|
||||||
assert self.t.transform('http://qutebrowser.org/') == expected
|
assert actual == expected
|
||||||
|
|
||||||
def test_transform_more(self):
|
def test_transform_more(self):
|
||||||
"""Test transform with multiple values."""
|
"""Test transform with multiple values."""
|
||||||
assert (
|
actual = self.t.transform('http://qutebrowser.org/,http://heise.de/')
|
||||||
self.t.transform('http://qutebrowser.org/,http://heise.de/') ==
|
expected = [QUrl('http://qutebrowser.org/'), QUrl('http://heise.de/')]
|
||||||
[QUrl('http://qutebrowser.org/'), QUrl('http://heise.de/')])
|
assert actual == expected
|
||||||
|
|
||||||
def test_transform_empty(self):
|
def test_transform_empty(self):
|
||||||
"""Test transform with an empty value."""
|
"""Test transform with an empty value."""
|
||||||
@ -2094,6 +2143,7 @@ class TestUrlList:
|
|||||||
|
|
||||||
|
|
||||||
class TestFormatString:
|
class TestFormatString:
|
||||||
|
|
||||||
"""Test FormatString."""
|
"""Test FormatString."""
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
@ -2134,6 +2184,7 @@ class TestFormatString:
|
|||||||
|
|
||||||
|
|
||||||
class TestUserAgent:
|
class TestUserAgent:
|
||||||
|
|
||||||
"""Test UserAgent."""
|
"""Test UserAgent."""
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
|
@ -24,27 +24,24 @@ import pytest
|
|||||||
|
|
||||||
@pytest.fixture(scope='session', autouse=True)
|
@pytest.fixture(scope='session', autouse=True)
|
||||||
def app_and_logging(qapp):
|
def app_and_logging(qapp):
|
||||||
"""
|
"""Initialize a QApplication and logging.
|
||||||
Initializes our logging system and ensures that a QApplication is created
|
|
||||||
and used by all tests.
|
This ensures that a QApplication is created and used by all tests.
|
||||||
"""
|
"""
|
||||||
from log import init
|
from log import init
|
||||||
|
|
||||||
init()
|
init()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
def stubs():
|
def stubs():
|
||||||
"""
|
"""Provide access to stub objects useful for testing."""
|
||||||
Provides access to stub objects useful for testing.
|
|
||||||
"""
|
|
||||||
import stubs
|
import stubs
|
||||||
|
|
||||||
return stubs
|
return stubs
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
def unicode_encode_err():
|
def unicode_encode_err():
|
||||||
|
"""Provide a fake UnicodeEncodeError exception."""
|
||||||
return UnicodeEncodeError('ascii', # codec
|
return UnicodeEncodeError('ascii', # codec
|
||||||
'', # object
|
'', # object
|
||||||
0, # start
|
0, # start
|
||||||
@ -66,9 +63,7 @@ def webpage():
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def fake_keyevent_factory():
|
def fake_keyevent_factory():
|
||||||
"""
|
"""Fixture that when called will return a mock instance of a QKeyEvent."""
|
||||||
Fixture that when called will return a mock instance of a QKeyEvent.
|
|
||||||
"""
|
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
from PyQt5.QtGui import QKeyEvent
|
from PyQt5.QtGui import QKeyEvent
|
||||||
|
|
||||||
@ -80,4 +75,4 @@ def fake_keyevent_factory():
|
|||||||
evtmock.text.return_value = text
|
evtmock.text.return_value = text
|
||||||
return evtmock
|
return evtmock
|
||||||
|
|
||||||
return fake_keyevent
|
return fake_keyevent
|
||||||
|
@ -44,9 +44,7 @@ BINDINGS = {'test': {'<Ctrl-a>': 'ctrla',
|
|||||||
|
|
||||||
@pytest.yield_fixture
|
@pytest.yield_fixture
|
||||||
def fake_keyconfig():
|
def fake_keyconfig():
|
||||||
"""
|
"""Create a mock of a KeyConfiguration and register it into objreg."""
|
||||||
Creates a mock of a KeyConfiguration and registers it into objreg.
|
|
||||||
"""
|
|
||||||
fake_keyconfig = mock.Mock(spec=['get_bindings_for'])
|
fake_keyconfig = mock.Mock(spec=['get_bindings_for'])
|
||||||
fake_keyconfig.get_bindings_for.side_effect = lambda s: BINDINGS[s]
|
fake_keyconfig.get_bindings_for.side_effect = lambda s: BINDINGS[s]
|
||||||
objreg.register('key-config', fake_keyconfig)
|
objreg.register('key-config', fake_keyconfig)
|
||||||
@ -56,9 +54,7 @@ def fake_keyconfig():
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_timer(mocker, stubs):
|
def mock_timer(mocker, stubs):
|
||||||
"""Mocks the QTimer class used by the
|
"""Mock the Timer class used by the usertypes module with a stub."""
|
||||||
"qutebrowser.keyinput.basekeyparser.usertypes" module with a stub version.
|
|
||||||
"""
|
|
||||||
mocker.patch('qutebrowser.keyinput.basekeyparser.usertypes.Timer',
|
mocker.patch('qutebrowser.keyinput.basekeyparser.usertypes.Timer',
|
||||||
new=stubs.FakeTimer)
|
new=stubs.FakeTimer)
|
||||||
|
|
||||||
@ -211,12 +207,12 @@ class TestKeyChain:
|
|||||||
assert self.kp._keystring == ''
|
assert self.kp._keystring == ''
|
||||||
|
|
||||||
def test_ambiguous_keychain(self, fake_keyevent_factory, mocker, stubs):
|
def test_ambiguous_keychain(self, fake_keyevent_factory, mocker, stubs):
|
||||||
"""Test ambigious keychain."""
|
"""Test ambiguous keychain."""
|
||||||
mocker.patch('qutebrowser.keyinput.basekeyparser.config',
|
mocker.patch('qutebrowser.keyinput.basekeyparser.config',
|
||||||
new=stubs.ConfigStub(CONFIG))
|
new=stubs.ConfigStub(CONFIG))
|
||||||
timer = self.kp._ambiguous_timer
|
timer = self.kp._ambiguous_timer
|
||||||
assert not timer.isActive()
|
assert not timer.isActive()
|
||||||
# We start with 'a' where the keychain gives us an ambigious result.
|
# We start with 'a' where the keychain gives us an ambiguous result.
|
||||||
# Then we check if the timer has been set up correctly
|
# Then we check if the timer has been set up correctly
|
||||||
self.kp.handle(fake_keyevent_factory(Qt.Key_A, text='a'))
|
self.kp.handle(fake_keyevent_factory(Qt.Key_A, text='a'))
|
||||||
assert not self.kp.execute.called
|
assert not self.kp.execute.called
|
||||||
|
@ -92,4 +92,3 @@ class TestsNormalKeyParser:
|
|||||||
assert not self.kp.execute.called
|
assert not self.kp.execute.called
|
||||||
assert self.kp._keystring == ''
|
assert self.kp._keystring == ''
|
||||||
keystring_updated_mock.assert_called_once_with('')
|
keystring_updated_mock.assert_called_once_with('')
|
||||||
|
|
||||||
|
@ -1,5 +1,23 @@
|
|||||||
"""
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
||||||
pytest fixtures and utilities for testing.
|
|
||||||
|
# Copyright 2014-2015 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
||||||
|
#
|
||||||
|
# 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/>.
|
||||||
|
|
||||||
|
"""pytest fixtures and utilities for testing.
|
||||||
|
|
||||||
Fixtures defined here will be visible to all test files in this directory and
|
Fixtures defined here will be visible to all test files in this directory and
|
||||||
below.
|
below.
|
||||||
@ -16,8 +34,8 @@ def default_config():
|
|||||||
"""
|
"""
|
||||||
Fixture that registers an empty config object into the objreg module.
|
Fixture that registers an empty config object into the objreg module.
|
||||||
|
|
||||||
Should be used by tests which create widgets that obtain their initial state
|
Should be used by tests which create widgets that obtain their initial
|
||||||
from the global config object.
|
state from the global config object.
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
|
|
||||||
@ -31,4 +49,4 @@ def default_config():
|
|||||||
config_obj = ConfigManager(configdir=None, fname=None, relaxed=True)
|
config_obj = ConfigManager(configdir=None, fname=None, relaxed=True)
|
||||||
objreg.register('config', config_obj)
|
objreg.register('config', config_obj)
|
||||||
yield config_obj
|
yield config_obj
|
||||||
objreg.delete('config')
|
objreg.delete('config')
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
|
|
||||||
"""Test Percentage widget."""
|
"""Test Percentage widget."""
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from qutebrowser.mainwindow.statusbar.percentage import Percentage
|
from qutebrowser.mainwindow.statusbar.percentage import Percentage
|
||||||
@ -37,7 +38,8 @@ def test_percentage_text(qtbot, y, expected):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
qtbot: pytestqt.plugin.QtBot fixture
|
qtbot: pytestqt.plugin.QtBot fixture
|
||||||
y: y position of the page as an int in the range [0, 100]. parametrized.
|
y: y position of the page as an int in the range [0, 100].
|
||||||
|
parametrized.
|
||||||
expected: expected text given y position. parametrized.
|
expected: expected text given y position. parametrized.
|
||||||
"""
|
"""
|
||||||
percentage = Percentage()
|
percentage = Percentage()
|
||||||
|
@ -30,9 +30,7 @@ from qutebrowser.mainwindow.statusbar.progress import Progress
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def progress_widget(qtbot, default_config):
|
def progress_widget(qtbot, default_config):
|
||||||
"""
|
"""Create a Progress widget and checks its initial state."""
|
||||||
Creates a Progress widget and checks it initial state.
|
|
||||||
"""
|
|
||||||
widget = Progress()
|
widget = Progress()
|
||||||
qtbot.add_widget(widget)
|
qtbot.add_widget(widget)
|
||||||
assert not widget.isVisible()
|
assert not widget.isVisible()
|
||||||
@ -41,7 +39,8 @@ def progress_widget(qtbot, default_config):
|
|||||||
|
|
||||||
|
|
||||||
def test_load_started(progress_widget):
|
def test_load_started(progress_widget):
|
||||||
"""
|
"""Ensure the Progress widget reacts properly when the page starts loading.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
progress_widget: Progress widget that will be tested.
|
progress_widget: Progress widget that will be tested.
|
||||||
"""
|
"""
|
||||||
@ -62,13 +61,14 @@ Tab = namedtuple('Tab', 'progress load_status')
|
|||||||
(Tab(100, webview.LoadStatus.none), False),
|
(Tab(100, webview.LoadStatus.none), False),
|
||||||
])
|
])
|
||||||
def test_tab_changed(progress_widget, tab, expected_visible):
|
def test_tab_changed(progress_widget, tab, expected_visible):
|
||||||
"""
|
"""Test that progress widget value and visibility state match expectations.
|
||||||
Test that progress widget value and visibility state match expectations,
|
|
||||||
using a dummy Tab object.
|
This uses a dummy Tab object.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
progress_widget: Progress widget that will be tested.
|
progress_widget: Progress widget that will be tested.
|
||||||
"""
|
"""
|
||||||
progress_widget.on_tab_changed(tab)
|
progress_widget.on_tab_changed(tab)
|
||||||
assert (progress_widget.value(), progress_widget.isVisible()) == \
|
actual = progress_widget.value(), progress_widget.isVisible()
|
||||||
(tab.progress, expected_visible)
|
expected = tab.progress, expected_visible
|
||||||
|
assert actual == expected
|
||||||
|
@ -24,18 +24,15 @@ from qutebrowser.mainwindow.statusbar.textbase import TextBase
|
|||||||
|
|
||||||
|
|
||||||
def test_elided_text(qtbot):
|
def test_elided_text(qtbot):
|
||||||
"""
|
"""Ensure that a widget too small to hold the entire label text will elide.
|
||||||
Ensure that a widget that can't hold the entire label text will display
|
|
||||||
and elided version of the string instead.
|
Note:
|
||||||
|
It is difficult to check what is actually being drawn in a portable
|
||||||
|
way, so at least we ensure our customized methods are being called and
|
||||||
|
the elided string contains the horizontal ellipsis character.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
qtbot: pytestqt.plugin.QtBot fixture
|
qtbot: pytestqt.plugin.QtBot fixture
|
||||||
|
|
||||||
Note:
|
|
||||||
|
|
||||||
It is difficult to check what is actually being drawn in a
|
|
||||||
portable way, so at least we ensure our customized methods are being
|
|
||||||
called and the elided string contains the horizontal ellipsis character.
|
|
||||||
"""
|
"""
|
||||||
label = TextBase()
|
label = TextBase()
|
||||||
qtbot.add_widget(label)
|
qtbot.add_widget(label)
|
||||||
@ -43,4 +40,4 @@ def test_elided_text(qtbot):
|
|||||||
label.setText(long_string)
|
label.setText(long_string)
|
||||||
label.resize(100, 50)
|
label.resize(100, 50)
|
||||||
label.show()
|
label.show()
|
||||||
assert '…' in label._elided_text
|
assert '…' in label._elided_text # pylint: disable=protected-access
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import unittest
|
|
||||||
import logging
|
import logging
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
@ -75,14 +74,15 @@ class TestArg:
|
|||||||
"bin", ["foo", filename, "bar"])
|
"bin", ["foo", filename, "bar"])
|
||||||
|
|
||||||
def test_in_arg_placeholder(self):
|
def test_in_arg_placeholder(self):
|
||||||
|
"""Test starting editor with placeholder argument inside argument."""
|
||||||
self.config.data = {'general': {'editor': ['bin', 'foo{}bar'],
|
self.config.data = {'general': {'editor': ['bin', 'foo{}bar'],
|
||||||
'editor-encoding': 'utf-8'}}
|
'editor-encoding': 'utf-8'}}
|
||||||
"""Test starting editor with placeholder argument inside argument."""
|
|
||||||
self.editor.edit("")
|
self.editor.edit("")
|
||||||
self.editor._proc.start.assert_called_with("bin", ["foo{}bar"])
|
self.editor._proc.start.assert_called_with("bin", ["foo{}bar"])
|
||||||
|
|
||||||
|
|
||||||
class TestFileHandling(object):
|
class TestFileHandling(object):
|
||||||
|
|
||||||
"""Test creation/deletion of tempfile.
|
"""Test creation/deletion of tempfile.
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
@ -132,6 +132,7 @@ class TestFileHandling(object):
|
|||||||
|
|
||||||
|
|
||||||
class TestModifyTests(object):
|
class TestModifyTests(object):
|
||||||
|
|
||||||
"""Tests to test if the text gets saved/loaded correctly.
|
"""Tests to test if the text gets saved/loaded correctly.
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
@ -202,6 +203,7 @@ class TestModifyTests(object):
|
|||||||
|
|
||||||
|
|
||||||
class TestErrorMessage:
|
class TestErrorMessage:
|
||||||
|
|
||||||
"""Test if statusbar error messages get emitted correctly.
|
"""Test if statusbar error messages get emitted correctly.
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
@ -233,4 +235,3 @@ class TestErrorMessage:
|
|||||||
with caplog.atLevel(logging.ERROR, 'message'):
|
with caplog.atLevel(logging.ERROR, 'message'):
|
||||||
self.editor.on_proc_closed(1, QProcess.NormalExit)
|
self.editor.on_proc_closed(1, QProcess.NormalExit)
|
||||||
assert len(caplog.records()) == 3
|
assert len(caplog.records()) == 3
|
||||||
|
|
||||||
|
@ -32,20 +32,18 @@ from qutebrowser.misc import readline
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mocked_qapp(mocker, stubs):
|
def mocked_qapp(mocker, stubs):
|
||||||
"""
|
"""Fixture that mocks readline.QApplication and returns it."""
|
||||||
Fixture that mocks QApplication in the readline module and returns it.
|
|
||||||
"""
|
|
||||||
return mocker.patch('qutebrowser.misc.readline.QApplication',
|
return mocker.patch('qutebrowser.misc.readline.QApplication',
|
||||||
new_callable=stubs.FakeQApplication)
|
new_callable=stubs.FakeQApplication)
|
||||||
|
|
||||||
|
|
||||||
class TestNoneWidget:
|
class TestNoneWidget:
|
||||||
|
|
||||||
"""Tests when the focused widget is None."""
|
"""Test if there are no exceptions when the widget is None."""
|
||||||
|
|
||||||
def test_none(self, mocked_qapp):
|
def test_none(self, mocked_qapp):
|
||||||
|
"""Call each rl_* method with a None focusWidget."""
|
||||||
self.bridge = readline.ReadlineBridge()
|
self.bridge = readline.ReadlineBridge()
|
||||||
"""Test if there are no exceptions when the widget is None."""
|
|
||||||
mocked_qapp.focusWidget = mock.Mock(return_value=None)
|
mocked_qapp.focusWidget = mock.Mock(return_value=None)
|
||||||
for name, method in inspect.getmembers(self.bridge, inspect.ismethod):
|
for name, method in inspect.getmembers(self.bridge, inspect.ismethod):
|
||||||
if name.startswith('rl_'):
|
if name.startswith('rl_'):
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
# pylint: disable=invalid-name
|
# pylint: disable=invalid-name
|
||||||
|
|
||||||
"""Fake objects/stubs."""
|
"""Fake objects/stubs."""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
@ -272,6 +273,7 @@ class FakeTimer(QObject):
|
|||||||
|
|
||||||
|
|
||||||
class MessageModule:
|
class MessageModule:
|
||||||
|
|
||||||
"""A drop-in replacement for qutebrowser.utils.message."""
|
"""A drop-in replacement for qutebrowser.utils.message."""
|
||||||
|
|
||||||
def error(self, _win_id, message, _immediately=False):
|
def error(self, _win_id, message, _immediately=False):
|
||||||
@ -284,4 +286,4 @@ class MessageModule:
|
|||||||
|
|
||||||
def info(self, _win_id, message, _immediately=True):
|
def info(self, _win_id, message, _immediately=True):
|
||||||
"""Log an info message to the message logger."""
|
"""Log an info message to the message logger."""
|
||||||
logging.getLogger('message').info(message)
|
logging.getLogger('message').info(message)
|
||||||
|
@ -105,5 +105,3 @@ def test_interval(timer):
|
|||||||
assert timer.interval() == 0
|
assert timer.interval() == 0
|
||||||
timer.setInterval(1000)
|
timer.setInterval(1000)
|
||||||
assert timer.interval() == 1000
|
assert timer.interval() == 1000
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from PyQt5.QtCore import Qt
|
|
||||||
from PyQt5.QtWidgets import QStyle, QFrame
|
from PyQt5.QtWidgets import QStyle, QFrame
|
||||||
|
|
||||||
from qutebrowser.utils import debug
|
from qutebrowser.utils import debug
|
||||||
|
@ -31,9 +31,10 @@ from qutebrowser.utils import standarddir
|
|||||||
|
|
||||||
@pytest.yield_fixture(autouse=True)
|
@pytest.yield_fixture(autouse=True)
|
||||||
def change_qapp_name():
|
def change_qapp_name():
|
||||||
"""
|
"""Change the name of the QApplication instance.
|
||||||
Change the name of the QApplication instance for all tests in this module
|
|
||||||
to "qutebrowser_test".
|
This changes the applicationName for all tests in this module to
|
||||||
|
"qutebrowser_test".
|
||||||
"""
|
"""
|
||||||
old_name = QApplication.instance().applicationName()
|
old_name = QApplication.instance().applicationName()
|
||||||
QApplication.instance().setApplicationName('qutebrowser_test')
|
QApplication.instance().setApplicationName('qutebrowser_test')
|
||||||
@ -44,23 +45,23 @@ def change_qapp_name():
|
|||||||
@pytest.mark.skipif(not sys.platform.startswith("linux"),
|
@pytest.mark.skipif(not sys.platform.startswith("linux"),
|
||||||
reason="requires Linux")
|
reason="requires Linux")
|
||||||
class TestGetStandardDirLinux:
|
class TestGetStandardDirLinux:
|
||||||
"""Tests for standarddir under Linux.
|
|
||||||
"""
|
"""Tests for standarddir under Linux."""
|
||||||
|
|
||||||
def test_data_explicit(self, monkeypatch, tmpdir):
|
def test_data_explicit(self, monkeypatch, tmpdir):
|
||||||
"""Test data dir with XDG_DATA_HOME explicitely set."""
|
"""Test data dir with XDG_DATA_HOME explicitly set."""
|
||||||
monkeypatch.setenv('XDG_DATA_HOME', str(tmpdir))
|
monkeypatch.setenv('XDG_DATA_HOME', str(tmpdir))
|
||||||
standarddir.init(None)
|
standarddir.init(None)
|
||||||
assert standarddir.data() == str(tmpdir / 'qutebrowser_test')
|
assert standarddir.data() == str(tmpdir / 'qutebrowser_test')
|
||||||
|
|
||||||
def test_config_explicit(self, monkeypatch, tmpdir):
|
def test_config_explicit(self, monkeypatch, tmpdir):
|
||||||
"""Test config dir with XDG_CONFIG_HOME explicitely set."""
|
"""Test config dir with XDG_CONFIG_HOME explicitly set."""
|
||||||
monkeypatch.setenv('XDG_CONFIG_HOME', str(tmpdir))
|
monkeypatch.setenv('XDG_CONFIG_HOME', str(tmpdir))
|
||||||
standarddir.init(None)
|
standarddir.init(None)
|
||||||
assert standarddir.config() == str(tmpdir / 'qutebrowser_test')
|
assert standarddir.config() == str(tmpdir / 'qutebrowser_test')
|
||||||
|
|
||||||
def test_cache_explicit(self, monkeypatch, tmpdir):
|
def test_cache_explicit(self, monkeypatch, tmpdir):
|
||||||
"""Test cache dir with XDG_CACHE_HOME explicitely set."""
|
"""Test cache dir with XDG_CACHE_HOME explicitly set."""
|
||||||
monkeypatch.setenv('XDG_CACHE_HOME', str(tmpdir))
|
monkeypatch.setenv('XDG_CACHE_HOME', str(tmpdir))
|
||||||
standarddir.init(None)
|
standarddir.init(None)
|
||||||
assert standarddir.cache() == str(tmpdir / 'qutebrowser_test')
|
assert standarddir.cache() == str(tmpdir / 'qutebrowser_test')
|
||||||
@ -93,8 +94,8 @@ class TestGetStandardDirLinux:
|
|||||||
@pytest.mark.skipif(not sys.platform.startswith("win"),
|
@pytest.mark.skipif(not sys.platform.startswith("win"),
|
||||||
reason="requires Windows")
|
reason="requires Windows")
|
||||||
class TestGetStandardDirWindows:
|
class TestGetStandardDirWindows:
|
||||||
"""Tests for standarddir under Windows.
|
|
||||||
"""
|
"""Tests for standarddir under Windows."""
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def reset_standarddir(self):
|
def reset_standarddir(self):
|
||||||
|
@ -21,9 +21,6 @@
|
|||||||
|
|
||||||
"""Tests for qutebrowser.utils.urlutils."""
|
"""Tests for qutebrowser.utils.urlutils."""
|
||||||
|
|
||||||
import unittest
|
|
||||||
from unittest import mock
|
|
||||||
|
|
||||||
from PyQt5.QtCore import QUrl
|
from PyQt5.QtCore import QUrl
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -46,6 +43,7 @@ def get_config_stub(auto_search=True):
|
|||||||
|
|
||||||
|
|
||||||
class TestSpecialURL:
|
class TestSpecialURL:
|
||||||
|
|
||||||
"""Test is_special_url.
|
"""Test is_special_url.
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
@ -78,10 +76,12 @@ class TestSpecialURL:
|
|||||||
|
|
||||||
|
|
||||||
class TestSearchUrl:
|
class TestSearchUrl:
|
||||||
|
|
||||||
"""Test _get_search_url."""
|
"""Test _get_search_url."""
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def mock_config(self, stubs, mocker):
|
def mock_config(self, stubs, mocker):
|
||||||
|
"""Fixture to patch urlutils.config with a stub."""
|
||||||
mocker.patch('qutebrowser.utils.urlutils.config',
|
mocker.patch('qutebrowser.utils.urlutils.config',
|
||||||
new=stubs.ConfigStub(get_config_stub()))
|
new=stubs.ConfigStub(get_config_stub()))
|
||||||
|
|
||||||
@ -123,6 +123,7 @@ class TestSearchUrl:
|
|||||||
|
|
||||||
|
|
||||||
class TestIsUrl:
|
class TestIsUrl:
|
||||||
|
|
||||||
"""Tests for is_url.
|
"""Tests for is_url.
|
||||||
|
|
||||||
Class attributes:
|
Class attributes:
|
||||||
@ -179,43 +180,42 @@ class TestIsUrl:
|
|||||||
|
|
||||||
|
|
||||||
class TestQurlFromUserInput:
|
class TestQurlFromUserInput:
|
||||||
|
|
||||||
"""Tests for qurl_from_user_input."""
|
"""Tests for qurl_from_user_input."""
|
||||||
|
|
||||||
def test_url(self):
|
def test_url(self):
|
||||||
"""Test a normal URL."""
|
"""Test a normal URL."""
|
||||||
assert (
|
url = urlutils.qurl_from_user_input('qutebrowser.org')
|
||||||
urlutils.qurl_from_user_input('qutebrowser.org').toString()
|
assert url.toString() == 'http://qutebrowser.org'
|
||||||
== 'http://qutebrowser.org')
|
|
||||||
|
|
||||||
def test_url_http(self):
|
def test_url_http(self):
|
||||||
"""Test a normal URL with http://."""
|
"""Test a normal URL with http://."""
|
||||||
assert (
|
url = urlutils.qurl_from_user_input('http://qutebrowser.org')
|
||||||
urlutils.qurl_from_user_input('http://qutebrowser.org').toString()
|
assert url.toString() == 'http://qutebrowser.org'
|
||||||
== 'http://qutebrowser.org')
|
|
||||||
|
|
||||||
def test_ipv6_bare(self):
|
def test_ipv6_bare(self):
|
||||||
"""Test an IPv6 without brackets."""
|
"""Test an IPv6 without brackets."""
|
||||||
assert (urlutils.qurl_from_user_input('::1/foo').toString()
|
url = urlutils.qurl_from_user_input('::1/foo')
|
||||||
== 'http://[::1]/foo')
|
assert url.toString() == 'http://[::1]/foo'
|
||||||
|
|
||||||
def test_ipv6(self):
|
def test_ipv6(self):
|
||||||
"""Test an IPv6 with brackets."""
|
"""Test an IPv6 with brackets."""
|
||||||
assert (urlutils.qurl_from_user_input('[::1]/foo').toString() ==
|
url = urlutils.qurl_from_user_input('[::1]/foo')
|
||||||
'http://[::1]/foo')
|
assert url.toString() == 'http://[::1]/foo'
|
||||||
|
|
||||||
def test_ipv6_http(self):
|
def test_ipv6_http(self):
|
||||||
"""Test an IPv6 with http:// and brackets."""
|
"""Test an IPv6 with http:// and brackets."""
|
||||||
assert (
|
url = urlutils.qurl_from_user_input('http://[::1]')
|
||||||
urlutils.qurl_from_user_input('http://[::1]').toString() ==
|
assert url.toString() == 'http://[::1]'
|
||||||
'http://[::1]')
|
|
||||||
|
|
||||||
|
|
||||||
class TestFilenameFromUrl:
|
class TestFilenameFromUrl:
|
||||||
|
|
||||||
"""Tests for filename_from_url."""
|
"""Tests for filename_from_url."""
|
||||||
|
|
||||||
def test_invalid_url(self):
|
def test_invalid_url(self):
|
||||||
"""Test with an invalid QUrl."""
|
"""Test with an invalid QUrl."""
|
||||||
assert urlutils.filename_from_url(QUrl()) == None
|
assert urlutils.filename_from_url(QUrl()) is None
|
||||||
|
|
||||||
def test_url_path(self):
|
def test_url_path(self):
|
||||||
"""Test with an URL with path."""
|
"""Test with an URL with path."""
|
||||||
|
@ -478,4 +478,3 @@ class TestNewestSlice:
|
|||||||
items = range(5)
|
items = range(5)
|
||||||
sliced = utils.newest_slice(items, 50)
|
sliced = utils.newest_slice(items, 50)
|
||||||
assert list(sliced) == list(items)
|
assert list(sliced) == list(items)
|
||||||
|
|
||||||
|
2
tox.ini
2
tox.ini
@ -69,7 +69,7 @@ deps = pep257==0.5.0
|
|||||||
# D102: Docstring missing, will be handled by others
|
# D102: Docstring missing, will be handled by others
|
||||||
# D209: Blank line before closing """ (removed from PEP257)
|
# D209: Blank line before closing """ (removed from PEP257)
|
||||||
# D402: First line should not be function's signature (false-positives)
|
# D402: First line should not be function's signature (false-positives)
|
||||||
commands = {envpython} -m pep257 scripts tests qutebrowser --ignore=D102,D209,D402 '--match=(?!resources|test_content_disposition).*\.py'
|
commands = {envpython} -m pep257 scripts tests qutebrowser --ignore=D102,D103,D209,D402 '--match=(?!resources|test_content_disposition).*\.py'
|
||||||
|
|
||||||
[testenv:flake8]
|
[testenv:flake8]
|
||||||
skip_install = true
|
skip_install = true
|
||||||
|
Loading…
Reference in New Issue
Block a user