summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <git@the-compiler.org>2016-07-23 14:03:08 +0200
committerFlorian Bruhin <git@the-compiler.org>2016-07-23 14:03:08 +0200
commit78fd614237f9da733f958a1247e2b48c4e466fb9 (patch)
tree4d139148be72eb7d4972e1b290446b933502e385
parent76eab7617b61bda58c4a80d7cbd4662f5ec7e784 (diff)
parentd1cc5428351533639c49ba2c3c8f32cda5407b5c (diff)
downloadqutebrowser-78fd614237f9da733f958a1247e2b48c4e466fb9.tar.gz
qutebrowser-78fd614237f9da733f958a1247e2b48c4e466fb9.zip
Merge branch 'ganwell-issue_1670_tests_fail_due_to_SSL_error'
-rw-r--r--README.asciidoc1
-rw-r--r--qutebrowser/misc/earlyinit.py5
-rw-r--r--qutebrowser/utils/log.py19
-rw-r--r--qutebrowser/utils/qtutils.py8
-rw-r--r--tests/unit/utils/test_log.py13
5 files changed, 42 insertions, 4 deletions
diff --git a/README.asciidoc b/README.asciidoc
index 12a114ca9..33a11911e 100644
--- a/README.asciidoc
+++ b/README.asciidoc
@@ -210,6 +210,7 @@ Contributors, sorted by the number of commits in descending order:
* Regina Hug
* Mathias Fussenegger
* Marcelo Santos
+* Jean-Louis Fuchs
* Fritz V155 Reichwald
* Franz Fellner
* zwarag
diff --git a/qutebrowser/misc/earlyinit.py b/qutebrowser/misc/earlyinit.py
index c2b631f96..c53492360 100644
--- a/qutebrowser/misc/earlyinit.py
+++ b/qutebrowser/misc/earlyinit.py
@@ -309,13 +309,14 @@ def earlyinit(args):
# Here we check if QtCore is available, and if not, print a message to the
# console or via Tk.
check_pyqt_core()
+ # Init logging as early as possible
+ init_log(args)
# Now the faulthandler is enabled we fix the Qt harfbuzzing library, before
# importing QtWidgets.
fix_harfbuzz(args)
# Now we can be sure QtCore is available, so we can print dialogs on
# errors, so people only using the GUI notice them as well.
check_qt_version()
- check_ssl_support()
remove_inputhook()
check_libraries(args)
- init_log(args)
+ check_ssl_support()
diff --git a/qutebrowser/utils/log.py b/qutebrowser/utils/log.py
index 7f67ae9f2..a1210caf0 100644
--- a/qutebrowser/utils/log.py
+++ b/qutebrowser/utils/log.py
@@ -167,9 +167,14 @@ def init_log(args):
root.addHandler(ram)
root.setLevel(logging.NOTSET)
logging.captureWarnings(True)
+ _init_py_warnings()
+ QtCore.qInstallMessageHandler(qt_message_handler)
+
+
+def _init_py_warnings():
+ """Initialize Python warning handling."""
warnings.simplefilter('default')
warnings.filterwarnings('ignore', module='pdb', category=ResourceWarning)
- QtCore.qInstallMessageHandler(qt_message_handler)
@contextlib.contextmanager
@@ -182,6 +187,14 @@ def disable_qt_msghandler():
QtCore.qInstallMessageHandler(old_handler)
+@contextlib.contextmanager
+def ignore_py_warnings(**kwargs):
+ """Contextmanager to temporarily hke certain Python warnings."""
+ warnings.filterwarnings('ignore', **kwargs)
+ yield
+ _init_py_warnings()
+
+
def _init_handlers(level, color, force_color, json_logging, ram_capacity):
"""Init log handlers.
@@ -330,6 +343,10 @@ def qt_message_handler(msg_type, context, msg):
"Image of format '' blocked because it is not considered safe. If you "
"are sure it is safe to do so, you can white-list the format by "
"setting the environment variable QTWEBKIT_IMAGEFORMAT_WHITELIST=",
+ # Installing Qt from the installer may cause it looking for SSL3 which
+ # may not be available on the system
+ "QSslSocket: cannot resolve SSLv3_client_method",
+ "QSslSocket: cannot resolve SSLv3_server_method",
]
if sys.platform == 'darwin':
suppressed_msgs += [
diff --git a/qutebrowser/utils/qtutils.py b/qutebrowser/utils/qtutils.py
index 4da9d48af..7d6da1dc6 100644
--- a/qutebrowser/utils/qtutils.py
+++ b/qutebrowser/utils/qtutils.py
@@ -33,11 +33,17 @@ import sys
import operator
import contextlib
-import pkg_resources
from PyQt5.QtCore import (qVersion, QEventLoop, QDataStream, QByteArray,
QIODevice, QSaveFile)
from PyQt5.QtWidgets import QApplication
+from qutebrowser.utils import log
+
+with log.ignore_py_warnings(category=PendingDeprecationWarning, module='imp'):
+ # This imports 'imp' and gives us a PendingDeprecationWarning on
+ # Debian Jessie.
+ import pkg_resources
+
MAXVALS = {
'int': 2 ** 31 - 1,
diff --git a/tests/unit/utils/test_log.py b/tests/unit/utils/test_log.py
index 5554717d9..4bf12c526 100644
--- a/tests/unit/utils/test_log.py
+++ b/tests/unit/utils/test_log.py
@@ -23,6 +23,7 @@ import logging
import argparse
import itertools
import sys
+import warnings
import pytest
import pytest_catchlog
@@ -36,6 +37,7 @@ def restore_loggers():
Based on CPython's Lib/test/test_logging.py.
"""
+ logging.captureWarnings(False)
logger_dict = logging.getLogger().manager.loggerDict
logging._acquireLock()
try:
@@ -278,3 +280,14 @@ def test_stub(caplog, suffix, expected):
log.stub(suffix)
assert len(caplog.records) == 1
assert caplog.records[0].message == expected
+
+
+def test_ignore_py_warnings(caplog):
+ logging.captureWarnings(True)
+ with log.ignore_py_warnings(category=UserWarning):
+ warnings.warn("hidden", UserWarning)
+ with caplog.at_level(logging.WARNING):
+ warnings.warn("not hidden", UserWarning)
+ assert len(caplog.records) == 1
+ msg = caplog.records[0].message.splitlines()[0]
+ assert msg.endswith("UserWarning: not hidden")