Skip to content

Commit

Permalink
100% for test_baseindex
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Nov 2, 2017
1 parent 15fa1f0 commit c9f0a5d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Expand Up @@ -5,4 +5,5 @@ source = zope.index
exclude_lines =
pragma: no cover
raise NotImplementedError
raise AssertionError
if __name__ == '__main__':
33 changes: 16 additions & 17 deletions src/zope/index/text/tests/test_baseindex.py
Expand Up @@ -15,8 +15,13 @@
"""
import unittest

class BaseIndexTestBase:
# Subclasses must define '_getBTreesFamily'
# pylint:disable=protected-access,abstract-method

class BaseIndexTestMixin:

def _getBTreesFamily(self):
raise NotImplementedError()

def _getTargetClass(self):
from zope.index.text.baseindex import BaseIndex
return BaseIndex
Expand Down Expand Up @@ -87,14 +92,14 @@ def test_clear_doesnt_lose_family(self):
def test_wordCount_method_raises_NotImplementedError(self):
class DerviedDoesntSet_wordCount(self._getTargetClass()):
def __init__(self):
pass
"""Intentionally not calling super"""
index = DerviedDoesntSet_wordCount()
self.assertRaises(NotImplementedError, index.wordCount)

def test_documentCount_method_raises_NotImplementedError(self):
class DerviedDoesntSet_documentCount(self._getTargetClass()):
def __init__(self):
pass
"""Intentionally not calling super"""
index = DerviedDoesntSet_documentCount()
self.assertRaises(NotImplementedError, index.documentCount)

Expand Down Expand Up @@ -177,7 +182,7 @@ def _faux_get_frequencies(wids):

# Don't mutate _wordinfo if no changes
def _dont_go_here(*args, **kw):
assert 0
raise AssertionError("Should not be called")
index._add_wordinfo = index._del_wordinfo = _dont_go_here

count = index._reindex_doc(1, 'one two three')
Expand Down Expand Up @@ -318,7 +323,7 @@ def test_search_w_empty_term(self):
def test_search_w_oov_term(self):
index = self._makeOne()
def _faux_search_wids(wids):
assert len(wids) == 0
assert not wids
return []
index._search_wids = _faux_search_wids
self.assertEqual(dict(index.search('nonesuch')), {})
Expand All @@ -341,15 +346,15 @@ def _faux_search_wids(wids):
def test_search_glob_w_empty_term(self):
index = self._makeOne()
def _faux_search_wids(wids):
assert len(wids) == 0
assert not wids
return []
index._search_wids = _faux_search_wids
self.assertEqual(dict(index.search_glob('')), {})

def test_search_glob_w_oov_term(self):
index = self._makeOne()
def _faux_search_wids(wids):
assert len(wids) == 0
assert not wids
return []
index._search_wids = _faux_search_wids
self.assertEqual(dict(index.search_glob('nonesuch*')), {})
Expand All @@ -372,7 +377,7 @@ def _faux_search_wids(wids):
def test_search_phrase_w_empty_term(self):
index = self._makeOne()
def _faux_search_wids(wids):
assert len(wids) == 0
assert not wids
return []
index._search_wids = _faux_search_wids
self.assertEqual(dict(index.search_phrase('')), {})
Expand Down Expand Up @@ -466,20 +471,14 @@ def test__del_wordinfo_upgrades_wordCount(self):
index._del_wordinfo(123, 1)
self.assertEqual(index.wordCount(), 0)

class BaseIndexTest32(BaseIndexTestBase, unittest.TestCase):
class BaseIndexTest32(BaseIndexTestMixin, unittest.TestCase):

def _getBTreesFamily(self):
import BTrees
return BTrees.family32

class BaseIndexTest64(BaseIndexTestBase, unittest.TestCase):
class BaseIndexTest64(BaseIndexTestMixin, unittest.TestCase):

def _getBTreesFamily(self):
import BTrees
return BTrees.family64

def test_suite():
return unittest.TestSuite((
unittest.makeSuite(BaseIndexTest32),
unittest.makeSuite(BaseIndexTest64),
))

0 comments on commit c9f0a5d

Please sign in to comment.