More tests for cmdhistory
This commit is contained in:
parent
26058f4e80
commit
18d42d1f0a
@ -29,7 +29,11 @@ class HistoryEmptyError(Exception):
|
|||||||
|
|
||||||
"""Raised when the history is empty."""
|
"""Raised when the history is empty."""
|
||||||
|
|
||||||
pass
|
def __init__(self, value):
|
||||||
|
self.value = value
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.value
|
||||||
|
|
||||||
|
|
||||||
class HistoryEndReachedError(Exception):
|
class HistoryEndReachedError(Exception):
|
||||||
@ -90,7 +94,7 @@ class History(QObject):
|
|||||||
else:
|
else:
|
||||||
items = self.history
|
items = self.history
|
||||||
if not items:
|
if not items:
|
||||||
raise HistoryEmptyError
|
raise HistoryEmptyError("History is empty.")
|
||||||
self._tmphist = usertypes.NeighborList(items)
|
self._tmphist = usertypes.NeighborList(items)
|
||||||
return self._tmphist.lastitem()
|
return self._tmphist.lastitem()
|
||||||
|
|
||||||
@ -109,7 +113,7 @@ class History(QObject):
|
|||||||
try:
|
try:
|
||||||
return self._tmphist.previtem()
|
return self._tmphist.previtem()
|
||||||
except IndexError:
|
except IndexError:
|
||||||
raise HistoryEndReachedError
|
raise HistoryEndReachedError("History end reached")
|
||||||
|
|
||||||
def nextitem(self):
|
def nextitem(self):
|
||||||
"""Get the next item in the temp history.
|
"""Get the next item in the temp history.
|
||||||
@ -121,7 +125,7 @@ class History(QObject):
|
|||||||
try:
|
try:
|
||||||
return self._tmphist.nextitem()
|
return self._tmphist.nextitem()
|
||||||
except IndexError:
|
except IndexError:
|
||||||
raise HistoryEndReachedError
|
raise HistoryEndReachedError("History end reached")
|
||||||
|
|
||||||
def append(self, text):
|
def append(self, text):
|
||||||
"""Append a new item to the history.
|
"""Append a new item to the history.
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from qutebrowser.misc.cmdhistory import History
|
from qutebrowser.misc.cmdhistory import History, HistoryEmptyError
|
||||||
|
|
||||||
|
|
||||||
HISTORY = ['first', 'second', 'third', 'fourth', 'fifth']
|
HISTORY = ['first', 'second', 'third', 'fourth', 'fifth']
|
||||||
@ -83,7 +83,7 @@ class TestBrowsing(TestCommandHistory):
|
|||||||
self.hist._tmphist = HISTORY
|
self.hist._tmphist = HISTORY
|
||||||
assert self.hist.is_browsing()
|
assert self.hist.is_browsing()
|
||||||
|
|
||||||
def test_start_stop_is_browsing(self):
|
def test_start_stop(self):
|
||||||
"""Test the start/stop."""
|
"""Test the start/stop."""
|
||||||
|
|
||||||
# We can use is_browsing() because it is tested above
|
# We can use is_browsing() because it is tested above
|
||||||
@ -92,3 +92,43 @@ class TestBrowsing(TestCommandHistory):
|
|||||||
assert self.hist.is_browsing()
|
assert self.hist.is_browsing()
|
||||||
self.hist.stop()
|
self.hist.stop()
|
||||||
assert not self.hist.is_browsing()
|
assert not self.hist.is_browsing()
|
||||||
|
|
||||||
|
def test_start_with_text(self):
|
||||||
|
"""Test start with given 'text'."""
|
||||||
|
self.hist.start('f')
|
||||||
|
assert 'first' in self.hist._tmphist
|
||||||
|
assert 'fourth' in self.hist._tmphist
|
||||||
|
assert 'second' not in self.hist._tmphist
|
||||||
|
|
||||||
|
def test_start_no_text(self):
|
||||||
|
"""Test start with no given text."""
|
||||||
|
self.hist.start('')
|
||||||
|
|
||||||
|
# There is probably a better way for NeighbourList?
|
||||||
|
for i in self.hist._tmphist:
|
||||||
|
assert i in HISTORY
|
||||||
|
|
||||||
|
for i in HISTORY:
|
||||||
|
assert i in self.hist._tmphist
|
||||||
|
|
||||||
|
def test_start_no_items(self):
|
||||||
|
"""Test start with no matching text."""
|
||||||
|
with pytest.raises(HistoryEmptyError) as excinfo:
|
||||||
|
self.hist.start('k')
|
||||||
|
assert str(excinfo.value) == "History is empty."
|
||||||
|
assert not self.hist._tmphist
|
||||||
|
|
||||||
|
def test_get_item(self):
|
||||||
|
"""Test __get_item__."""
|
||||||
|
for i in range(0, len(HISTORY)):
|
||||||
|
assert self.hist[i] == HISTORY[i]
|
||||||
|
|
||||||
|
def test_not_browsing_error(self):
|
||||||
|
"""Test that next/previtem throws a ValueError"""
|
||||||
|
with pytest.raises(ValueError) as error1:
|
||||||
|
self.hist.nextitem()
|
||||||
|
assert str(error1.value) == "Currently not browsing history"
|
||||||
|
|
||||||
|
with pytest.raises(ValueError) as error2:
|
||||||
|
self.hist.previtem()
|
||||||
|
assert str(error2.value) == "Currently not browsing history"
|
||||||
|
Loading…
Reference in New Issue
Block a user