Merge branch 'ganwell-issue_1670_tests_fail_due_to_SSL_error'

This commit is contained in:
Florian Bruhin 2016-07-23 14:03:08 +02:00
commit 78fd614237
5 changed files with 42 additions and 4 deletions

View File

@ -210,6 +210,7 @@ Contributors, sorted by the number of commits in descending order:
* Regina Hug * Regina Hug
* Mathias Fussenegger * Mathias Fussenegger
* Marcelo Santos * Marcelo Santos
* Jean-Louis Fuchs
* Fritz V155 Reichwald * Fritz V155 Reichwald
* Franz Fellner * Franz Fellner
* zwarag * zwarag

View File

@ -309,13 +309,14 @@ def earlyinit(args):
# Here we check if QtCore is available, and if not, print a message to the # Here we check if QtCore is available, and if not, print a message to the
# console or via Tk. # console or via Tk.
check_pyqt_core() check_pyqt_core()
# Init logging as early as possible
init_log(args)
# Now the faulthandler is enabled we fix the Qt harfbuzzing library, before # Now the faulthandler is enabled we fix the Qt harfbuzzing library, before
# importing QtWidgets. # importing QtWidgets.
fix_harfbuzz(args) fix_harfbuzz(args)
# Now we can be sure QtCore is available, so we can print dialogs on # 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. # errors, so people only using the GUI notice them as well.
check_qt_version() check_qt_version()
check_ssl_support()
remove_inputhook() remove_inputhook()
check_libraries(args) check_libraries(args)
init_log(args) check_ssl_support()

View File

@ -167,9 +167,14 @@ def init_log(args):
root.addHandler(ram) root.addHandler(ram)
root.setLevel(logging.NOTSET) root.setLevel(logging.NOTSET)
logging.captureWarnings(True) logging.captureWarnings(True)
_init_py_warnings()
QtCore.qInstallMessageHandler(qt_message_handler)
def _init_py_warnings():
"""Initialize Python warning handling."""
warnings.simplefilter('default') warnings.simplefilter('default')
warnings.filterwarnings('ignore', module='pdb', category=ResourceWarning) warnings.filterwarnings('ignore', module='pdb', category=ResourceWarning)
QtCore.qInstallMessageHandler(qt_message_handler)
@contextlib.contextmanager @contextlib.contextmanager
@ -182,6 +187,14 @@ def disable_qt_msghandler():
QtCore.qInstallMessageHandler(old_handler) 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): def _init_handlers(level, color, force_color, json_logging, ram_capacity):
"""Init log handlers. """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 " "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 " "are sure it is safe to do so, you can white-list the format by "
"setting the environment variable QTWEBKIT_IMAGEFORMAT_WHITELIST=", "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': if sys.platform == 'darwin':
suppressed_msgs += [ suppressed_msgs += [

View File

@ -33,11 +33,17 @@ import sys
import operator import operator
import contextlib import contextlib
import pkg_resources
from PyQt5.QtCore import (qVersion, QEventLoop, QDataStream, QByteArray, from PyQt5.QtCore import (qVersion, QEventLoop, QDataStream, QByteArray,
QIODevice, QSaveFile) QIODevice, QSaveFile)
from PyQt5.QtWidgets import QApplication 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 = { MAXVALS = {
'int': 2 ** 31 - 1, 'int': 2 ** 31 - 1,

View File

@ -23,6 +23,7 @@ import logging
import argparse import argparse
import itertools import itertools
import sys import sys
import warnings
import pytest import pytest
import pytest_catchlog import pytest_catchlog
@ -36,6 +37,7 @@ def restore_loggers():
Based on CPython's Lib/test/test_logging.py. Based on CPython's Lib/test/test_logging.py.
""" """
logging.captureWarnings(False)
logger_dict = logging.getLogger().manager.loggerDict logger_dict = logging.getLogger().manager.loggerDict
logging._acquireLock() logging._acquireLock()
try: try:
@ -278,3 +280,14 @@ def test_stub(caplog, suffix, expected):
log.stub(suffix) log.stub(suffix)
assert len(caplog.records) == 1 assert len(caplog.records) == 1
assert caplog.records[0].message == expected 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")