Add tests for history progress
This commit is contained in:
parent
e4b7786bcc
commit
ec774379bd
@ -125,6 +125,9 @@ class WebHistory(sql.SqlTable):
|
|||||||
completion: A CompletionHistory instance.
|
completion: A CompletionHistory instance.
|
||||||
metainfo: A CompletionMetaInfo instance.
|
metainfo: A CompletionMetaInfo instance.
|
||||||
_progress: A HistoryProgress instance.
|
_progress: A HistoryProgress instance.
|
||||||
|
|
||||||
|
Class attributes:
|
||||||
|
_PROGRESS_THRESHOLD: When to start showing progress dialogs.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# All web history cleared
|
# All web history cleared
|
||||||
@ -132,6 +135,8 @@ class WebHistory(sql.SqlTable):
|
|||||||
# one url cleared
|
# one url cleared
|
||||||
url_cleared = pyqtSignal(QUrl)
|
url_cleared = pyqtSignal(QUrl)
|
||||||
|
|
||||||
|
_PROGRESS_THRESHOLD = 1000
|
||||||
|
|
||||||
def __init__(self, progress, parent=None):
|
def __init__(self, progress, parent=None):
|
||||||
super().__init__("History", ['url', 'title', 'atime', 'redirect'],
|
super().__init__("History", ['url', 'title', 'atime', 'redirect'],
|
||||||
constraints={'url': 'NOT NULL',
|
constraints={'url': 'NOT NULL',
|
||||||
@ -203,7 +208,7 @@ class WebHistory(sql.SqlTable):
|
|||||||
'GROUP BY url ORDER BY atime asc')
|
'GROUP BY url ORDER BY atime asc')
|
||||||
entries = list(q.run())
|
entries = list(q.run())
|
||||||
|
|
||||||
if len(entries) > 1000:
|
if len(entries) > self._PROGRESS_THRESHOLD:
|
||||||
self._progress.start("Rebuilding completion...", len(entries))
|
self._progress.start("Rebuilding completion...", len(entries))
|
||||||
|
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
|
@ -41,14 +41,19 @@ class FakeHistoryProgress:
|
|||||||
|
|
||||||
"""Fake for a WebHistoryProgress object."""
|
"""Fake for a WebHistoryProgress object."""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self._started = False
|
||||||
|
self._finished = False
|
||||||
|
self._value = 0
|
||||||
|
|
||||||
def start(self, _text, _maximum):
|
def start(self, _text, _maximum):
|
||||||
pass
|
self._started = True
|
||||||
|
|
||||||
def tick(self):
|
def tick(self):
|
||||||
pass
|
self._value += 1
|
||||||
|
|
||||||
def finish(self):
|
def finish(self):
|
||||||
pass
|
self._finished = True
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
@ -515,6 +520,21 @@ class TestRebuild:
|
|||||||
config_stub.val.history_gap_interval = 1234
|
config_stub.val.history_gap_interval = 1234
|
||||||
assert not hist.metainfo['force_rebuild']
|
assert not hist.metainfo['force_rebuild']
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('patch_threshold', [True, False])
|
||||||
|
def test_progress(self, hist, config_stub, monkeypatch, patch_threshold):
|
||||||
|
hist.add_url(QUrl('example.com/1'), redirect=False, atime=1)
|
||||||
|
hist.add_url(QUrl('example.com/2'), redirect=False, atime=2)
|
||||||
|
hist.metainfo['force_rebuild'] = True
|
||||||
|
|
||||||
|
if patch_threshold:
|
||||||
|
monkeypatch.setattr(history.WebHistory, '_PROGRESS_THRESHOLD', 1)
|
||||||
|
|
||||||
|
progress = FakeHistoryProgress()
|
||||||
|
history.WebHistory(progress=progress)
|
||||||
|
assert progress._value == 2
|
||||||
|
assert progress._finished
|
||||||
|
assert progress._started == patch_threshold
|
||||||
|
|
||||||
|
|
||||||
class TestCompletionMetaInfo:
|
class TestCompletionMetaInfo:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user