Skip to content
Browse files

coverage and removal of bw compat code

  • Loading branch information...
1 parent a303bf1 commit c96fb3155456a6564f014efd8edce4bd659a645e @mcdonc mcdonc committed Jun 18, 2012
View
7 hypatia/facet/__init__.py
@@ -1,9 +1,4 @@
-try:
- from hashlib import md5
-except: # pragma no cover
- from md5 import new as md5
-
-from persistent import Persistent
+from hashlib import md5
from zope.interface import implementer
from ..keyword import KeywordIndex
View
18 hypatia/field/tests.py
@@ -1,18 +1,3 @@
-##############################################################################
-#
-# Copyright (c) 2002 Zope Foundation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Test field index
-"""
import unittest
import doctest
@@ -1114,6 +1099,3 @@ def test_suite():
doctest.DocFileSuite('README.txt', optionflags=doctest.ELLIPSIS),
unittest.makeSuite(FieldIndexTests),
))
-
-if __name__=='__main__':
- unittest.main(defaultTest='test_suite')
View
1 hypatia/keyword/__init__.py
@@ -6,7 +6,6 @@
from persistent import Persistent
from BTrees.Length import Length
-from ZODB.broken import Broken
from hypatia.interfaces import IInjection, IStatistics, IIndexSearch
from .interfaces import IKeywordQuerying
View
5 hypatia/keyword/tests.py
@@ -565,8 +565,3 @@ def _forbidden(self, *args, **kw):
assert 0 # pragma: no cover
__setitem__ = __delitem__ = clear = update = _forbidden
-def test_suite():
- return unittest.TestSuite((
- unittest.makeSuite(KeywordIndexTests32),
- unittest.makeSuite(KeywordIndexTests64),
- ))
View
2 hypatia/path/__init__.py
@@ -9,7 +9,7 @@
_marker = ()
@implementer(ICatalogIndex)
-class CatalogPathIndex(CatalogIndex):
+class CatalogPathIndex(CatalogIndex, Persistent):
"""Index for model paths (tokens separated by '/' characters)
View
5 hypatia/query/__init__.py
@@ -4,6 +4,8 @@
_marker = object()
+from ..util import RichComparisonMixin
+
class Query(object):
"""
@@ -269,7 +271,7 @@ def __str__(self):
return '%s not in all(%s)' % (self.index_name, repr(self._value))
-class _Range(Comparator):
+class _Range(Comparator, RichComparisonMixin):
@classmethod
def fromGTLT(cls, start, end):
@@ -338,7 +340,6 @@ def __eq__(self, other):
self.start_exclusive == other.start_exclusive and
self.end_exclusive == other.end_exclusive)
-
class InRange(_Range):
""" Index value falls within a range.
View
6 hypatia/tests/test_functional.py
@@ -47,12 +47,6 @@ class TestQueryWithPythonQueryObjects(unittest.TestCase, TestQueryBase):
)
-try:
- import ast
-except ImportError: #pragma NO COVERAGE
- del TestQueryWithCQE
- del TestQueryWithPythonQueryObjects
-
class Content(object):
def __init__(self, name, title, text, allowed):
self.name = name
View
2 hypatia/text/__init__.py
@@ -18,8 +18,6 @@
from persistent import Persistent
from zope.interface import implementer
-from ZODB.broken import Broken
-
from hypatia.interfaces import (
IIndexSearch,
IInjection,
View
7 hypatia/text/tests/test_baseindex.py
@@ -176,7 +176,7 @@ def _faux_get_frequencies(wids):
index.index_doc(1, 'one two three')
# Don't mutate _wordinfo if no changes
- def _dont_go_here(*args, **kw):
+ def _dont_go_here(*args, **kw): # pragma: no cover
assert 0
index._add_wordinfo = index._del_wordinfo = _dont_go_here
@@ -478,8 +478,3 @@ def _getBTreesFamily(self):
import BTrees
return BTrees.family64
-def test_suite():
- return unittest.TestSuite((
- unittest.makeSuite(BaseIndexTest32),
- unittest.makeSuite(BaseIndexTest64),
- ))
View
5 hypatia/text/tests/test_cosineindex.py
@@ -117,8 +117,3 @@ def _getBTreesFamily(self):
import BTrees
return BTrees.family64
-def test_suite():
- return unittest.TestSuite((
- unittest.makeSuite(CosineIndexTest32),
- unittest.makeSuite(CosineIndexTest64),
- ))
View
8 hypatia/text/tests/test_htmlsplitter.py
@@ -52,11 +52,11 @@ def test_process_w_locale_awareness(self):
self._old_locale = locale.setlocale(locale.LC_ALL)
# set German locale
try:
- if sys.platform == 'win32':
+ if sys.platform == 'win32': # pragma: no cover
locale.setlocale(locale.LC_ALL, 'German_Germany.1252')
else:
locale.setlocale(locale.LC_ALL, 'de_DE.ISO8859-1')
- except locale.Error:
+ except locale.Error: # pragma: no cove
return # This test doesn't work here :-(
expected = ['m\xfclltonne', 'waschb\xe4r',
'beh\xf6rde', '\xfcberflieger']
@@ -97,7 +97,3 @@ def test_processGlob_no_markup_w_glob(self):
self.assertEqual(splitter.processGlob(['abc?def hij*klm nop* qrs?']),
['abc?def', 'hij*klm', 'nop*', 'qrs?'])
-def test_suite():
- return unittest.TestSuite((
- unittest.makeSuite(HTMLWordSplitterTests),
- ))
View
7 hypatia/text/tests/test_index.py
@@ -214,10 +214,3 @@ def _getBTreesFamily(self):
import BTrees
return BTrees.family64
-def test_suite():
- return unittest.TestSuite((
- unittest.makeSuite(CosineIndexTest32),
- unittest.makeSuite(OkapiIndexTest32),
- unittest.makeSuite(CosineIndexTest64),
- unittest.makeSuite(OkapiIndexTest64),
- ))
View
12 hypatia/text/tests/test_lexicon.py
@@ -247,11 +247,11 @@ def test_process_w_locale_awareness(self):
self._old_locale = locale.setlocale(locale.LC_ALL)
# set German locale
try:
- if sys.platform == 'win32':
+ if sys.platform == 'win32': # pragma: no cover
locale.setlocale(locale.LC_ALL, 'German_Germany.1252')
else:
locale.setlocale(locale.LC_ALL, 'de_DE.ISO8859-1')
- except locale.Error:
+ except locale.Error: # pragma: no cover
return # This test doesn't work here :-(
expected = ['m\xfclltonne', 'waschb\xe4r',
'beh\xf6rde', '\xfcberflieger']
@@ -404,11 +404,3 @@ def process(self, seq):
res.append(term)
return res
-def test_suite():
- return unittest.TestSuite((
- unittest.makeSuite(LexiconTests),
- unittest.makeSuite(SplitterTests),
- unittest.makeSuite(CaseNormalizerTests),
- unittest.makeSuite(StopWordRemoverTests),
- unittest.makeSuite(StopWordAndSingleCharRemoverTests),
- ))
View
5 hypatia/text/tests/test_okapiindex.py
@@ -150,8 +150,3 @@ def _getBTreesFamily(self):
import BTrees
return BTrees.family64
-def test_suite():
- return unittest.TestSuite((
- unittest.makeSuite(OkapiIndexTest32),
- unittest.makeSuite(OkapiIndexTest64),
- ))
View
31 hypatia/text/tests/test_parsetree.py
@@ -1,17 +1,3 @@
-##############################################################################
-#
-# Copyright (c) 2009 Zope Foundation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-
import unittest
class ConformsToIQueryParseTree:
@@ -254,33 +240,18 @@ def __init__(self, *terms):
self._terms = terms[:]
def terms(self):
return self._terms
- def __eq__(self, other):
- return self._terms == other._terms
def __repr__(self):
return 'FV:%s' % ' '.join(self._terms)
class FauxSubnode:
- def __init__(self, node_type, query_results, value=None):
+ def __init__(self, node_type, query_results):
self._nodeType = node_type
self._query_results = query_results
- self._value = value
def nodeType(self):
return self._nodeType
def executeQuery(self, index):
return self._query_results
def getValue(self):
- if self._value is not None:
- return self._value
return self
-def test_suite():
- return unittest.TestSuite((
- unittest.makeSuite(ParseTreeNodeTests),
- unittest.makeSuite(NotNodeTests),
- unittest.makeSuite(AndNodeTests),
- unittest.makeSuite(OrNodeTests),
- unittest.makeSuite(AtomNodeTests),
- unittest.makeSuite(PhraseNodeTests),
- unittest.makeSuite(GlobNodeTests),
- ))
View
2 hypatia/text/tests/test_queryengine.py
@@ -73,5 +73,3 @@ def testInvalidQuery(self):
tree = NotNode(AtomNode("foo"))
self.assertRaises(QueryError, tree.executeQuery, index)
-def test_suite():
- return unittest.makeSuite(TestQueryEngine)
View
5 hypatia/text/tests/test_queryparser.py
@@ -417,8 +417,3 @@ def process(self, list):
return [word for word in list if word != "stop"]
-def test_suite():
- return unittest.TestSuite((
- unittest.makeSuite(TestQueryParser),
- unittest.makeSuite(StopWordTestQueryParser),
- ))
View
5 hypatia/text/tests/test_setops.py
@@ -259,8 +259,3 @@ def test_many(self):
got = self._callFUT(L)
self.assertEqual(expected, list(got.items()))
-def test_suite():
- return unittest.TestSuite((
- unittest.makeSuite(Test_mass_weightedIntersection),
- unittest.makeSuite(Test_mass_weightedUnion),
- ))
View
39 hypatia/text/tests/test_textindex.py
@@ -23,7 +23,8 @@ def _getTargetClass(self):
from .. import TextIndex
return TextIndex
- def _makeOne(self, discriminator=_marker, lexicon=_marker, index=_marker):
+ def _makeOne(self, discriminator=_marker, lexicon=_marker, index=_marker,
+ family=None):
def _discriminator(obj, default):
if obj is _marker:
return default
@@ -32,34 +33,20 @@ def _discriminator(obj, default):
discriminator = _discriminator
if lexicon is _marker:
if index is _marker: # defaults
- return self._getTargetClass()(discriminator=discriminator)
+ return self._getTargetClass()(discriminator=discriminator,
+ family=family)
else:
return self._getTargetClass()(discriminator=discriminator,
- index=index)
+ index=index, family=family)
else:
if index is _marker:
return self._getTargetClass()(discriminator=discriminator,
- lexicon=lexicon)
+ lexicon=lexicon, family=family)
else:
return self._getTargetClass()(discriminator=discriminator,
lexicon=lexicon,
- index=index)
-
- def _makeLexicon(self, *pipeline):
- from ..lexicon import Lexicon
- from ..lexicon import Splitter
- if not pipeline:
- pipeline = (Splitter(),)
- return Lexicon(*pipeline)
-
- def _makeOkapi(self, lexicon=None, family=None):
- import BTrees
- from ..okapiindex import OkapiIndex
- if lexicon is None:
- lexicon = self._makeLexicon()
- if family is None:
- family = BTrees.family64
- return OkapiIndex(lexicon, family=family)
+ index=index,
+ family=family)
def test_class_conforms_to_IInjection(self):
from zope.interface.verify import verifyClass
@@ -135,6 +122,11 @@ def test_ctor_explicit_lexicon(self):
self.failUnless(isinstance(index.index, OkapiIndex))
self.failUnless(index.index._lexicon is lexicon)
+ def test_ctor_explicit_family(self):
+ import BTrees
+ index = self._makeOne(family=BTrees.family32)
+ self.failUnless(index.family is BTrees.family32)
+
def test_ctor_explicit_index(self):
lexicon = object()
okapi = DummyOkapi(lexicon)
@@ -399,8 +391,3 @@ class DummyIndex:
def clear(self):
self.cleared = True
-def test_suite():
- return unittest.TestSuite((
- unittest.makeSuite(TextIndexTests),
- ))
-
View
27 hypatia/text/tests/test_widcode.py
@@ -58,25 +58,15 @@ def test_decode_zero(self):
def test__decode_other_one_byte_asserts(self):
from ..widcode import _decode
for wid in range(1, 128):
- try:
- _decode(chr(128 + wid))
- except AssertionError:
- pass
- else:
- self.fail("Didn't assert: %d" % wid)
+ self.assertRaises(AssertionError, _decode, chr(128+wid))
def test__decode_two_bytes_asserts(self):
from ..widcode import _decode
for wid in range(128, 2**14):
- try:
- hi, lo = divmod(wid, 128)
- code = chr(hi + 128) + chr(lo)
- _decode(code)
- except AssertionError:
- pass
- else:
- self.fail("Didn't assert: %d" % wid)
-
+ hi, lo = divmod(wid, 128)
+ code = chr(hi + 128) + chr(lo)
+ self.assertRaises(AssertionError, _decode, code)
+
def test__decode_three_bytes(self):
from ..widcode import _decode
for wid in range(2**14, 2**21, 247):
@@ -98,13 +88,8 @@ def test__decode_four_bytes(self):
def test_symmetric(self):
from ..widcode import decode
from ..widcode import encode
- for wid in xrange(2**28, 1117):
+ for wid in xrange(2**14, 2**21, 247):
wids = [wid]
code = encode(wids)
self.assertEqual(decode(code), wids)
-def test_suite():
- return unittest.TestSuite((
- unittest.makeSuite(Test_widcode),
- ))
-

0 comments on commit c96fb31

Please sign in to comment.
Something went wrong with that request. Please try again.