Commit 2dac1c5c authored by Andreas Jung's avatar Andreas Jung

code cleanup

parent 90a56376
......@@ -4,7 +4,6 @@ import unittest
import Zope
from Products.ZCatalog.ZCatalog import ZCatalog
from Products.PluginIndexes.TextIndex import Splitter
# This patch pretends the ZCatalog is using the Unicode Splitter
......@@ -15,7 +14,6 @@ Splitter.availableSplitters = [ ("UnicodeSplitter" , "Unicode-aware splitter"
Splitter.splitterNames = [ "UnicodeSplitter" ]
class TO:
def __init__(self,txt,kw=''):
......@@ -46,7 +44,7 @@ class UnicodeTextIndexCatalogTest(unittest.TestCase):
amerikanischen Angriffen vier afghanische Mitarbeiter einer von den UN
finanzierten Hilfsorganisation gettet wurden. Diese knnten auch durch
Gegenfeuer der Taliban gettet worden sein.
""",[unicode('dreitgigen','latin1')])
""",[unicode('dreitgigen','latin1'),'zerstrt'])
self.cat.catalog_object(t1,"o1")
......@@ -56,111 +54,68 @@ class UnicodeTextIndexCatalogTest(unittest.TestCase):
self.cat.catalog_object(t5,"o5")
self.tests = [('quick',('o1',)),
('fox',('o1','o2','o3','o4')),
('fox',('o1','o3','o4')),
('afghanischen', ('o5',)),
('dreitgigen',('o5',))
]
self.kw_tests = [ ('quick',('o1',) ),
('zerstrt',('o3',)),
('zerstrt',('o3','o5')),
('dreitgigen',('o5',))
]
def testAsciiQuery(self):
""" simple query test """
for q,objs in self.tests:
res=self.cat.searchResults({'text':{'query':q}})
def _doTests(self,tests,field,test_unicode=0):
for r in res:
assert r.getURL() in objs,\
"%s: %s vs %s" % (q,str(r.getURL()),str(objs))
def testUnicodeQuery(self):
""" unicode query test """
for q,objs in tests:
if test_unicode:
res=self.cat.searchResults({field:{'query':unicode(q,'latin1')}})
else:
res=self.cat.searchResults({field:{'query':q}})
for q,objs in self.tests:
res=self.cat.searchResults({'text':{'query':unicode(q,'latin1')}})
got = [ x.getURL() for x in res]
got.sort()
for r in res:
assert r.getURL() in objs, \
"%s: %s vs %s" % (q,str(r.getURL()),str(objs))
expected = list(objs)
expected.sort()
assert got == expected, \
"%s: got: %s, expected: %s" % (q,got,expected)
def testAsciiKeywords(self):
""" test keyword index """
for q,objs in self.kw_tests:
res=self.cat.searchResults({'kw':{'query':q}})
for r in res:
assert r.getURL() in objs, \
"%s: %s vs %s" % (q,str(r.getURL()),str(objs))
def testUnicodeKeywords(self):
""" test unicode keyword index """
def testAsciiQuery(self):
""" ascii query textindex """
self._doTests(self.tests, 'text', test_unicode=0)
for q,objs in self.kw_tests:
res=self.cat.searchResults({'kw':{'query':unicode(q,'latin1')}})
for r in res:
assert r.getURL() in objs, \
"%s: %s vs %s" % (q,str(r.getURL()),str(objs))
def testUnicodeQuery(self):
""" unicode query textindex """
self._doTests(self.tests, 'text', test_unicode=1)
# The Tests for KeywordIndexes are disabled at this time
# because of a strange behaviour of OOBTrees containing
# mixed strings and unicode strings
#
#
# def testAsciiKeywords(self):
# """ ascii query keyword index """
# self._doTests(self.kw_tests, 'kw', test_unicode=0)
#
#
# def testUnicodeKeywords(self):
# """ ascii query keyword index """
# self._doTests(self.kw_tests, 'kw', test_unicode=1)
def test_suite():
return unittest.makeSuite(UnicodeTextIndexCatalogTest)
def main():
mb = os.path.join(here, 'zope.mbox')
if not os.path.isfile(mb):
print "do you want to get the zope.mbox file from lists.zope.org?"
print "it's required for testing (98MB, ~ 30mins on fast conn)"
print "it's also available at korak:/home/chrism/zope.mbox"
print "-- type 'Y' or 'N'"
a = raw_input()
if lower(a[:1]) == 'y':
server = 'lists.zope.org:80'
method = '/pipermail/zope.mbox/zope.mbox'
h = httplib.HTTP(server)
h.putrequest('GET', method)
h.putheader('User-Agent', 'silly')
h.putheader('Accept', 'text/html')
h.putheader('Accept', 'text/plain')
h.putheader('Host', server)
h.endheaders()
errcode, errmsg, headers = h.getreply()
if errcode != 200:
f = h.getfile()
data = f.read()
print data
raise "Error reading from host %s" % server
f = h.getfile()
out=open(mb,'w')
print "this is going to take a while..."
print "downloading mbox from %s" % server
while 1:
l = f.readline()
if not l: break
out.write(l)
alltests=test_suite()
runner = unittest.TextTestRunner()
runner.run(alltests)
def debug():
test_suite().debug()
unittest.TextTestRunner().run(test_suite())
if __name__=='__main__':
if len(sys.argv) > 1:
globals()[sys.argv[1]]()
else:
main()
main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment