[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/DateIndex/tests - test_DateIndex.py:1.1.2.1
Martijn Pieters
mj@zope.com
Wed, 8 May 2002 17:14:58 -0400
Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/DateIndex/tests
In directory cvs.zope.org:/tmp/cvs-serv16358/DateIndex/tests
Added Files:
Tag: mj-dateindexes_integration-branch
test_DateIndex.py
Log Message:
Third time lucky. Rename dir, and move DateRangeIndex to it's own package.
=== Added File Zope/lib/python/Products/PluginIndexes/DateIndex/tests/test_DateIndex.py ===
import Zope
import unittest
from DateTime import DateTime
from Products.PluginIndexes.DateIndexes.DateIndex import DateIndex
class Dummy:
def __init__(self, name, date):
self._name = name
self._date = date
def name(self):
return self._name
def date(self):
return self._date
dummies = (Dummy('a', None), Dummy('b', DateTime(0)), Dummy('c',
DateTime('2002-05-08 15:16:17')))
def matchingDummies(value):
return [d for d in dummies if d.date() == value]
class DI_Tests(unittest.TestCase):
def test_empty(self):
empty = DateIndex('empty')
self._assert(empty.getEntryForObject(1234) is None)
empty.unindex_object(1234) # shouldn't throw
assert not empty.uniqueValues('foo')
assert not empty.uniqueValues('foo', 1)
assert empty._apply_index({'zed' : 12345}) is None
result, used = empty._apply_index({'empty': 12345})
assert not result
assert used == ( None )
def test_retrieval( self ):
work = DateRangeIndex( 'work', 'date' )
for i in range( len( dummies ) ):
work.index_object( i, dummies[i] )
for i in range( len( dummies ) ):
assert work.getEntryForObject( i ) == dummies[i].date()
def test_suite():
suite = unittest.TestSuite()
suite.addTest( unittest.makeSuite( DI_Tests ) )
return suite
def run():
unittest.TextTestRunner().run(test_suite())
if __name__ == '__main__':
run()