From c9f0a5d1ea45ab4acb5ed56b78ae6f3f69725659 Mon Sep 17 00:00:00 2001 From: Jason Madden Date: Thu, 2 Nov 2017 07:35:11 -0500 Subject: [PATCH] 100% for test_baseindex --- .coveragerc | 1 + src/zope/index/text/tests/test_baseindex.py | 33 ++++++++++----------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/.coveragerc b/.coveragerc index 7a62e4b..e782ec6 100644 --- a/.coveragerc +++ b/.coveragerc @@ -5,4 +5,5 @@ source = zope.index exclude_lines = pragma: no cover raise NotImplementedError + raise AssertionError if __name__ == '__main__': diff --git a/src/zope/index/text/tests/test_baseindex.py b/src/zope/index/text/tests/test_baseindex.py index 56165b3..60c5b25 100644 --- a/src/zope/index/text/tests/test_baseindex.py +++ b/src/zope/index/text/tests/test_baseindex.py @@ -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 @@ -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) @@ -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') @@ -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')), {}) @@ -341,7 +346,7 @@ 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('')), {}) @@ -349,7 +354,7 @@ def _faux_search_wids(wids): 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*')), {}) @@ -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('')), {}) @@ -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), - ))