Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vangheem committed Aug 20, 2015
1 parent d1f299a commit 9c0933d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/zope/index/field/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@ def index_doc(self, docid, value):
"""See interface IInjection"""
rev_index = self._rev_index
if docid in rev_index:
if docid in self._fwd_index.get(value, ()):
if value is not None and docid in self._fwd_index.get(value, ()):
# no need to index the doc, its already up to date
return
# unindex doc if present
self.unindex_doc(docid)

if value is not None:
# Insert into forward index.
set = self._fwd_index.get(value)
if set is None:
set = self.family.IF.TreeSet()
self._fwd_index[value] = set
set.insert(docid)
# Insert into forward index.
set = self._fwd_index.get(value)
if set is None:
set = self.family.IF.TreeSet()
self._fwd_index[value] = set
set.insert(docid)

# increment doc count
self._num_docs.change(1)
Expand Down
15 changes: 15 additions & 0 deletions src/zope/index/field/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,21 @@ def test_sort_badlimit(self):
result = index.sort(c1, limit=0)
self.assertRaises(ValueError, list, result)

def test_insert_none_value_does_not_raise_typeerror(self):
index = self._makeOne()
index.index_doc(1, None)

def test_insert_none_value_to_update_does_not_raise_typeerror(self):
index = self._makeOne()
index.index_doc(1, 5)
index.index_doc(1, None)

def test_insert_none_value_does_not_insert_into_forward_index(self):
index = self._makeOne()
index.index_doc(1, None)
self.assertEquals(len(index._fwd_index), 0)
self.assertEquals(len(index._rev_index), 1)

def test_suite():
return unittest.TestSuite((
doctest.DocFileSuite('README.txt', optionflags=doctest.ELLIPSIS),
Expand Down

0 comments on commit 9c0933d

Please sign in to comment.