Move command-history init to cmdhistory.py
This commit is contained in:
parent
54214873f4
commit
e87a782411
@ -52,7 +52,7 @@ from qutebrowser.browser.webkit.network import networkmanager
|
||||
from qutebrowser.keyinput import macros
|
||||
from qutebrowser.mainwindow import mainwindow, prompt
|
||||
from qutebrowser.misc import (readline, ipc, savemanager, sessions,
|
||||
crashsignal, earlyinit, objects, sql)
|
||||
crashsignal, earlyinit, objects, sql, cmdhistory)
|
||||
from qutebrowser.misc import utilcmds # pylint: disable=unused-import
|
||||
from qutebrowser.utils import (log, version, message, utils, qtutils, urlutils,
|
||||
objreg, usertypes, standarddir, error)
|
||||
@ -419,6 +419,9 @@ def _init_modules(args, crash_handler):
|
||||
pre_text='Error initializing SQL')
|
||||
sys.exit(usertypes.Exit.err_init)
|
||||
|
||||
log.init.debug("Initializing command history...")
|
||||
cmdhistory.init()
|
||||
|
||||
log.init.debug("Initializing web history...")
|
||||
history.init(qApp)
|
||||
|
||||
|
@ -199,18 +199,6 @@ def init(config):
|
||||
state = StateConfig()
|
||||
objreg.register('state-config', state)
|
||||
|
||||
# We need to import this here because lineparser needs config.
|
||||
# FIXME:conf add this to the Command widget or something?
|
||||
from qutebrowser.misc import lineparser
|
||||
save_manager = objreg.get('save-manager')
|
||||
command_history = lineparser.LimitLineParser(
|
||||
standarddir.data(), 'cmd-history',
|
||||
limit='completion.cmd_history_max_items',
|
||||
parent=config)
|
||||
objreg.register('command-history', command_history)
|
||||
save_manager.add_saveable('command-history', command_history.save,
|
||||
command_history.changed)
|
||||
|
||||
# Set the QSettings path to something like
|
||||
# ~/.config/qutebrowser/qsettings/qutebrowser/qutebrowser.conf so it
|
||||
# doesn't overwrite our config.
|
||||
|
@ -21,7 +21,8 @@
|
||||
|
||||
from PyQt5.QtCore import pyqtSlot, pyqtSignal, QObject
|
||||
|
||||
from qutebrowser.utils import usertypes, log
|
||||
from qutebrowser.utils import usertypes, log, standarddir, objreg
|
||||
from qutebrowser.misc import lineparser
|
||||
|
||||
|
||||
class HistoryEmptyError(Exception):
|
||||
@ -129,3 +130,14 @@ class History(QObject):
|
||||
if not self.history or text != self.history[-1]:
|
||||
self.history.append(text)
|
||||
self.changed.emit()
|
||||
|
||||
|
||||
def init():
|
||||
"""Initialize the LimitLineParser storing the history."""
|
||||
save_manager = objreg.get('save-manager')
|
||||
command_history = lineparser.LimitLineParser(
|
||||
standarddir.data(), 'cmd-history',
|
||||
limit='completion.cmd_history_max_items')
|
||||
objreg.register('command-history', command_history)
|
||||
save_manager.add_saveable('command-history', command_history.save,
|
||||
command_history.changed)
|
||||
|
@ -869,7 +869,7 @@ def init_patch(qapp, fake_save_manager, monkeypatch, config_tmpdir,
|
||||
monkeypatch.setattr(config, 'key_instance', None)
|
||||
monkeypatch.setattr(config, '_change_filters', [])
|
||||
yield
|
||||
for obj in ['config-commands', 'state-config', 'command-history']:
|
||||
for obj in ['config-commands', 'state-config']:
|
||||
try:
|
||||
objreg.delete(obj)
|
||||
except KeyError:
|
||||
@ -906,8 +906,6 @@ def test_init(qtbot, init_patch, fake_save_manager, config_tmpdir,
|
||||
objreg.get('config-commands')
|
||||
assert isinstance(config.instance, config.Config)
|
||||
assert isinstance(config.key_instance, config.KeyConfig)
|
||||
fake_save_manager.add_saveable.assert_any_call(
|
||||
'command-history', unittest.mock.ANY, unittest.mock.ANY)
|
||||
fake_save_manager.add_saveable.assert_any_call(
|
||||
'state-config', unittest.mock.ANY)
|
||||
fake_save_manager.add_saveable.assert_any_call(
|
||||
|
@ -277,7 +277,6 @@ def init_patch(qapp, fake_save_manager, config_tmpdir, data_tmpdir,
|
||||
config_stub):
|
||||
yield
|
||||
objreg.delete('state-config')
|
||||
objreg.delete('command-history')
|
||||
|
||||
|
||||
def test_init(init_patch, config_tmpdir):
|
||||
|
@ -20,9 +20,12 @@
|
||||
|
||||
"""Tests for misc.cmdhistory.History."""
|
||||
|
||||
import unittest.mock
|
||||
|
||||
import pytest
|
||||
|
||||
from qutebrowser.misc import cmdhistory
|
||||
from qutebrowser.utils import objreg
|
||||
|
||||
|
||||
HISTORY = ['first', 'second', 'third', 'fourth', 'fifth']
|
||||
@ -167,3 +170,15 @@ def test_append_double(hist):
|
||||
hist.append('fifth')
|
||||
# assert that the new 'fifth' is not added
|
||||
assert hist.history[-2:] == ['fourth', 'fifth']
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def init_patch():
|
||||
yield
|
||||
objreg.delete('command-history')
|
||||
|
||||
|
||||
def test_init(init_patch, fake_save_manager, data_tmpdir, config_stub):
|
||||
cmdhistory.init()
|
||||
fake_save_manager.add_saveable.assert_any_call(
|
||||
'command-history', unittest.mock.ANY, unittest.mock.ANY)
|
||||
|
Loading…
Reference in New Issue
Block a user