Fix tests for object registry.
This commit is contained in:
parent
34a5ad48b2
commit
c19b8fe982
@ -29,6 +29,7 @@ from PyQt5.QtCore import Qt
|
|||||||
|
|
||||||
from qutebrowser.keyinput import basekeyparser
|
from qutebrowser.keyinput import basekeyparser
|
||||||
from qutebrowser.test import stubs, helpers
|
from qutebrowser.test import stubs, helpers
|
||||||
|
from qutebrowser.utils import objreg
|
||||||
|
|
||||||
|
|
||||||
CONFIG = {'input': {'timeout': 100}}
|
CONFIG = {'input': {'timeout': 100}}
|
||||||
@ -42,6 +43,10 @@ BINDINGS = {'test': {'<Ctrl-a>': 'ctrla',
|
|||||||
'test2': {'foo': 'bar', '<Ctrl+X>': 'ctrlx'}}
|
'test2': {'foo': 'bar', '<Ctrl+X>': 'ctrlx'}}
|
||||||
|
|
||||||
|
|
||||||
|
fake_keyconfig = mock.Mock(spec=['get_bindings_for'])
|
||||||
|
fake_keyconfig.get_bindings_for.side_effect = lambda s: BINDINGS[s]
|
||||||
|
|
||||||
|
|
||||||
def setUpModule():
|
def setUpModule():
|
||||||
"""Mock out some imports in basekeyparser."""
|
"""Mock out some imports in basekeyparser."""
|
||||||
basekeyparser.QObject = mock.Mock()
|
basekeyparser.QObject = mock.Mock()
|
||||||
@ -53,14 +58,6 @@ def tearDownModule():
|
|||||||
logging.disable(logging.NOTSET)
|
logging.disable(logging.NOTSET)
|
||||||
|
|
||||||
|
|
||||||
def _get_fake_application():
|
|
||||||
"""Construct a fake QApplication with a keyconfig."""
|
|
||||||
app = stubs.FakeQApplication()
|
|
||||||
app.keyconfig = mock.Mock(spec=['get_bindings_for'])
|
|
||||||
app.keyconfig.get_bindings_for.side_effect = lambda s: BINDINGS[s]
|
|
||||||
return app
|
|
||||||
|
|
||||||
|
|
||||||
class SplitCountTests(unittest.TestCase):
|
class SplitCountTests(unittest.TestCase):
|
||||||
|
|
||||||
"""Test the _split_count method.
|
"""Test the _split_count method.
|
||||||
@ -109,9 +106,12 @@ class ReadConfigTests(unittest.TestCase):
|
|||||||
"""Test reading the config."""
|
"""Test reading the config."""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
basekeyparser.QCoreApplication = _get_fake_application()
|
objreg.register('key-config', fake_keyconfig)
|
||||||
basekeyparser.usertypes.Timer = mock.Mock()
|
basekeyparser.usertypes.Timer = mock.Mock()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
objreg.delete('key-config')
|
||||||
|
|
||||||
def test_read_config_invalid(self):
|
def test_read_config_invalid(self):
|
||||||
"""Test reading config without setting it before."""
|
"""Test reading config without setting it before."""
|
||||||
kp = basekeyparser.BaseKeyParser()
|
kp = basekeyparser.BaseKeyParser()
|
||||||
@ -145,12 +145,15 @@ class SpecialKeysTests(unittest.TestCase):
|
|||||||
'qutebrowser.keyinput.basekeyparser.usertypes.Timer',
|
'qutebrowser.keyinput.basekeyparser.usertypes.Timer',
|
||||||
autospec=True)
|
autospec=True)
|
||||||
patcher.start()
|
patcher.start()
|
||||||
|
objreg.register('key-config', fake_keyconfig)
|
||||||
self.addCleanup(patcher.stop)
|
self.addCleanup(patcher.stop)
|
||||||
basekeyparser.QCoreApplication = _get_fake_application()
|
|
||||||
self.kp = basekeyparser.BaseKeyParser()
|
self.kp = basekeyparser.BaseKeyParser()
|
||||||
self.kp.execute = mock.Mock()
|
self.kp.execute = mock.Mock()
|
||||||
self.kp.read_config('test')
|
self.kp.read_config('test')
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
objreg.delete('key-config')
|
||||||
|
|
||||||
def test_valid_key(self):
|
def test_valid_key(self):
|
||||||
"""Test a valid special keyevent."""
|
"""Test a valid special keyevent."""
|
||||||
self.kp.handle(helpers.fake_keyevent(Qt.Key_A, Qt.ControlModifier))
|
self.kp.handle(helpers.fake_keyevent(Qt.Key_A, Qt.ControlModifier))
|
||||||
@ -181,7 +184,7 @@ class KeyChainTests(unittest.TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""Set up mocks and read the test config."""
|
"""Set up mocks and read the test config."""
|
||||||
basekeyparser.QCoreApplication = _get_fake_application()
|
objreg.register('key-config', fake_keyconfig)
|
||||||
self.timermock = mock.Mock()
|
self.timermock = mock.Mock()
|
||||||
basekeyparser.usertypes.Timer = mock.Mock(return_value=self.timermock)
|
basekeyparser.usertypes.Timer = mock.Mock(return_value=self.timermock)
|
||||||
self.kp = basekeyparser.BaseKeyParser(supports_chains=True,
|
self.kp = basekeyparser.BaseKeyParser(supports_chains=True,
|
||||||
@ -189,6 +192,9 @@ class KeyChainTests(unittest.TestCase):
|
|||||||
self.kp.execute = mock.Mock()
|
self.kp.execute = mock.Mock()
|
||||||
self.kp.read_config('test')
|
self.kp.read_config('test')
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
objreg.delete('key-config')
|
||||||
|
|
||||||
def test_valid_special_key(self):
|
def test_valid_special_key(self):
|
||||||
"""Test valid special key."""
|
"""Test valid special key."""
|
||||||
self.kp.handle(helpers.fake_keyevent(Qt.Key_A, Qt.ControlModifier))
|
self.kp.handle(helpers.fake_keyevent(Qt.Key_A, Qt.ControlModifier))
|
||||||
@ -246,7 +252,7 @@ class CountTests(unittest.TestCase):
|
|||||||
"""Test execute() with counts."""
|
"""Test execute() with counts."""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
basekeyparser.QCoreApplication = _get_fake_application()
|
objreg.register('key-config', fake_keyconfig)
|
||||||
basekeyparser.usertypes.Timer = mock.Mock()
|
basekeyparser.usertypes.Timer = mock.Mock()
|
||||||
self.kp = basekeyparser.BaseKeyParser(supports_chains=True,
|
self.kp = basekeyparser.BaseKeyParser(supports_chains=True,
|
||||||
supports_count=True)
|
supports_count=True)
|
||||||
@ -296,6 +302,9 @@ class CountTests(unittest.TestCase):
|
|||||||
self.kp.execute.assert_called_once_with('ccc', self.kp.Type.chain, 23)
|
self.kp.execute.assert_called_once_with('ccc', self.kp.Type.chain, 23)
|
||||||
self.assertEqual(self.kp._keystring, '')
|
self.assertEqual(self.kp._keystring, '')
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
objreg.delete('key-config')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user