tests: Share common markers.
This commit is contained in:
parent
be3f61af62
commit
9b264c7514
@ -586,7 +586,7 @@ class TestAttachment:
|
|||||||
header_checker.check_filename('attachment; filename="/foo.html"',
|
header_checker.check_filename('attachment; filename="/foo.html"',
|
||||||
'foo.html')
|
'foo.html')
|
||||||
|
|
||||||
@pytest.mark.skipif(os.name != 'posix', reason="requires POSIX")
|
@pytest.mark.posix
|
||||||
def test_attabspathwin_unix(self, header_checker):
|
def test_attabspathwin_unix(self, header_checker):
|
||||||
"""'attachment', specifying an absolute filename in the fs root.
|
"""'attachment', specifying an absolute filename in the fs root.
|
||||||
|
|
||||||
@ -601,7 +601,7 @@ class TestAttachment:
|
|||||||
header_checker.check_filename(r'attachment; filename="\\foo.html"',
|
header_checker.check_filename(r'attachment; filename="\\foo.html"',
|
||||||
r'\foo.html')
|
r'\foo.html')
|
||||||
|
|
||||||
@pytest.mark.skipif(os.name != 'nt', reason="requires Windows")
|
@pytest.mark.windows
|
||||||
def test_attabspathwin_win(self, header_checker):
|
def test_attabspathwin_win(self, header_checker):
|
||||||
"""'attachment', specifying an absolute filename in the fs root.
|
"""'attachment', specifying an absolute filename in the fs root.
|
||||||
|
|
||||||
@ -791,7 +791,7 @@ class TestCharacterSet:
|
|||||||
"attachment; filename*=UTF-8''A-%2541.html",
|
"attachment; filename*=UTF-8''A-%2541.html",
|
||||||
'A-%41.html')
|
'A-%41.html')
|
||||||
|
|
||||||
@pytest.mark.skipif(os.name != 'posix', reason="requires POSIX")
|
@pytest.mark.posix
|
||||||
def test_attwithfn2231abspathdisguised_unix(self, header_checker):
|
def test_attwithfn2231abspathdisguised_unix(self, header_checker):
|
||||||
r"""'attachment', specifying a filename of \foo.html.
|
r"""'attachment', specifying a filename of \foo.html.
|
||||||
|
|
||||||
@ -801,7 +801,7 @@ class TestCharacterSet:
|
|||||||
"attachment; filename*=UTF-8''%5cfoo.html",
|
"attachment; filename*=UTF-8''%5cfoo.html",
|
||||||
r'\foo.html')
|
r'\foo.html')
|
||||||
|
|
||||||
@pytest.mark.skipif(os.name != 'nt', reason="requires Windows")
|
@pytest.mark.windows
|
||||||
def test_attwithfn2231abspathdisguised_win(self, header_checker):
|
def test_attwithfn2231abspathdisguised_win(self, header_checker):
|
||||||
r"""'attachment', specifying a filename of \foo.html.
|
r"""'attachment', specifying a filename of \foo.html.
|
||||||
|
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
"""The qutebrowser test suite contest file."""
|
"""The qutebrowser test suite contest file."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
import collections
|
import collections
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
@ -196,3 +198,22 @@ def config_stub(stubs):
|
|||||||
objreg.register('config', stub)
|
objreg.register('config', stub)
|
||||||
yield stub
|
yield stub
|
||||||
objreg.delete('config')
|
objreg.delete('config')
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_runtest_setup(item):
|
||||||
|
"""Add some custom markers."""
|
||||||
|
if not isinstance(item, item.Function):
|
||||||
|
return
|
||||||
|
|
||||||
|
if item.get_marker('posix') and os.name != 'posix':
|
||||||
|
pytest.skip("Requires a POSIX os.")
|
||||||
|
elif item.get_marker('windows') and os.name != 'nt':
|
||||||
|
pytest.skip("Requires Windows.")
|
||||||
|
elif item.get_marker('linux') and not sys.platform.startswith('linux'):
|
||||||
|
pytest.skip("Requires Linux.")
|
||||||
|
elif item.get_marker('osx') and os.name != 'darwin':
|
||||||
|
pytest.skip("Requires OS X.")
|
||||||
|
elif item.get_marker('not_frozen') and getattr(sys, 'frozen', False):
|
||||||
|
pytest.skip("Can't be run when frozen!")
|
||||||
|
elif item.get_marker('frozen') and not getattr(sys, 'frozen', False):
|
||||||
|
pytest.skip("Can only run when frozen!")
|
||||||
|
@ -33,10 +33,6 @@ from qutebrowser.misc import guiprocess
|
|||||||
# FIXME check statusbar messages
|
# FIXME check statusbar messages
|
||||||
|
|
||||||
|
|
||||||
no_frozen = pytest.mark.skipif(
|
|
||||||
getattr(sys, 'frozen', False), reason="Can't be executed when frozen.")
|
|
||||||
|
|
||||||
|
|
||||||
def _py_proc(code):
|
def _py_proc(code):
|
||||||
"""Get a python executable and args list which executes the given code."""
|
"""Get a python executable and args list which executes the given code."""
|
||||||
return (sys.executable, ['-c', textwrap.dedent(code.strip('\n'))])
|
return (sys.executable, ['-c', textwrap.dedent(code.strip('\n'))])
|
||||||
@ -68,7 +64,7 @@ def fake_proc(monkeypatch, stubs):
|
|||||||
return p
|
return p
|
||||||
|
|
||||||
|
|
||||||
@no_frozen
|
@pytest.mark.not_frozen
|
||||||
def test_start(proc, qtbot):
|
def test_start(proc, qtbot):
|
||||||
"""Test simply starting a process."""
|
"""Test simply starting a process."""
|
||||||
with qtbot.waitSignals([proc.started, proc.finished], raising=True,
|
with qtbot.waitSignals([proc.started, proc.finished], raising=True,
|
||||||
@ -80,7 +76,7 @@ def test_start(proc, qtbot):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('argv', [
|
@pytest.mark.parametrize('argv', [
|
||||||
no_frozen(_py_proc('import sys; sys.exit(0)')),
|
pytest.mark.not_frozen(_py_proc('import sys; sys.exit(0)')),
|
||||||
('does_not', 'exist'),
|
('does_not', 'exist'),
|
||||||
])
|
])
|
||||||
def test_start_detached(fake_proc, argv):
|
def test_start_detached(fake_proc, argv):
|
||||||
@ -90,7 +86,7 @@ def test_start_detached(fake_proc, argv):
|
|||||||
fake_proc._proc.startDetached.assert_called_with(*list(argv) + [None])
|
fake_proc._proc.startDetached.assert_called_with(*list(argv) + [None])
|
||||||
|
|
||||||
|
|
||||||
@no_frozen
|
@pytest.mark.not_frozen
|
||||||
def test_double_start(qtbot, proc):
|
def test_double_start(qtbot, proc):
|
||||||
"""Test starting a GUIProcess twice."""
|
"""Test starting a GUIProcess twice."""
|
||||||
with qtbot.waitSignal(proc.started, raising=True, timeout=2000):
|
with qtbot.waitSignal(proc.started, raising=True, timeout=2000):
|
||||||
@ -100,7 +96,7 @@ def test_double_start(qtbot, proc):
|
|||||||
proc.start('', [])
|
proc.start('', [])
|
||||||
|
|
||||||
|
|
||||||
@no_frozen
|
@pytest.mark.not_frozen
|
||||||
def test_double_start_finished(qtbot, proc):
|
def test_double_start_finished(qtbot, proc):
|
||||||
"""Test starting a GUIProcess twice (with the first call finished)."""
|
"""Test starting a GUIProcess twice (with the first call finished)."""
|
||||||
with qtbot.waitSignals([proc.started, proc.finished], raising=True,
|
with qtbot.waitSignals([proc.started, proc.finished], raising=True,
|
||||||
@ -127,7 +123,7 @@ def test_error(qtbot, proc):
|
|||||||
proc.start('this_does_not_exist_either', [])
|
proc.start('this_does_not_exist_either', [])
|
||||||
|
|
||||||
|
|
||||||
@no_frozen
|
@pytest.mark.not_frozen
|
||||||
def test_exit_unsuccessful(qtbot, proc):
|
def test_exit_unsuccessful(qtbot, proc):
|
||||||
with qtbot.waitSignal(proc.finished, raising=True, timeout=2000):
|
with qtbot.waitSignal(proc.finished, raising=True, timeout=2000):
|
||||||
proc.start(*_py_proc('import sys; sys.exit(0)'))
|
proc.start(*_py_proc('import sys; sys.exit(0)'))
|
||||||
|
@ -757,8 +757,7 @@ class TestPyQIODevice:
|
|||||||
with pytest.raises(io.UnsupportedOperation):
|
with pytest.raises(io.UnsupportedOperation):
|
||||||
pyqiodev.seek(0, whence)
|
pyqiodev.seek(0, whence)
|
||||||
|
|
||||||
@pytest.mark.skipif(getattr(sys, 'frozen', False),
|
@pytest.mark.not_frozen
|
||||||
reason="Can't be executed when frozen.")
|
|
||||||
def test_qprocess(self):
|
def test_qprocess(self):
|
||||||
"""Test PyQIODevice with a QProcess which is non-sequential.
|
"""Test PyQIODevice with a QProcess which is non-sequential.
|
||||||
|
|
||||||
@ -872,7 +871,7 @@ class TestPyQIODevice:
|
|||||||
pyqiodev_failing.write(b'x')
|
pyqiodev_failing.write(b'x')
|
||||||
assert str(excinfo.value) == 'Writing failed'
|
assert str(excinfo.value) == 'Writing failed'
|
||||||
|
|
||||||
@pytest.mark.skipif(os.name != 'posix', reason="Needs a POSIX OS.")
|
@pytest.mark.posix
|
||||||
@pytest.mark.skipif(not os.path.exists('/dev/full'),
|
@pytest.mark.skipif(not os.path.exists('/dev/full'),
|
||||||
reason="Needs /dev/full.")
|
reason="Needs /dev/full.")
|
||||||
def test_write_error_real(self):
|
def test_write_error_real(self):
|
||||||
|
@ -101,8 +101,7 @@ class TestWritableLocation:
|
|||||||
assert '\\' in loc
|
assert '\\' in loc
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(not sys.platform.startswith("linux"),
|
@pytest.mark.linux
|
||||||
reason="requires Linux")
|
|
||||||
@pytest.mark.usefixtures('no_cachedir_tag')
|
@pytest.mark.usefixtures('no_cachedir_tag')
|
||||||
class TestGetStandardDirLinux:
|
class TestGetStandardDirLinux:
|
||||||
|
|
||||||
@ -145,8 +144,7 @@ class TestGetStandardDirLinux:
|
|||||||
assert standarddir.cache() == expected
|
assert standarddir.cache() == expected
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(not sys.platform.startswith("win"),
|
@pytest.mark.windows
|
||||||
reason="requires Windows")
|
|
||||||
@pytest.mark.usefixtures('no_cachedir_tag')
|
@pytest.mark.usefixtures('no_cachedir_tag')
|
||||||
class TestGetStandardDirWindows:
|
class TestGetStandardDirWindows:
|
||||||
|
|
||||||
|
@ -112,15 +112,13 @@ class TestGitStr:
|
|||||||
commit_file_mock.side_effect = OSError
|
commit_file_mock.side_effect = OSError
|
||||||
assert version._git_str() is None
|
assert version._git_str() is None
|
||||||
|
|
||||||
@pytest.mark.skipif(getattr(sys, 'frozen', False),
|
@pytest.mark.not_frozen
|
||||||
reason="Can't be executed when frozen!")
|
|
||||||
def test_normal_successful(self, git_str_subprocess_fake):
|
def test_normal_successful(self, git_str_subprocess_fake):
|
||||||
"""Test with git returning a successful result."""
|
"""Test with git returning a successful result."""
|
||||||
git_str_subprocess_fake.retval = 'c0ffeebabe'
|
git_str_subprocess_fake.retval = 'c0ffeebabe'
|
||||||
assert version._git_str() == 'c0ffeebabe'
|
assert version._git_str() == 'c0ffeebabe'
|
||||||
|
|
||||||
@pytest.mark.skipif(not getattr(sys, 'frozen', False),
|
@pytest.mark.frozen
|
||||||
reason="Can only executed when frozen!")
|
|
||||||
def test_normal_successful_frozen(self, git_str_subprocess_fake):
|
def test_normal_successful_frozen(self, git_str_subprocess_fake):
|
||||||
"""Test with git returning a successful result."""
|
"""Test with git returning a successful result."""
|
||||||
# The value is defined in scripts/freeze_tests.py.
|
# The value is defined in scripts/freeze_tests.py.
|
||||||
@ -140,8 +138,7 @@ class TestGitStr:
|
|||||||
side_effect=OSError)
|
side_effect=OSError)
|
||||||
assert version._git_str() is None
|
assert version._git_str() is None
|
||||||
|
|
||||||
@pytest.mark.skipif(getattr(sys, 'frozen', False),
|
@pytest.mark.not_frozen
|
||||||
reason="Can't be executed when frozen!")
|
|
||||||
def test_normal_path_nofile(self, monkeypatch, caplog,
|
def test_normal_path_nofile(self, monkeypatch, caplog,
|
||||||
git_str_subprocess_fake, commit_file_mock):
|
git_str_subprocess_fake, commit_file_mock):
|
||||||
"""Test with undefined __file__ but available git-commit-id."""
|
"""Test with undefined __file__ but available git-commit-id."""
|
||||||
@ -511,17 +508,17 @@ class TestOsInfo:
|
|||||||
expected = ['OS Version: ?']
|
expected = ['OS Version: ?']
|
||||||
assert ret == expected
|
assert ret == expected
|
||||||
|
|
||||||
@pytest.mark.skipif(sys.platform != 'linux', reason="requires Linux")
|
@pytest.mark.linux
|
||||||
def test_linux_real(self):
|
def test_linux_real(self):
|
||||||
"""Make sure there are no exceptions with a real Linux."""
|
"""Make sure there are no exceptions with a real Linux."""
|
||||||
version._os_info()
|
version._os_info()
|
||||||
|
|
||||||
@pytest.mark.skipif(sys.platform != 'win32', reason="requires Windows")
|
@pytest.mark.windows
|
||||||
def test_windows_real(self):
|
def test_windows_real(self):
|
||||||
"""Make sure there are no exceptions with a real Windows."""
|
"""Make sure there are no exceptions with a real Windows."""
|
||||||
version._os_info()
|
version._os_info()
|
||||||
|
|
||||||
@pytest.mark.skipif(sys.platform != 'darwin', reason="requires OS X")
|
@pytest.mark.osx
|
||||||
def test_os_x_real(self):
|
def test_os_x_real(self):
|
||||||
"""Make sure there are no exceptions with a real OS X."""
|
"""Make sure there are no exceptions with a real OS X."""
|
||||||
version._os_info()
|
version._os_info()
|
||||||
|
6
tox.ini
6
tox.ini
@ -184,6 +184,12 @@ commands =
|
|||||||
norecursedirs = .tox .venv
|
norecursedirs = .tox .venv
|
||||||
markers =
|
markers =
|
||||||
gui: Tests using the GUI (e.g. spawning widgets)
|
gui: Tests using the GUI (e.g. spawning widgets)
|
||||||
|
posix: Tests which only can run on a POSIX OS.
|
||||||
|
windows: Tests which only can run on Windows.
|
||||||
|
linux: Tests which only can run on Linux.
|
||||||
|
osx: Tests which only can run on OS X.
|
||||||
|
not_frozen: Tests which can't be run if sys.frozen is True.
|
||||||
|
frozen: Tests which can only be run if sys.frozen is True.
|
||||||
flakes-ignore =
|
flakes-ignore =
|
||||||
UnusedImport
|
UnusedImport
|
||||||
UnusedVariable
|
UnusedVariable
|
||||||
|
Loading…
Reference in New Issue
Block a user