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

code cleanup

parent 90a56376
...@@ -4,7 +4,6 @@ import unittest ...@@ -4,7 +4,6 @@ import unittest
import Zope import Zope
from Products.ZCatalog.ZCatalog import ZCatalog from Products.ZCatalog.ZCatalog import ZCatalog
from Products.PluginIndexes.TextIndex import Splitter from Products.PluginIndexes.TextIndex import Splitter
# This patch pretends the ZCatalog is using the Unicode Splitter # This patch pretends the ZCatalog is using the Unicode Splitter
...@@ -15,7 +14,6 @@ Splitter.availableSplitters = [ ("UnicodeSplitter" , "Unicode-aware splitter" ...@@ -15,7 +14,6 @@ Splitter.availableSplitters = [ ("UnicodeSplitter" , "Unicode-aware splitter"
Splitter.splitterNames = [ "UnicodeSplitter" ] Splitter.splitterNames = [ "UnicodeSplitter" ]
class TO: class TO:
def __init__(self,txt,kw=''): def __init__(self,txt,kw=''):
...@@ -46,7 +44,7 @@ class UnicodeTextIndexCatalogTest(unittest.TestCase): ...@@ -46,7 +44,7 @@ class UnicodeTextIndexCatalogTest(unittest.TestCase):
amerikanischen Angriffen vier afghanische Mitarbeiter einer von den UN amerikanischen Angriffen vier afghanische Mitarbeiter einer von den UN
finanzierten Hilfsorganisation gettet wurden. Diese knnten auch durch finanzierten Hilfsorganisation gettet wurden. Diese knnten auch durch
Gegenfeuer der Taliban gettet worden sein. Gegenfeuer der Taliban gettet worden sein.
""",[unicode('dreitgigen','latin1')]) """,[unicode('dreitgigen','latin1'),'zerstrt'])
self.cat.catalog_object(t1,"o1") self.cat.catalog_object(t1,"o1")
...@@ -56,62 +54,60 @@ class UnicodeTextIndexCatalogTest(unittest.TestCase): ...@@ -56,62 +54,60 @@ class UnicodeTextIndexCatalogTest(unittest.TestCase):
self.cat.catalog_object(t5,"o5") self.cat.catalog_object(t5,"o5")
self.tests = [('quick',('o1',)), self.tests = [('quick',('o1',)),
('fox',('o1','o2','o3','o4')), ('fox',('o1','o3','o4')),
('afghanischen', ('o5',)), ('afghanischen', ('o5',)),
('dreitgigen',('o5',)) ('dreitgigen',('o5',))
] ]
self.kw_tests = [ ('quick',('o1',) ), self.kw_tests = [ ('quick',('o1',) ),
('zerstrt',('o3',)), ('zerstrt',('o3','o5')),
('dreitgigen',('o5',)) ('dreitgigen',('o5',))
] ]
def testAsciiQuery(self): def _doTests(self,tests,field,test_unicode=0):
""" simple query test """
for q,objs in self.tests:
res=self.cat.searchResults({'text':{'query':q}})
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 self.tests:
res=self.cat.searchResults({'text':{'query':unicode(q,'latin1')}})
for r in res: for q,objs in tests:
assert r.getURL() in objs, \ if test_unicode:
"%s: %s vs %s" % (q,str(r.getURL()),str(objs)) res=self.cat.searchResults({field:{'query':unicode(q,'latin1')}})
else:
res=self.cat.searchResults({field:{'query':q}})
got = [ x.getURL() for x in res]
got.sort()
def testAsciiKeywords(self): expected = list(objs)
""" test keyword index """ expected.sort()
for q,objs in self.kw_tests: assert got == expected, \
res=self.cat.searchResults({'kw':{'query':q}}) "%s: got: %s, expected: %s" % (q,got,expected)
for r in res:
assert r.getURL() in objs, \
"%s: %s vs %s" % (q,str(r.getURL()),str(objs))
def testUnicodeKeywords(self): def testAsciiQuery(self):
""" test unicode keyword index """ """ 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: def testUnicodeQuery(self):
assert r.getURL() in objs, \ """ unicode query textindex """
"%s: %s vs %s" % (q,str(r.getURL()),str(objs)) 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)
...@@ -119,48 +115,7 @@ def test_suite(): ...@@ -119,48 +115,7 @@ def test_suite():
return unittest.makeSuite(UnicodeTextIndexCatalogTest) return unittest.makeSuite(UnicodeTextIndexCatalogTest)
def main(): def main():
mb = os.path.join(here, 'zope.mbox') unittest.TextTestRunner().run(test_suite())
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()
if __name__=='__main__': 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