Get rid of utils.actute_warning
Only Ubuntu Trusty still uses Qt < 5.3, and the issue seems to be fixed there by now.
This commit is contained in:
parent
f86f9cd92a
commit
7ba01e6764
@ -133,7 +133,6 @@ def init(args, crash_handler):
|
||||
log.init.debug("Starting init...")
|
||||
qApp.setQuitOnLastWindowClosed(False)
|
||||
_init_icon()
|
||||
utils.actute_warning()
|
||||
|
||||
try:
|
||||
_init_modules(args, crash_handler)
|
||||
|
@ -158,37 +158,6 @@ def resource_filename(filename):
|
||||
return pkg_resources.resource_filename(qutebrowser.__name__, filename)
|
||||
|
||||
|
||||
def actute_warning():
|
||||
"""Display a warning about the dead_actute issue if needed."""
|
||||
# WORKAROUND (remove this when we bump the requirements to 5.3.0)
|
||||
# Non Linux OS' aren't affected
|
||||
if not sys.platform.startswith('linux'):
|
||||
return
|
||||
# If no compose file exists for some reason, we're not affected
|
||||
if not os.path.exists('/usr/share/X11/locale/en_US.UTF-8/Compose'):
|
||||
return
|
||||
# Qt >= 5.3 doesn't seem to be affected
|
||||
try:
|
||||
if qtutils.version_check('5.3'):
|
||||
return
|
||||
except ValueError: # pragma: no cover
|
||||
pass
|
||||
try:
|
||||
with open('/usr/share/X11/locale/en_US.UTF-8/Compose', 'r',
|
||||
encoding='utf-8') as f:
|
||||
for line in f:
|
||||
if '<dead_actute>' in line:
|
||||
if sys.stdout is not None:
|
||||
sys.stdout.flush()
|
||||
print("Note: If you got a 'dead_actute' warning above, "
|
||||
"that is not a bug in qutebrowser! See "
|
||||
"https://bugs.freedesktop.org/show_bug.cgi?id=69476 "
|
||||
"for details.")
|
||||
break
|
||||
except OSError:
|
||||
log.init.exception("Failed to read Compose file")
|
||||
|
||||
|
||||
def _get_color_percentage(a_c1, a_c2, a_c3, b_c1, b_c2, b_c3, percent):
|
||||
"""Get a color which is percent% interpolated between start and end.
|
||||
|
||||
|
@ -148,127 +148,6 @@ def test_resource_filename():
|
||||
assert f.read().splitlines()[0] == "Hello World!"
|
||||
|
||||
|
||||
class Patcher:
|
||||
|
||||
"""Helper for TestActuteWarning.
|
||||
|
||||
Attributes:
|
||||
monkeypatch: The pytest monkeypatch fixture.
|
||||
"""
|
||||
|
||||
def __init__(self, monkeypatch):
|
||||
self.monkeypatch = monkeypatch
|
||||
|
||||
def patch_platform(self, platform='linux'):
|
||||
"""Patch sys.platform."""
|
||||
self.monkeypatch.setattr(sys, 'platform', platform)
|
||||
|
||||
def patch_exists(self, exists=True):
|
||||
"""Patch os.path.exists."""
|
||||
self.monkeypatch.setattr(utils.os.path, 'exists', lambda path: exists)
|
||||
|
||||
def patch_version(self, version='5.2.0'):
|
||||
"""Patch Qt version."""
|
||||
self.monkeypatch.setattr(utils.qtutils, 'qVersion', lambda: version)
|
||||
|
||||
def patch_file(self, data):
|
||||
"""Patch open() to return the given data."""
|
||||
fake_file = io.StringIO(data)
|
||||
self.monkeypatch.setattr(utils, 'open',
|
||||
lambda filename, mode, encoding: fake_file,
|
||||
raising=False)
|
||||
|
||||
def patch_all(self, data):
|
||||
"""Patch everything so the issue would exist."""
|
||||
self.patch_platform()
|
||||
self.patch_exists()
|
||||
self.patch_version()
|
||||
self.patch_file(data)
|
||||
|
||||
|
||||
class TestActuteWarning:
|
||||
|
||||
"""Test actute_warning."""
|
||||
|
||||
@pytest.fixture
|
||||
def patcher(self, monkeypatch):
|
||||
"""Fixture providing a Patcher helper."""
|
||||
return Patcher(monkeypatch)
|
||||
|
||||
def test_non_linux(self, patcher, capsys):
|
||||
"""Test with a non-Linux OS."""
|
||||
patcher.patch_platform('toaster')
|
||||
utils.actute_warning()
|
||||
out, err = capsys.readouterr()
|
||||
assert not out
|
||||
assert not err
|
||||
|
||||
def test_no_compose(self, patcher, capsys):
|
||||
"""Test with no compose file."""
|
||||
patcher.patch_platform()
|
||||
patcher.patch_exists(False)
|
||||
utils.actute_warning()
|
||||
out, err = capsys.readouterr()
|
||||
assert not out
|
||||
assert not err
|
||||
|
||||
def test_newer_qt(self, patcher, capsys):
|
||||
"""Test with compose file but newer Qt version."""
|
||||
patcher.patch_platform()
|
||||
patcher.patch_exists()
|
||||
patcher.patch_version('5.4')
|
||||
utils.actute_warning()
|
||||
out, err = capsys.readouterr()
|
||||
assert not out
|
||||
assert not err
|
||||
|
||||
def test_no_match(self, patcher, capsys):
|
||||
"""Test with compose file and affected Qt but no match."""
|
||||
patcher.patch_all('foobar')
|
||||
utils.actute_warning()
|
||||
out, err = capsys.readouterr()
|
||||
assert not out
|
||||
assert not err
|
||||
|
||||
def test_empty(self, patcher, capsys):
|
||||
"""Test with empty compose file."""
|
||||
patcher.patch_all(None)
|
||||
utils.actute_warning()
|
||||
out, err = capsys.readouterr()
|
||||
assert not out
|
||||
assert not err
|
||||
|
||||
def test_match(self, patcher, capsys):
|
||||
"""Test with compose file and affected Qt and a match."""
|
||||
patcher.patch_all('foobar\n<dead_actute>\nbaz')
|
||||
utils.actute_warning()
|
||||
out, err = capsys.readouterr()
|
||||
assert out.startswith('Note: If you got a')
|
||||
assert not err
|
||||
|
||||
def test_match_stdout_none(self, monkeypatch, patcher, capsys):
|
||||
"""Test with a match and stdout being None."""
|
||||
patcher.patch_all('foobar\n<dead_actute>\nbaz')
|
||||
monkeypatch.setattr(sys, 'stdout', None)
|
||||
utils.actute_warning()
|
||||
|
||||
def test_unreadable(self, mocker, patcher, capsys, caplog):
|
||||
"""Test with an unreadable compose file."""
|
||||
patcher.patch_platform()
|
||||
patcher.patch_exists()
|
||||
patcher.patch_version()
|
||||
mocker.patch('qutebrowser.utils.utils.open', side_effect=OSError,
|
||||
create=True)
|
||||
|
||||
with caplog.at_level(logging.ERROR, 'init'):
|
||||
utils.actute_warning()
|
||||
|
||||
assert len(caplog.records) == 1
|
||||
assert caplog.records[0].message == 'Failed to read Compose file'
|
||||
out, _err = capsys.readouterr()
|
||||
assert not out
|
||||
|
||||
|
||||
class TestInterpolateColor:
|
||||
|
||||
"""Tests for interpolate_color.
|
||||
|
Loading…
Reference in New Issue
Block a user