Use flake8-pytest-style

This commit is contained in:
Florian Bruhin 2022-01-04 10:27:51 +01:00
parent e1af0ff74d
commit f4714a9300
23 changed files with 36 additions and 30 deletions

13
.flake8
View File

@ -41,6 +41,9 @@ exclude = .*,__pycache__,resources.py
# W503: like break before binary operator # W503: like break before binary operator
# W504: line break after binary operator # W504: line break after binary operator
# FI15: __future__ import "generator_stop" missing # FI15: __future__ import "generator_stop" missing
# PT004: fixture '{name}' does not return anything, add leading underscore
# PT011: pytest.raises(ValueError) is too broad, set the match parameter or use a more specific exception
# PT012: pytest.raises() block should contain a single simple statement
ignore = ignore =
B001,B008,B305, B001,B008,B305,
E128,E226,E265,E501,E402,E266,E722,E731, E128,E226,E265,E501,E402,E266,E722,E731,
@ -49,8 +52,11 @@ ignore =
P101,P102,P103, P101,P102,P103,
D102,D103,D106,D107,D104,D105,D209,D211,D401,D402,D403,D412,D413, D102,D103,D106,D107,D104,D105,D209,D211,D401,D402,D403,D412,D413,
A003, A003,
W503, W504 W503, W504,
FI15 FI15,
PT004,
PT011,
PT012
min-version = 3.6.1 min-version = 3.6.1
max-complexity = 12 max-complexity = 12
per-file-ignores = per-file-ignores =
@ -62,3 +68,6 @@ per-file-ignores =
copyright-check = True copyright-check = True
copyright-regexp = # Copyright [\d-]+ .* copyright-regexp = # Copyright [\d-]+ .*
copyright-min-file-size = 110 copyright-min-file-size = 110
pytest-fixture-no-parentheses = True
pytest-mark-no-parentheses = True
pytest-parametrize-names-type = csv

View File

@ -11,7 +11,9 @@ flake8-deprecated==1.3
flake8-docstrings==1.6.0 flake8-docstrings==1.6.0
flake8-future-import==0.4.6 flake8-future-import==0.4.6
flake8-mock==0.3 flake8-mock==0.3
flake8-plugin-utils==1.3.2
flake8-polyfill==1.0.2 flake8-polyfill==1.0.2
flake8-pytest-style==1.6.0
flake8-string-format==0.3.0 flake8-string-format==0.3.0
flake8-tidy-imports==4.5.0 flake8-tidy-imports==4.5.0
flake8-tuple==0.4.1 flake8-tuple==0.4.1

View File

@ -11,6 +11,7 @@ flake8-mock
flake8-string-format flake8-string-format
flake8-tidy-imports flake8-tidy-imports
flake8-tuple flake8-tuple
flake8-pytest-style
pep8-naming pep8-naming
pydocstyle pydocstyle
pyflakes pyflakes

View File

@ -95,6 +95,8 @@ CHANGELOG_URLS = {
'flake8-mock': 'https://github.com/aleGpereira/flake8-mock#changes', 'flake8-mock': 'https://github.com/aleGpereira/flake8-mock#changes',
'flake8-polyfill': 'https://gitlab.com/pycqa/flake8-polyfill/-/blob/master/CHANGELOG.rst', 'flake8-polyfill': 'https://gitlab.com/pycqa/flake8-polyfill/-/blob/master/CHANGELOG.rst',
'flake8-string-format': 'https://github.com/xZise/flake8-string-format#changes', 'flake8-string-format': 'https://github.com/xZise/flake8-string-format#changes',
'flake8-plugin-utils': 'https://github.com/afonasev/flake8-plugin-utils#change-log',
'flake8-pytest-style': 'https://github.com/m-burst/flake8-pytest-style#change-log',
'pep8-naming': 'https://github.com/PyCQA/pep8-naming/blob/master/CHANGELOG.rst', 'pep8-naming': 'https://github.com/PyCQA/pep8-naming/blob/master/CHANGELOG.rst',
'pycodestyle': 'https://github.com/PyCQA/pycodestyle/blob/master/CHANGES.txt', 'pycodestyle': 'https://github.com/PyCQA/pycodestyle/blob/master/CHANGES.txt',
'pyflakes': 'https://github.com/PyCQA/pyflakes/blob/master/NEWS.rst', 'pyflakes': 'https://github.com/PyCQA/pyflakes/blob/master/NEWS.rst',

View File

@ -22,7 +22,7 @@
import pytest import pytest
@pytest.mark.parametrize(['file_name', 'elem_id', 'source', 'input_text'], [ @pytest.mark.parametrize('file_name, elem_id, source, input_text', [
('textarea.html', 'qute-textarea', 'clipboard', 'qutebrowser'), ('textarea.html', 'qute-textarea', 'clipboard', 'qutebrowser'),
('textarea.html', 'qute-textarea', 'keypress', 'superqutebrowser'), ('textarea.html', 'qute-textarea', 'keypress', 'superqutebrowser'),
('input.html', 'qute-input', 'clipboard', 'amazingqutebrowser'), ('input.html', 'qute-input', 'clipboard', 'amazingqutebrowser'),

View File

@ -632,7 +632,7 @@ def redirect_webengine_data(data_tmpdir, monkeypatch):
monkeypatch.setenv('HOME', str(data_tmpdir)) monkeypatch.setenv('HOME', str(data_tmpdir))
@pytest.fixture() @pytest.fixture
def short_tmpdir(): def short_tmpdir():
"""A short temporary directory for a XDG_RUNTIME_DIR.""" """A short temporary directory for a XDG_RUNTIME_DIR."""
with tempfile.TemporaryDirectory() as tdir: with tempfile.TemporaryDirectory() as tdir:

View File

@ -70,7 +70,7 @@ class Selection:
self._qtbot.wait(50) self._qtbot.wait(50)
assert False, 'Failed to get selection!' pytest.fail('Failed to get selection!')
def check_multiline(self, expected, *, strip=False): def check_multiline(self, expected, *, strip=False):
self.check(textwrap.dedent(expected).strip(), strip=strip) self.check(textwrap.dedent(expected).strip(), strip=strip)

View File

@ -141,7 +141,7 @@ class TestDelete:
class TestAdd: class TestAdd:
@pytest.fixture() @pytest.fixture
def mock_time(self, mocker): def mock_time(self, mocker):
m = mocker.patch('qutebrowser.browser.history.time') m = mocker.patch('qutebrowser.browser.history.time')
m.time.return_value = 12345 m.time.return_value = 12345

View File

@ -151,4 +151,5 @@ def test_detach_after_toggling(hidden_again, needs_recreate,
else: else:
with qtbot.assert_not_emitted(fake_inspector.recreate): with qtbot.assert_not_emitted(fake_inspector.recreate):
fake_inspector.set_position(inspector.Position.window) fake_inspector.set_position(inspector.Position.window)
assert fake_inspector.isVisible() and fake_inspector.isWindow() assert fake_inspector.isVisible()
assert fake_inspector.isWindow()

View File

@ -866,8 +866,6 @@ class TestIsEditable:
@pytest.mark.parametrize('setting, tagname, attributes, editable', [ @pytest.mark.parametrize('setting, tagname, attributes, editable', [
(True, 'embed', {}, True), (True, 'embed', {}, True),
(True, 'embed', {}, True),
(False, 'applet', {}, False),
(False, 'applet', {}, False), (False, 'applet', {}, False),
(True, 'object', {'type': 'application/foo'}, True), (True, 'object', {'type': 'application/foo'}, True),
(False, 'object', {'type': 'application/foo'}, False), (False, 'object', {'type': 'application/foo'}, False),

View File

@ -37,13 +37,13 @@ def completionview(qtbot, status_command_stub, config_stub, win_registry,
mocker.patch('qutebrowser.completion.completer.Completer', autospec=True) mocker.patch('qutebrowser.completion.completer.Completer', autospec=True)
mocker.patch( mocker.patch(
'qutebrowser.completion.completiondelegate.CompletionItemDelegate', 'qutebrowser.completion.completiondelegate.CompletionItemDelegate',
new=lambda *_: None) return_value=None)
view = completionwidget.CompletionView(cmd=status_command_stub, win_id=0) view = completionwidget.CompletionView(cmd=status_command_stub, win_id=0)
qtbot.add_widget(view) qtbot.add_widget(view)
return view return view
@pytest.fixture() @pytest.fixture
def model(): def model():
return completionmodel.CompletionModel() return completionmodel.CompletionModel()

View File

@ -76,7 +76,7 @@ def _check_completions(model, expected):
assert sum(model.column_widths) == 100 assert sum(model.column_widths) == 100
@pytest.fixture() @pytest.fixture
def cmdutils_stub(monkeypatch, stubs): def cmdutils_stub(monkeypatch, stubs):
"""Patch the cmdutils module to provide fake commands.""" """Patch the cmdutils module to provide fake commands."""
return monkeypatch.setattr(objects, 'commands', { return monkeypatch.setattr(objects, 'commands', {
@ -93,7 +93,7 @@ def cmdutils_stub(monkeypatch, stubs):
}) })
@pytest.fixture() @pytest.fixture
def configdata_stub(config_stub, monkeypatch, configdata_init): def configdata_stub(config_stub, monkeypatch, configdata_init):
"""Patch the configdata module to provide fake data.""" """Patch the configdata module to provide fake data."""
monkeypatch.setattr(configdata, 'DATA', collections.OrderedDict([ monkeypatch.setattr(configdata, 'DATA', collections.OrderedDict([

View File

@ -27,7 +27,7 @@ from PyQt5.QtCore import QUrl
from qutebrowser.config import configcommands from qutebrowser.config import configcommands
from qutebrowser.api import cmdutils from qutebrowser.api import cmdutils
from qutebrowser.utils import usertypes, urlmatch from qutebrowser.utils import usertypes, urlmatch, utils
from qutebrowser.keyinput import keyutils from qutebrowser.keyinput import keyutils
from qutebrowser.misc import objects from qutebrowser.misc import objects
@ -529,7 +529,7 @@ class TestSource:
pyfile = config_tmpdir / 'sourced.py' pyfile = config_tmpdir / 'sourced.py'
arg = 'sourced.py' arg = 'sourced.py'
else: else:
assert False, location raise utils.Unreachable(location)
pyfile.write_text('\n'.join(['config.load_autoconfig(False)', pyfile.write_text('\n'.join(['config.load_autoconfig(False)',
'c.content.javascript.enabled = False']), 'c.content.javascript.enabled = False']),

View File

@ -1481,7 +1481,6 @@ class TestConfigPyWriter:
def init_patch(qapp, fake_save_manager, config_tmpdir, data_tmpdir, def init_patch(qapp, fake_save_manager, config_tmpdir, data_tmpdir,
config_stub, monkeypatch): config_stub, monkeypatch):
monkeypatch.setattr(configfiles, 'state', None) monkeypatch.setattr(configfiles, 'state', None)
yield
def test_init(init_patch, config_tmpdir): def test_init(init_patch, config_tmpdir):

View File

@ -1876,7 +1876,6 @@ class TestShellCommand:
@pytest.mark.parametrize('kwargs, val', [ @pytest.mark.parametrize('kwargs, val', [
({'placeholder': True}, '[foo, bar]'), ({'placeholder': True}, '[foo, bar]'),
({'placeholder': True}, '[foo, "{", "}", bar'), ({'placeholder': True}, '[foo, "{", "}", bar'),
({'placeholder': True}, '[foo, bar]'),
({'placeholder': True}, '[foo, "{fi", "le}", bar'), ({'placeholder': True}, '[foo, "{fi", "le}", bar'),
# Like valid ones but with wrong placeholder # Like valid ones but with wrong placeholder

View File

@ -318,13 +318,11 @@ class TestFontFamilies:
@pytest.mark.parametrize('families, quote, expected', [ @pytest.mark.parametrize('families, quote, expected', [
(['family'], True, 'family'), (['family'], True, 'family'),
(['family1', 'family2'], True, 'family1, family2'), (['family1', 'family2'], True, 'family1, family2'),
(['family'], True, 'family'),
(['space family', 'alien'], True, '"space family", alien'), (['space family', 'alien'], True, '"space family", alien'),
(['comma,family', 'period'], True, '"comma,family", period'), (['comma,family', 'period'], True, '"comma,family", period'),
(['family'], False, 'family'), (['family'], False, 'family'),
(['family1', 'family2'], False, 'family1, family2'), (['family1', 'family2'], False, 'family1, family2'),
(['family'], False, 'family'),
(['space family', 'alien'], False, 'space family, alien'), (['space family', 'alien'], False, 'space family, alien'),
(['comma,family', 'period'], False, 'comma,family, period'), (['comma,family', 'period'], False, 'comma,family, period'),
]) ])

View File

@ -324,7 +324,6 @@ class TestWebEngineArgs:
("light", "5.15.0", False), ("light", "5.15.0", False),
("light", "5.15.1", False), ("light", "5.15.1", False),
("light", "5.15.2", False), ("light", "5.15.2", False),
("light", "5.15.2", False),
("light", "5.15.3", False), ("light", "5.15.3", False),
("light", "6.0.0", False), ("light", "6.0.0", False),
@ -333,7 +332,6 @@ class TestWebEngineArgs:
("auto", "5.15.0", False), ("auto", "5.15.0", False),
("auto", "5.15.1", False), ("auto", "5.15.1", False),
("auto", "5.15.2", False), ("auto", "5.15.2", False),
("auto", "5.15.2", False),
("auto", "5.15.3", False), ("auto", "5.15.3", False),
("auto", "6.0.0", False), ("auto", "6.0.0", False),
]) ])

View File

@ -24,7 +24,7 @@ from qutebrowser.misc import objects
from qutebrowser.utils import usertypes from qutebrowser.utils import usertypes
@pytest.mark.parametrize([ @pytest.mark.parametrize([ # noqa: PT006
'user_agent', 'os_info', 'webkit_version', 'user_agent', 'os_info', 'webkit_version',
'upstream_browser_key', 'upstream_browser_version', 'qt_key' 'upstream_browser_key', 'upstream_browser_version', 'qt_key'
], [ ], [

View File

@ -31,7 +31,7 @@ from qutebrowser.api import cmdutils
from qutebrowser.qt import sip from qutebrowser.qt import sip
@pytest.fixture() @pytest.fixture
def proc(qtbot, caplog): def proc(qtbot, caplog):
"""A fixture providing a GUIProcess and cleaning it up after the test.""" """A fixture providing a GUIProcess and cleaning it up after the test."""
p = guiprocess.GUIProcess('testprocess') p = guiprocess.GUIProcess('testprocess')
@ -46,7 +46,7 @@ def proc(qtbot, caplog):
p._proc.waitForFinished() p._proc.waitForFinished()
@pytest.fixture() @pytest.fixture
def fake_proc(monkeypatch, stubs): def fake_proc(monkeypatch, stubs):
"""A fixture providing a GUIProcess with a mocked QProcess.""" """A fixture providing a GUIProcess with a mocked QProcess."""
p = guiprocess.GUIProcess('testprocess') p = guiprocess.GUIProcess('testprocess')

View File

@ -38,7 +38,7 @@ class TestCommandLineEdit:
cmd_edit.set_prompt(':') cmd_edit.set_prompt(':')
qtbot.add_widget(cmd_edit) qtbot.add_widget(cmd_edit)
assert cmd_edit.text() == '' assert cmd_edit.text() == ''
yield cmd_edit return cmd_edit
def test_position(self, qtbot, cmd_edit): def test_position(self, qtbot, cmd_edit):
"""Test cursor position based on the prompt.""" """Test cursor position based on the prompt."""

View File

@ -348,7 +348,7 @@ class TestHideQtWarning:
"""Tests for hide_qt_warning/QtWarningFilter.""" """Tests for hide_qt_warning/QtWarningFilter."""
@pytest.fixture() @pytest.fixture
def qt_logger(self): def qt_logger(self):
return logging.getLogger('qt-tests') return logging.getLogger('qt-tests')

View File

@ -51,8 +51,7 @@ else:
test_file = None test_file = None
@pytest.mark.parametrize(['qversion', 'compiled', 'pyqt', 'version', 'exact', @pytest.mark.parametrize('qversion, compiled, pyqt, version, exact, expected', [
'expected'], [
# equal versions # equal versions
('5.14.0', None, None, '5.14.0', False, True), ('5.14.0', None, None, '5.14.0', False, True),
('5.14.0', None, None, '5.14.0', True, True), # exact=True ('5.14.0', None, None, '5.14.0', True, True), # exact=True
@ -741,7 +740,7 @@ class TestPyQIODevice:
with pytest.raises(io.UnsupportedOperation): with pytest.raises(io.UnsupportedOperation):
pyqiodev.seek(0, whence) pyqiodev.seek(0, whence)
@pytest.mark.flaky() @pytest.mark.flaky
def test_qprocess(self, py_proc): def test_qprocess(self, py_proc):
"""Test PyQIODevice with a QProcess which is non-sequential. """Test PyQIODevice with a QProcess which is non-sequential.

View File

@ -65,7 +65,7 @@ class TestReadFile:
'qutebrowser/html/unrelatedhtml', 'qutebrowser/html/unrelatedhtml',
] ]
yield zipfile.Path(zip_path) / 'qutebrowser' return zipfile.Path(zip_path) / 'qutebrowser'
@pytest.fixture(params=['pathlib', 'zipfile']) @pytest.fixture(params=['pathlib', 'zipfile'])
def resource_root(self, request): def resource_root(self, request):