Merge utils.signals into utils.debug
This commit is contained in:
parent
6aff5fd374
commit
5996651a2f
@ -23,7 +23,7 @@ from functools import partial
|
||||
|
||||
from PyQt5.QtCore import QObject
|
||||
|
||||
from qutebrowser.utils.signals import dbg_signal
|
||||
from qutebrowser.utils.debug import dbg_signal
|
||||
from qutebrowser.widgets.webview import WebView
|
||||
from qutebrowser.utils.log import signals as logger
|
||||
|
||||
|
@ -27,6 +27,14 @@ from PyQt5.QtWidgets import QStyle, QFrame
|
||||
import qutebrowser.utils.debug as debug
|
||||
|
||||
|
||||
class FakeSignal:
|
||||
|
||||
"""Fake pyqtSignal stub which uses a mock to see if it was called."""
|
||||
|
||||
def __init__(self, name='fake'):
|
||||
self.signal = '2{}(int, int)'.format(name)
|
||||
|
||||
|
||||
class QEnumKeyTests(TestCase):
|
||||
|
||||
"""Tests for qenum_key."""
|
||||
@ -45,5 +53,33 @@ class QEnumKeyTests(TestCase):
|
||||
self.assertEqual(key, 'Sunken')
|
||||
|
||||
|
||||
class TestDebug(TestCase):
|
||||
|
||||
"""Test signal debug output functions."""
|
||||
|
||||
def setUp(self):
|
||||
self.signal = FakeSignal()
|
||||
|
||||
def test_signal_name(self):
|
||||
"""Test signal_name()."""
|
||||
self.assertEqual(debug.signal_name(self.signal), 'fake')
|
||||
|
||||
def test_dbg_signal(self):
|
||||
"""Test dbg_signal()."""
|
||||
self.assertEqual(debug.dbg_signal(self.signal, [23, 42]),
|
||||
'fake(23, 42)')
|
||||
|
||||
def test_dbg_signal_eliding(self):
|
||||
"""Test eliding in dbg_signal()."""
|
||||
self.assertEqual(debug.dbg_signal(self.signal,
|
||||
[12345678901234567890123]),
|
||||
'fake(1234567890123456789\u2026)')
|
||||
|
||||
def test_dbg_signal_newline(self):
|
||||
"""Test dbg_signal() with a newline."""
|
||||
self.assertEqual(debug.dbg_signal(self.signal, ['foo\nbar']),
|
||||
'fake(foo bar)')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -1,63 +0,0 @@
|
||||
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et
|
||||
|
||||
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
||||
#
|
||||
# This file is part of qutebrowser.
|
||||
#
|
||||
# qutebrowser is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# qutebrowser is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# pylint: disable=missing-docstring
|
||||
|
||||
"""Tests for signal utils."""
|
||||
|
||||
import unittest
|
||||
from unittest import TestCase
|
||||
|
||||
import qutebrowser.utils.signals as sigutils
|
||||
|
||||
|
||||
class FakeSignal:
|
||||
|
||||
"""Fake pyqtSignal stub which uses a mock to see if it was called."""
|
||||
|
||||
def __init__(self, name='fake'):
|
||||
self.signal = '2{}(int, int)'.format(name)
|
||||
|
||||
|
||||
class TestDebug(TestCase):
|
||||
|
||||
"""Test signal debug output functions."""
|
||||
|
||||
def setUp(self):
|
||||
self.signal = FakeSignal()
|
||||
|
||||
def test_signal_name(self):
|
||||
self.assertEqual(sigutils.signal_name(self.signal), 'fake')
|
||||
|
||||
def test_dbg_signal(self):
|
||||
self.assertEqual(sigutils.dbg_signal(self.signal, [23, 42]),
|
||||
'fake(23, 42)')
|
||||
|
||||
def test_dbg_signal_eliding(self):
|
||||
self.assertEqual(sigutils.dbg_signal(self.signal,
|
||||
[12345678901234567890123]),
|
||||
'fake(1234567890123456789\u2026)')
|
||||
|
||||
def test_dbg_signal_newline(self):
|
||||
self.assertEqual(sigutils.dbg_signal(self.signal, ['foo\nbar']),
|
||||
'fake(foo bar)')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
@ -19,12 +19,14 @@
|
||||
|
||||
"""Utilities used for debugging."""
|
||||
|
||||
import re
|
||||
import sys
|
||||
import types
|
||||
from functools import wraps
|
||||
|
||||
from PyQt5.QtCore import pyqtRemoveInputHook, QEvent, QCoreApplication
|
||||
|
||||
from qutebrowser.utils.misc import elide
|
||||
from qutebrowser.utils.log import misc as logger
|
||||
|
||||
|
||||
@ -146,3 +148,30 @@ def qenum_key(base, value):
|
||||
if isinstance(obj, klass) and obj == value:
|
||||
return name
|
||||
return None
|
||||
|
||||
|
||||
def signal_name(sig):
|
||||
"""Get a cleaned up name of a signal.
|
||||
|
||||
Args:
|
||||
sig: The pyqtSignal
|
||||
|
||||
Return:
|
||||
The cleaned up signal name.
|
||||
"""
|
||||
m = re.match(r'[0-9]+(.*)\(.*\)', sig.signal)
|
||||
return m.group(1)
|
||||
|
||||
|
||||
def dbg_signal(sig, args):
|
||||
"""Get a string representation of a signal for debugging.
|
||||
|
||||
Args:
|
||||
sig: A pyqtSignal.
|
||||
args: The arguments as list of strings.
|
||||
|
||||
Return:
|
||||
A human-readable string representation of signal/args.
|
||||
"""
|
||||
argstr = ', '.join([elide(str(a).replace('\n', ' '), 20) for a in args])
|
||||
return '{}({})'.format(signal_name(sig), argstr)
|
||||
|
@ -1,51 +0,0 @@
|
||||
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
||||
|
||||
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
||||
#
|
||||
# This file is part of qutebrowser.
|
||||
#
|
||||
# qutebrowser is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# qutebrowser is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""Utilities regarding signals."""
|
||||
|
||||
import re
|
||||
|
||||
from qutebrowser.utils.misc import elide
|
||||
|
||||
|
||||
def signal_name(sig):
|
||||
"""Get a cleaned up name of a signal.
|
||||
|
||||
Args:
|
||||
sig: The pyqtSignal
|
||||
|
||||
Return:
|
||||
The cleaned up signal name.
|
||||
"""
|
||||
m = re.match(r'[0-9]+(.*)\(.*\)', sig.signal)
|
||||
return m.group(1)
|
||||
|
||||
|
||||
def dbg_signal(sig, args):
|
||||
"""Get a string representation of a signal for debugging.
|
||||
|
||||
Args:
|
||||
sig: A pyqtSignal.
|
||||
args: The arguments as list of strings.
|
||||
|
||||
Return:
|
||||
A human-readable string representation of signal/args.
|
||||
"""
|
||||
argstr = ', '.join([elide(str(a).replace('\n', ' '), 20) for a in args])
|
||||
return '{}({})'.format(signal_name(sig), argstr)
|
Loading…
Reference in New Issue
Block a user