def _die(self, msg): """Abort the download and emit an error.""" assert not self.successful self._read_timer.stop() self.reply.downloadProgress.disconnect() self.reply.finished.disconnect() self.reply.error.disconnect() self.reply.readyRead.disconnect() self.error_msg = msg self.stats.finish() self.error.emit(msg) with log.hide_qt_warning('QNetworkReplyImplPrivate::error: Internal ' 'problem, this method must only be called ' 'once.'): # See https://codereview.qt-project.org/#/c/107863/ self.reply.abort() self.reply.deleteLater() self.reply = None self.done = True self.data_changed.emit() if self.fileobj is not None: try: self.fileobj.close() except OSError: log.downloads.exception("Error while closing file object")
def test_unfiltered(self, qt_logger, caplog): with log.hide_qt_warning("World", 'qt-tests'): with caplog.at_level(logging.WARNING, 'qt-tests'): qt_logger.warning("Hello World") assert len(caplog.records) == 1 record = caplog.records[0] assert record.levelname == 'WARNING' assert record.message == "Hello World"
def test_unfiltered(self, logger, caplog): """Test a message which is not filtered.""" with log.hide_qt_warning("World", 'qt-tests'): with caplog.atLevel(logging.WARNING, 'qt-tests'): logger.warning("Hello World") assert len(caplog.records()) == 1 record = caplog.records()[0] assert record.levelname == 'WARNING' assert record.message == "Hello World"
def _die(self, msg): """Abort the download and emit an error.""" assert not self.successful # Prevent actions if calling _die() twice. This might happen if the # error handler correctly connects, and the error occurs in init_reply # between reply.error.connect and the reply.error() check. In this # case, the connected error handlers will be called twice, once via the # direct error.emit() and once here in _die(). The stacks look like # this then: # <networkmanager error.emit> -> on_reply_error -> _die -> # self.error.emit() # and # [init_reply -> <single shot timer> ->] <lambda in init_reply> -> # self.error.emit() # which may lead to duplicate error messages (and failing tests) if self._dead: return self._dead = True self._read_timer.stop() self.reply.downloadProgress.disconnect() self.reply.finished.disconnect() self.reply.error.disconnect() self.reply.readyRead.disconnect() self.error_msg = msg self.stats.finish() self.error.emit(msg) with log.hide_qt_warning('QNetworkReplyImplPrivate::error: Internal ' 'problem, this method must only be called ' 'once.'): # See https://codereview.qt-project.org/#/c/107863/ self.reply.abort() self.reply.deleteLater() self.reply = None self.done = True self.data_changed.emit() if self.fileobj is not None: try: self.fileobj.close() except OSError: log.downloads.exception("Error while closing file object")
def _do_die(self): """Abort the download and emit an error.""" self._read_timer.stop() if self._reply is None: log.downloads.debug("Reply gone while dying") return self._reply.downloadProgress.disconnect() self._reply.finished.disconnect() self._reply.error.disconnect() self._reply.readyRead.disconnect() with log.hide_qt_warning('QNetworkReplyImplPrivate::error: Internal ' 'problem, this method must only be called ' 'once.'): # See https://codereview.qt-project.org/#/c/107863/ self._reply.abort() self._reply.deleteLater() self._reply = None if self.fileobj is not None: try: self.fileobj.close() except OSError: log.downloads.exception("Error while closing file object")
def test_filtered_start(self, logger, caplog): """Test a message which is filtered (match at line start).""" with log.hide_qt_warning("Hello", 'qt-tests'): with caplog.atLevel(logging.WARNING, 'qt-tests'): logger.warning("Hello World") assert not caplog.records()
def test_unfiltered(self): """Test a message which is not filtered.""" with log.hide_qt_warning("World", logger='qt-tests'): with self.assertLogs('qt-tests', logging.WARNING): qWarning("Hello World")
def test_filtered_whitespace(self, logger, caplog): """Test a message which is filtered (match with whitespace).""" with log.hide_qt_warning("Hello", 'qt-tests'): with caplog.at_level(logging.WARNING, 'qt-tests'): logger.warning(" Hello World ") assert not caplog.records
def test_filtered_exact(self): """Test a message which is filtered (exact match).""" with log.hide_qt_warning("Hello", logger='qt-tests'): qWarning("Hello")
def test_filtered_start(self, logger, caplog): """Test a message which is filtered (match at line start).""" with log.hide_qt_warning("Hello", 'qt-tests'): with caplog.at_level(logging.WARNING, 'qt-tests'): logger.warning("Hello World") assert not caplog.records
def test_filtered_whitespace(self): """Test a message which is filtered (match with whitespace).""" with log.hide_qt_warning("Hello", logger='qt-tests'): qWarning(" Hello World ")
def test_filtered_start(self): """Test a message which is filtered (match at line start).""" with log.hide_qt_warning("Hello", logger='qt-tests'): qWarning("Hello World")
def test_filtered(self, qt_logger, caplog, line): with log.hide_qt_warning("Hello", 'qt-tests'): with caplog.at_level(logging.WARNING, 'qt-tests'): qt_logger.warning(line) assert not caplog.records
def test_filtered_exact(self, logger, caplog): """Test a message which is filtered (exact match).""" with log.hide_qt_warning("Hello", 'qt-tests'): with caplog.at_level(logging.WARNING, 'qt-tests'): logger.warning("Hello") assert not caplog.records