Simplify arg handling in test_version_output
This commit is contained in:
parent
3c9de92d58
commit
94951d92a1
@ -799,18 +799,27 @@ def test_chromium_version_unpatched(qapp):
|
|||||||
assert version._chromium_version() not in ['', 'unknown', 'unavailable']
|
assert version._chromium_version() not in ['', 'unknown', 'unavailable']
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(['git_commit', 'frozen', 'style', 'with_webkit',
|
class VersionParams:
|
||||||
'known_distribution'], [
|
|
||||||
(True, False, True, True, True), # normal
|
def __init__(self, git_commit=True, frozen=False, style=True,
|
||||||
(False, False, True, True, True), # no git commit
|
with_webkit=True, known_distribution=True):
|
||||||
(True, True, True, True, True), # frozen
|
self.git_commit = git_commit
|
||||||
(True, True, False, True, True), # no style
|
self.frozen = frozen
|
||||||
(True, False, True, False, True), # no webkit
|
self.style = style
|
||||||
(True, False, True, 'ng', True), # QtWebKit-NG
|
self.with_webkit = with_webkit
|
||||||
(True, False, True, True, False), # unknown Linux distribution
|
self.known_distribution = known_distribution
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('params', [
|
||||||
|
VersionParams(),
|
||||||
|
VersionParams(git_commit=False),
|
||||||
|
VersionParams(frozen=True),
|
||||||
|
VersionParams(style=False),
|
||||||
|
VersionParams(with_webkit=False),
|
||||||
|
VersionParams(with_webkit='ng'),
|
||||||
|
VersionParams(known_distribution=False),
|
||||||
]) # pylint: disable=too-many-locals
|
]) # pylint: disable=too-many-locals
|
||||||
def test_version_output(git_commit, frozen, style, with_webkit,
|
def test_version_output(params, stubs, monkeypatch):
|
||||||
known_distribution, stubs, monkeypatch):
|
|
||||||
"""Test version.version()."""
|
"""Test version.version()."""
|
||||||
class FakeWebEngineProfile:
|
class FakeWebEngineProfile:
|
||||||
def httpUserAgent(self):
|
def httpUserAgent(self):
|
||||||
@ -820,7 +829,7 @@ def test_version_output(git_commit, frozen, style, with_webkit,
|
|||||||
patches = {
|
patches = {
|
||||||
'qutebrowser.__file__': os.path.join(import_path, '__init__.py'),
|
'qutebrowser.__file__': os.path.join(import_path, '__init__.py'),
|
||||||
'qutebrowser.__version__': 'VERSION',
|
'qutebrowser.__version__': 'VERSION',
|
||||||
'_git_str': lambda: ('GIT COMMIT' if git_commit else None),
|
'_git_str': lambda: ('GIT COMMIT' if params.git_commit else None),
|
||||||
'platform.python_implementation': lambda: 'PYTHON IMPLEMENTATION',
|
'platform.python_implementation': lambda: 'PYTHON IMPLEMENTATION',
|
||||||
'platform.python_version': lambda: 'PYTHON VERSION',
|
'platform.python_version': lambda: 'PYTHON VERSION',
|
||||||
'PYQT_VERSION_STR': 'PYQT VERSION',
|
'PYQT_VERSION_STR': 'PYQT VERSION',
|
||||||
@ -832,24 +841,25 @@ def test_version_output(git_commit, frozen, style, with_webkit,
|
|||||||
'platform.architecture': lambda: ('ARCHITECTURE', ''),
|
'platform.architecture': lambda: ('ARCHITECTURE', ''),
|
||||||
'_os_info': lambda: ['OS INFO 1', 'OS INFO 2'],
|
'_os_info': lambda: ['OS INFO 1', 'OS INFO 2'],
|
||||||
'_path_info': lambda: {'PATH DESC': 'PATH NAME'},
|
'_path_info': lambda: {'PATH DESC': 'PATH NAME'},
|
||||||
'QApplication': (stubs.FakeQApplication(style='STYLE') if style else
|
'QApplication': (stubs.FakeQApplication(style='STYLE')
|
||||||
|
if params.style else
|
||||||
stubs.FakeQApplication(instance=None)),
|
stubs.FakeQApplication(instance=None)),
|
||||||
'QLibraryInfo.location': (lambda _loc: 'QT PATH'),
|
'QLibraryInfo.location': (lambda _loc: 'QT PATH'),
|
||||||
}
|
}
|
||||||
|
|
||||||
substitutions = {
|
substitutions = {
|
||||||
'git_commit': '\nGit commit: GIT COMMIT' if git_commit else '',
|
'git_commit': '\nGit commit: GIT COMMIT' if params.git_commit else '',
|
||||||
'style': '\nStyle: STYLE' if style else '',
|
'style': '\nStyle: STYLE' if params.style else '',
|
||||||
'qt': 'QT VERSION',
|
'qt': 'QT VERSION',
|
||||||
'frozen': str(frozen),
|
'frozen': str(params.frozen),
|
||||||
'import_path': import_path,
|
'import_path': import_path,
|
||||||
}
|
}
|
||||||
|
|
||||||
if with_webkit:
|
if params.with_webkit:
|
||||||
patches['qWebKitVersion'] = lambda: 'WEBKIT VERSION'
|
patches['qWebKitVersion'] = lambda: 'WEBKIT VERSION'
|
||||||
patches['objects.backend'] = usertypes.Backend.QtWebKit
|
patches['objects.backend'] = usertypes.Backend.QtWebKit
|
||||||
patches['QWebEngineProfile'] = None
|
patches['QWebEngineProfile'] = None
|
||||||
if with_webkit == 'ng':
|
if params.with_webkit == 'ng':
|
||||||
backend = 'QtWebKit-NG'
|
backend = 'QtWebKit-NG'
|
||||||
patches['qtutils.is_qtwebkit_ng'] = lambda: True
|
patches['qtutils.is_qtwebkit_ng'] = lambda: True
|
||||||
else:
|
else:
|
||||||
@ -862,7 +872,7 @@ def test_version_output(git_commit, frozen, style, with_webkit,
|
|||||||
patches['QWebEngineProfile'] = FakeWebEngineProfile
|
patches['QWebEngineProfile'] = FakeWebEngineProfile
|
||||||
substitutions['backend'] = 'QtWebEngine (Chromium CHROMIUMVERSION)'
|
substitutions['backend'] = 'QtWebEngine (Chromium CHROMIUMVERSION)'
|
||||||
|
|
||||||
if known_distribution:
|
if params.known_distribution:
|
||||||
patches['distribution'] = lambda: version.DistributionInfo(
|
patches['distribution'] = lambda: version.DistributionInfo(
|
||||||
parsed=version.Distribution.arch, version=None,
|
parsed=version.Distribution.arch, version=None,
|
||||||
pretty='LINUX DISTRIBUTION', id='arch')
|
pretty='LINUX DISTRIBUTION', id='arch')
|
||||||
@ -877,7 +887,7 @@ def test_version_output(git_commit, frozen, style, with_webkit,
|
|||||||
for attr, val in patches.items():
|
for attr, val in patches.items():
|
||||||
monkeypatch.setattr('qutebrowser.utils.version.' + attr, val)
|
monkeypatch.setattr('qutebrowser.utils.version.' + attr, val)
|
||||||
|
|
||||||
if frozen:
|
if params.frozen:
|
||||||
monkeypatch.setattr(sys, 'frozen', True, raising=False)
|
monkeypatch.setattr(sys, 'frozen', True, raising=False)
|
||||||
else:
|
else:
|
||||||
monkeypatch.delattr(sys, 'frozen', raising=False)
|
monkeypatch.delattr(sys, 'frozen', raising=False)
|
||||||
|
Loading…
Reference in New Issue
Block a user