Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
[#57] Test cases for DictCompleter.complete/__init__/__del__
Browse files Browse the repository at this point in the history
  • Loading branch information
iblislin committed Nov 11, 2015
1 parent e693b13 commit f1afd0e
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions zdict/test_completer.py
@@ -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)

2 comments on commit f1afd0e

@fkztw
Copy link
Member

@fkztw fkztw commented on f1afd0e Nov 18, 2015

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?

@iblislin
Copy link
Member Author

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

Please sign in to comment.