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
* Mathias Fussenegger
* Marcelo Santos
* Jean-Louis Fuchs
* Fritz V155 Reichwald
* Franz Fellner
* 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
# 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()

View File

@ -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 += [

View File

@ -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,

View File

@ -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")