Rewrite version.version() tests and test short arg.
This commit is contained in:
parent
e9b5c355d2
commit
6dbac1c047
@ -27,6 +27,7 @@ from unittest import mock
|
|||||||
|
|
||||||
from PyQt5.QtCore import pyqtSignal, QPoint, QProcess, QObject
|
from PyQt5.QtCore import pyqtSignal, QPoint, QProcess, QObject
|
||||||
from PyQt5.QtNetwork import QNetworkRequest
|
from PyQt5.QtNetwork import QNetworkRequest
|
||||||
|
from PyQt5.QtWidgets import QCommonStyle
|
||||||
|
|
||||||
|
|
||||||
class FakeKeyEvent:
|
class FakeKeyEvent:
|
||||||
@ -72,8 +73,10 @@ class FakeQApplication:
|
|||||||
|
|
||||||
"""Stub to insert as QApplication module."""
|
"""Stub to insert as QApplication module."""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, style=None):
|
||||||
self.instance = mock.Mock(return_value=self)
|
self.instance = mock.Mock(return_value=self)
|
||||||
|
self.style = mock.Mock(spec=QCommonStyle)
|
||||||
|
self.style().metaObject().className.return_value = style
|
||||||
|
|
||||||
|
|
||||||
class FakeUrl:
|
class FakeUrl:
|
||||||
|
@ -30,6 +30,7 @@ import builtins
|
|||||||
import types
|
import types
|
||||||
import importlib
|
import importlib
|
||||||
import logging
|
import logging
|
||||||
|
import textwrap
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -548,132 +549,80 @@ class FakeQSslSocket:
|
|||||||
return self._version
|
return self._version
|
||||||
|
|
||||||
|
|
||||||
class TestVersion:
|
@pytest.mark.parametrize('git_commit, harfbuzz, frozen, short', [
|
||||||
|
(True, True, False, False), # normal
|
||||||
|
(False, True, False, False), # no git commit
|
||||||
|
(True, False, False, False), # HARFBUZZ unset
|
||||||
|
(True, True, True, False), # frozen
|
||||||
|
(True, True, False, True), # short
|
||||||
|
(False, True, False, True), # short and no git commit
|
||||||
|
])
|
||||||
|
def test_version_output(git_commit, harfbuzz, frozen, short, stubs,
|
||||||
|
monkeypatch):
|
||||||
|
"""Test version.version()."""
|
||||||
|
patches = {
|
||||||
|
'qutebrowser.__version__': 'VERSION',
|
||||||
|
'_git_str': lambda: ('GIT COMMIT' if git_commit else None),
|
||||||
|
'platform.python_implementation': lambda: 'PYTHON IMPLEMENTATION',
|
||||||
|
'platform.python_version': lambda: 'PYTHON VERSION',
|
||||||
|
'QT_VERSION_STR': 'QT VERSION',
|
||||||
|
'qVersion': lambda: 'QT RUNTIME VERSION',
|
||||||
|
'PYQT_VERSION_STR': 'PYQT VERSION',
|
||||||
|
'_module_versions': lambda: ['MODULE VERSION 1', 'MODULE VERSION 2'],
|
||||||
|
'qWebKitVersion': lambda: 'WEBKIT VERSION',
|
||||||
|
'QSslSocket': FakeQSslSocket('SSL VERSION'),
|
||||||
|
'platform.platform': lambda: 'PLATFORM',
|
||||||
|
'platform.architecture': lambda: ('ARCHITECTURE', ''),
|
||||||
|
'_os_info': lambda: ['OS INFO 1', 'OS INFO 2'],
|
||||||
|
'QApplication': stubs.FakeQApplication(style='STYLE'),
|
||||||
|
}
|
||||||
|
|
||||||
"""Tests for version."""
|
for attr, val in patches.items():
|
||||||
|
monkeypatch.setattr('qutebrowser.utils.version.' + attr, val)
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
monkeypatch.setenv('DESKTOP_SESSION', 'DESKTOP')
|
||||||
def patch(self, monkeypatch):
|
|
||||||
"""Patch some sub-functions we're not interested in."""
|
|
||||||
monkeypatch.setattr('qutebrowser.utils.version._git_str', lambda: None)
|
|
||||||
monkeypatch.setattr('qutebrowser.utils.version._module_versions',
|
|
||||||
lambda: [])
|
|
||||||
monkeypatch.setattr('qutebrowser.utils.version._os_info', lambda: [])
|
|
||||||
|
|
||||||
def test_qutebrowser_version(self, monkeypatch):
|
if harfbuzz:
|
||||||
"""Test the qutebrowser version in the output."""
|
monkeypatch.setenv('QT_HARFBUZZ', 'HARFBUZZ')
|
||||||
monkeypatch.setattr(
|
else:
|
||||||
'qutebrowser.utils.version.qutebrowser.__version__', '23.42')
|
|
||||||
lines = version.version().splitlines()
|
|
||||||
assert lines[0] == 'qutebrowser v23.42'
|
|
||||||
|
|
||||||
def test_git_commit(self, monkeypatch):
|
|
||||||
"""Test the git commit in the output."""
|
|
||||||
monkeypatch.setattr('qutebrowser.utils.version._git_str',
|
|
||||||
lambda: 'deadbeef')
|
|
||||||
lines = version.version().splitlines()
|
|
||||||
assert lines[1] == 'Git commit: deadbeef'
|
|
||||||
|
|
||||||
def test_no_git_commit(self, monkeypatch):
|
|
||||||
"""Test the git commit with _git_str returning None."""
|
|
||||||
monkeypatch.setattr('qutebrowser.utils.version._git_str',
|
|
||||||
lambda: None)
|
|
||||||
lines = version.version().splitlines()
|
|
||||||
assert not lines[1].startswith('Git commit:')
|
|
||||||
|
|
||||||
def test_python_version(self, monkeypatch):
|
|
||||||
"""Test the python version in the output."""
|
|
||||||
monkeypatch.setattr(
|
|
||||||
'qutebrowser.utils.version.platform.python_implementation',
|
|
||||||
lambda: 'python_implementation')
|
|
||||||
monkeypatch.setattr(
|
|
||||||
'qutebrowser.utils.version.platform.python_version',
|
|
||||||
lambda: 'python_version')
|
|
||||||
lines = version.version().splitlines()
|
|
||||||
assert lines[2] == 'python_implementation: python_version'
|
|
||||||
|
|
||||||
def test_qt_version(self, monkeypatch):
|
|
||||||
"""Test the python version in the output."""
|
|
||||||
monkeypatch.setattr('qutebrowser.utils.version.QT_VERSION_STR', '12.3')
|
|
||||||
monkeypatch.setattr('qutebrowser.utils.version.qVersion',
|
|
||||||
lambda: '45.6')
|
|
||||||
lines = version.version().splitlines()
|
|
||||||
assert lines[3] == 'Qt: 12.3, runtime: 45.6'
|
|
||||||
|
|
||||||
def test_pyqt_version(self, monkeypatch):
|
|
||||||
"""Test the PyQt version in the output."""
|
|
||||||
monkeypatch.setattr('qutebrowser.utils.version.PYQT_VERSION_STR',
|
|
||||||
'78.9')
|
|
||||||
lines = version.version().splitlines()
|
|
||||||
assert lines[4] == 'PyQt: 78.9'
|
|
||||||
|
|
||||||
def test_style(self, monkeypatch):
|
|
||||||
"""Test the style in the output."""
|
|
||||||
lines = version.version().splitlines()
|
|
||||||
assert lines[5].startswith('Style: ')
|
|
||||||
|
|
||||||
def test_desktop_environment(self, monkeypatch):
|
|
||||||
"""Test the desktop environment in the output."""
|
|
||||||
monkeypatch.setenv('DESKTOP_SESSION', 'Blah')
|
|
||||||
lines = version.version().splitlines()
|
|
||||||
assert lines[6] == 'Desktop: Blah'
|
|
||||||
|
|
||||||
def test_module_versions(self, monkeypatch):
|
|
||||||
"""Test module versions in the output."""
|
|
||||||
monkeypatch.setattr('qutebrowser.utils.version._module_versions',
|
|
||||||
lambda: ['Hello', 'World'])
|
|
||||||
lines = version.version().splitlines()
|
|
||||||
assert (lines[7], lines[8]) == ('Hello', 'World')
|
|
||||||
|
|
||||||
def test_webkit_version(self, monkeypatch):
|
|
||||||
"""Test the webkit version in the output."""
|
|
||||||
monkeypatch.setattr('qutebrowser.utils.version.qWebKitVersion',
|
|
||||||
lambda: '567.1')
|
|
||||||
lines = version.version().splitlines()
|
|
||||||
assert lines[7] == 'Webkit: 567.1'
|
|
||||||
|
|
||||||
def test_harfbuzz_none(self, monkeypatch):
|
|
||||||
"""Test harfbuzz output with QT_HARFBUZZ unset."""
|
|
||||||
monkeypatch.delenv('QT_HARFBUZZ', raising=False)
|
monkeypatch.delenv('QT_HARFBUZZ', raising=False)
|
||||||
lines = version.version().splitlines()
|
|
||||||
assert lines[8] == 'Harfbuzz: system'
|
|
||||||
|
|
||||||
def test_harfbuzz_set(self, monkeypatch):
|
if frozen:
|
||||||
"""Test harfbuzz output with QT_HARFBUZZ set."""
|
monkeypatch.setattr(sys, 'frozen', True, raising=False)
|
||||||
monkeypatch.setenv('QT_HARFBUZZ', 'new')
|
else:
|
||||||
lines = version.version().splitlines()
|
monkeypatch.delattr(sys, 'frozen', raising=False)
|
||||||
assert lines[8] == 'Harfbuzz: new'
|
|
||||||
|
|
||||||
def test_ssl(self, monkeypatch):
|
template = textwrap.dedent("""
|
||||||
"""Test SSL version in the output."""
|
qutebrowser vVERSION
|
||||||
monkeypatch.setattr('qutebrowser.utils.version.QSslSocket',
|
{git_commit}
|
||||||
FakeQSslSocket('1.0.1'))
|
PYTHON IMPLEMENTATION: PYTHON VERSION
|
||||||
lines = version.version().splitlines()
|
Qt: QT VERSION, runtime: QT RUNTIME VERSION
|
||||||
assert lines[9] == 'SSL: 1.0.1'
|
PyQt: PYQT VERSION
|
||||||
|
""".lstrip('\n'))
|
||||||
|
|
||||||
@pytest.mark.parametrize('frozen, expected', [(True, 'Frozen: True'),
|
if git_commit:
|
||||||
(False, 'Frozen: False')])
|
substitutions = {'git_commit': 'Git commit: GIT COMMIT\n'}
|
||||||
def test_frozen(self, monkeypatch, frozen, expected):
|
else:
|
||||||
"""Test "Frozen: ..." in the version output."""
|
substitutions = {'git_commit': ''}
|
||||||
if frozen:
|
|
||||||
monkeypatch.setattr(sys, 'frozen', True, raising=False)
|
|
||||||
else:
|
|
||||||
monkeypatch.delattr(sys, 'frozen', raising=False)
|
|
||||||
lines = version.version().splitlines()
|
|
||||||
assert lines[11] == expected
|
|
||||||
|
|
||||||
def test_platform(self, monkeypatch):
|
if not short:
|
||||||
"""Test platform in the version output."""
|
template += textwrap.dedent("""
|
||||||
monkeypatch.setattr('qutebrowser.utils.version.platform.platform',
|
Style: STYLE
|
||||||
lambda: 'toaster')
|
Desktop: DESKTOP
|
||||||
monkeypatch.setattr('qutebrowser.utils.version.platform.architecture',
|
MODULE VERSION 1
|
||||||
lambda: ('64bit', ''))
|
MODULE VERSION 2
|
||||||
lines = version.version().splitlines()
|
Webkit: WEBKIT VERSION
|
||||||
assert lines[12] == 'Platform: toaster, 64bit'
|
Harfbuzz: {harfbuzz}
|
||||||
|
SSL: SSL VERSION
|
||||||
|
|
||||||
def test_os_info(self, monkeypatch):
|
Frozen: {frozen}
|
||||||
"""Test OS info in the output."""
|
Platform: PLATFORM, ARCHITECTURE
|
||||||
monkeypatch.setattr('qutebrowser.utils.version._os_info',
|
OS INFO 1
|
||||||
lambda: ['Hello', 'World'])
|
OS INFO 2
|
||||||
lines = version.version().splitlines()
|
""".lstrip('\n'))
|
||||||
assert (lines[13], lines[14]) == ('Hello', 'World')
|
|
||||||
|
substitutions['harfbuzz'] = 'HARFBUZZ' if harfbuzz else 'system'
|
||||||
|
substitutions['frozen'] = str(frozen)
|
||||||
|
|
||||||
|
expected = template.rstrip('\n').format(**substitutions)
|
||||||
|
assert version.version(short=short) == expected
|
||||||
|
Loading…
Reference in New Issue
Block a user