summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorlufte <javier@lufte.net>2021-07-02 21:48:34 -0300
committerlufte <javier@lufte.net>2021-07-02 21:48:34 -0300
commitb75d23e0b1ad305a681847107bdaff5b870e1fef (patch)
tree4b66fb483e3a1f2ac0ffd09f6f2ce8d544ad0778 /tests
parent748c686bf002822c6031565780e46ee8a378cc8e (diff)
downloadqutebrowser-b75d23e0b1ad305a681847107bdaff5b870e1fef.tar.gz
qutebrowser-b75d23e0b1ad305a681847107bdaff5b870e1fef.zip
Fix histcategory unit tests
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/completion/test_histcategory.py28
1 files changed, 15 insertions, 13 deletions
diff --git a/tests/unit/completion/test_histcategory.py b/tests/unit/completion/test_histcategory.py
index e0a12943b..4e3b657e2 100644
--- a/tests/unit/completion/test_histcategory.py
+++ b/tests/unit/completion/test_histcategory.py
@@ -32,10 +32,11 @@ from qutebrowser.utils import usertypes
@pytest.fixture
-def hist(init_sql, config_stub):
+def hist(data_tmpdir, config_stub):
+ db = sql.Database(str(data_tmpdir / 'test_histcategory.db'))
config_stub.val.completion.timestamp_format = '%Y-%m-%d'
config_stub.val.completion.web_history.max_items = -1
- return sql.SqlTable('CompletionHistory', ['url', 'title', 'last_atime'])
+ return sql.SqlTable(db, 'CompletionHistory', ['url', 'title', 'last_atime'])
@pytest.mark.parametrize('pattern, before, after', [
@@ -99,7 +100,7 @@ def test_set_pattern(pattern, before, after, model_validator, hist):
"""Validate the filtering and sorting results of set_pattern."""
for row in before:
hist.insert({'url': row[0], 'title': row[1], 'last_atime': 1})
- cat = histcategory.HistoryCategory()
+ cat = histcategory.HistoryCategory(database=hist._database)
model_validator.set_model(cat)
cat.set_pattern(pattern)
model_validator.validate(after)
@@ -110,7 +111,7 @@ def test_set_pattern_repeated(model_validator, hist):
hist.insert({'url': 'example.com/foo', 'title': 'title1', 'last_atime': 1})
hist.insert({'url': 'example.com/bar', 'title': 'title2', 'last_atime': 1})
hist.insert({'url': 'example.com/baz', 'title': 'title3', 'last_atime': 1})
- cat = histcategory.HistoryCategory()
+ cat = histcategory.HistoryCategory(database=hist._database)
model_validator.set_model(cat)
cat.set_pattern('b')
@@ -143,7 +144,7 @@ def test_set_pattern_repeated(model_validator, hist):
], ids=['numbers', 'characters'])
def test_set_pattern_long(hist, message_mock, caplog, pattern):
hist.insert({'url': 'example.com/foo', 'title': 'title1', 'last_atime': 1})
- cat = histcategory.HistoryCategory()
+ cat = histcategory.HistoryCategory(database=hist._database)
with caplog.at_level(logging.ERROR):
cat.set_pattern(pattern)
msg = message_mock.getmsg(usertypes.MessageLevel.error)
@@ -153,7 +154,7 @@ def test_set_pattern_long(hist, message_mock, caplog, pattern):
@hypothesis.given(pat=strategies.text())
def test_set_pattern_hypothesis(hist, pat, caplog):
hist.insert({'url': 'example.com/foo', 'title': 'title1', 'last_atime': 1})
- cat = histcategory.HistoryCategory()
+ cat = histcategory.HistoryCategory(database=hist._database)
with caplog.at_level(logging.ERROR):
cat.set_pattern(pat)
@@ -202,7 +203,7 @@ def test_sorting(max_items, before, after, model_validator, hist, config_stub):
for url, title, atime in before:
timestamp = datetime.datetime.strptime(atime, '%Y-%m-%d').timestamp()
hist.insert({'url': url, 'title': title, 'last_atime': timestamp})
- cat = histcategory.HistoryCategory()
+ cat = histcategory.HistoryCategory(database=hist._database)
model_validator.set_model(cat)
cat.set_pattern('')
model_validator.validate(after)
@@ -211,7 +212,7 @@ def test_sorting(max_items, before, after, model_validator, hist, config_stub):
def test_remove_rows(hist, model_validator):
hist.insert({'url': 'foo', 'title': 'Foo', 'last_atime': 0})
hist.insert({'url': 'bar', 'title': 'Bar', 'last_atime': 0})
- cat = histcategory.HistoryCategory()
+ cat = histcategory.HistoryCategory(database=hist._database)
model_validator.set_model(cat)
cat.set_pattern('')
hist.delete('url', 'foo')
@@ -227,7 +228,7 @@ def test_remove_rows_fetch(hist):
'title': [str(i) for i in range(300)],
'last_atime': [0] * 300,
})
- cat = histcategory.HistoryCategory()
+ cat = histcategory.HistoryCategory(database=hist._database)
cat.set_pattern('')
# sanity check that we didn't fetch everything up front
@@ -245,20 +246,21 @@ def test_remove_rows_fetch(hist):
('%m/%d/%Y %H:%M', '02/27/2018 08:30'),
('', ''),
])
-def test_timestamp_fmt(fmt, expected, model_validator, config_stub, init_sql):
+def test_timestamp_fmt(fmt, expected, model_validator, config_stub, data_tmpdir):
"""Validate the filtering and sorting results of set_pattern."""
config_stub.val.completion.timestamp_format = fmt
- hist = sql.SqlTable('CompletionHistory', ['url', 'title', 'last_atime'])
+ db = sql.Database(str(data_tmpdir / 'test_timestamp_fmt.db'))
+ hist = sql.SqlTable(db, 'CompletionHistory', ['url', 'title', 'last_atime'])
atime = datetime.datetime(2018, 2, 27, 8, 30)
hist.insert({'url': 'foo', 'title': '', 'last_atime': atime.timestamp()})
- cat = histcategory.HistoryCategory()
+ cat = histcategory.HistoryCategory(database=hist._database)
model_validator.set_model(cat)
cat.set_pattern('')
model_validator.validate([('foo', '', expected)])
def test_skip_duplicate_set(message_mock, caplog, hist):
- cat = histcategory.HistoryCategory()
+ cat = histcategory.HistoryCategory(database=hist._database)
cat.set_pattern('foo')
cat.set_pattern('foobarbaz')
msg = caplog.messages[-1]