This repository has been archived by the owner on Jul 10, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#57] Test cases for DictCompleter.complete/__init__/__del__
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from pytest import raises | ||
from unittest.mock import patch, Mock | ||
from zdict.completer import DictCompleter | ||
|
||
|
||
@patch('zdict.completer.db') | ||
def test_DictCompleter_db_connect(db): | ||
''' | ||
Test case for DictCompleter init/del | ||
DictCompleter will connect to db when __init__, | ||
and close db when __del__. | ||
''' | ||
# init | ||
completer = DictCompleter() | ||
assert db.connect.called | ||
|
||
# del | ||
del completer | ||
assert db.close.called | ||
|
||
|
||
@patch('zdict.completer.Record') | ||
@patch('zdict.completer.db') | ||
def test_DictCompleter_complete(db, Record): | ||
''' | ||
Test case for DictCompleter.complete implemented with iterator | ||
''' | ||
# Assume our db contains following words | ||
Record.select().where.return_value = [ | ||
Mock(word='apple'), | ||
Mock(word='apply')] | ||
|
||
completer = DictCompleter() | ||
|
||
# init query | ||
ret = completer.complete('a', state=0) | ||
assert ret == 'apple' | ||
|
||
ret = completer.complete('a', state=1) | ||
assert ret == 'apply' | ||
|
||
with raises(StopIteration): | ||
completer.complete('a', state=2) |
f1afd0e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uh... why is it here not the
tests/
dir?f1afd0e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh... may i mis-placing it