Commit f0007027 authored by Fred Drake's avatar Fred Drake

- remove unused imports

- use random.randrange() instead of whrandom.randint()
- commented some code that appears unused
- normalize whitespace
parent 61e37be5
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
# Unittests for Catalog # Unittests for Catalog
import os,sys, unittest import os
import random
import unittest
import ZODB, OFS.Application import ZODB, OFS.Application
from ZODB.DemoStorage import DemoStorage from ZODB.DemoStorage import DemoStorage
...@@ -17,8 +19,6 @@ from Products.PluginIndexes.TextIndex.TextIndex import TextIndex ...@@ -17,8 +19,6 @@ from Products.PluginIndexes.TextIndex.TextIndex import TextIndex
from Products.PluginIndexes.TextIndex.Lexicon import Lexicon from Products.PluginIndexes.TextIndex.Lexicon import Lexicon
from Products.PluginIndexes.KeywordIndex.KeywordIndex import KeywordIndex from Products.PluginIndexes.KeywordIndex.KeywordIndex import KeywordIndex
import whrandom,string, unittest, random
def createDatabase(): def createDatabase():
# XXX We have to import and init products in order for PluginIndexes to # XXX We have to import and init products in order for PluginIndexes to
...@@ -44,18 +44,20 @@ app = createDatabase() ...@@ -44,18 +44,20 @@ app = createDatabase()
################################################################################ ################################################################################
# Stuff of Chris # Stuff of Chris
# XXX What's this mean? What does this comment apply to?
################################################################################ ################################################################################
from AccessControl.SecurityManagement import newSecurityManager # XXX These imports and class don't appear to be needed?
from AccessControl.SecurityManagement import noSecurityManager ## from AccessControl.SecurityManagement import newSecurityManager
## from AccessControl.SecurityManagement import noSecurityManager
class DummyUser: ## class DummyUser:
def __init__( self, name ): ## def __init__( self, name ):
self._name = name ## self._name = name
def getUserName( self ): ## def getUserName( self ):
return self._name ## return self._name
class CatalogBase: class CatalogBase:
...@@ -133,13 +135,13 @@ class TestZCatalog(unittest.TestCase): ...@@ -133,13 +135,13 @@ class TestZCatalog(unittest.TestCase):
self._catalog = ZCatalog.ZCatalog('Catalog') self._catalog = ZCatalog.ZCatalog('Catalog')
self._catalog.addIndex('title', 'KeywordIndex') self._catalog.addIndex('title', 'KeywordIndex')
self._catalog.addColumn('title') self._catalog.addColumn('title')
self.upper = 10 self.upper = 10
class dummy(ExtensionClass.Base): class dummy(ExtensionClass.Base):
def __init__(self, num): def __init__(self, num):
self.num = num self.num = num
def title(self): def title(self):
return '%d' % self.num return '%d' % self.num
...@@ -154,10 +156,10 @@ class TestZCatalog(unittest.TestCase): ...@@ -154,10 +156,10 @@ class TestZCatalog(unittest.TestCase):
assert data['title'] == testNum assert data['title'] == testNum
def testGetIndexDataForUID(self): def testGetIndexDataForUID(self):
testNum = str(self.upper - 3) testNum = str(self.upper - 3)
data = self._catalog.getIndexDataForUID(testNum) data = self._catalog.getIndexDataForUID(testNum)
assert data['title'][0] == testNum assert data['title'][0] == testNum
def testSearch(self): def testSearch(self):
query = {'title': ['5','6','7']} query = {'title': ['5','6','7']}
sr = self._catalog.searchResults(query) sr = self._catalog.searchResults(query)
...@@ -166,16 +168,16 @@ class TestZCatalog(unittest.TestCase): ...@@ -166,16 +168,16 @@ class TestZCatalog(unittest.TestCase):
self.assertEqual(len(sr), 3) self.assertEqual(len(sr), 3)
class TestCatalogObject(unittest.TestCase): class TestCatalogObject(unittest.TestCase):
upper = 1000 upper = 1000
nums = range(upper) nums = range(upper)
for i in range(upper): for i in range(upper):
j = random.randint(0, upper-1) j = random.randrange(0, upper)
tmp = nums[i] tmp = nums[i]
nums[i] = nums[j] nums[i] = nums[j]
nums[j] = tmp nums[j] = tmp
def setUp(self): def setUp(self):
self._vocabulary = Vocabulary.Vocabulary('Vocabulary','Vocabulary', self._vocabulary = Vocabulary.Vocabulary('Vocabulary','Vocabulary',
globbing=1) globbing=1)
...@@ -222,7 +224,7 @@ class TestCatalogObject(unittest.TestCase): ...@@ -222,7 +224,7 @@ class TestCatalogObject(unittest.TestCase):
def col3(self): def col3(self):
return ['col3'] return ['col3']
for x in range(0, self.upper): for x in range(0, self.upper):
self._catalog.catalogObject(dummy(self.nums[x]), `x`) self._catalog.catalogObject(dummy(self.nums[x]), `x`)
self._catalog.aq_parent = dummy('foo') # fake out acquisition self._catalog.aq_parent = dummy('foo') # fake out acquisition
...@@ -362,13 +364,13 @@ class TestCatalogObject(unittest.TestCase): ...@@ -362,13 +364,13 @@ class TestCatalogObject(unittest.TestCase):
# set is much larger than the sort index. # set is much larger than the sort index.
a = self._catalog(sort_on='att1') a = self._catalog(sort_on='att1')
self.assertEqual(len(a), self.upper) self.assertEqual(len(a), self.upper)
def testBadSortLimits(self): def testBadSortLimits(self):
self.assertRaises( self.assertRaises(
AssertionError, self._catalog, sort_on='num', sort_limit=0) AssertionError, self._catalog, sort_on='num', sort_limit=0)
self.assertRaises( self.assertRaises(
AssertionError, self._catalog, sort_on='num', sort_limit=-10) AssertionError, self._catalog, sort_on='num', sort_limit=-10)
def testSortLimit(self): def testSortLimit(self):
full = self._catalog(sort_on='num') full = self._catalog(sort_on='num')
a = self._catalog(sort_on='num', sort_limit=10) a = self._catalog(sort_on='num', sort_limit=10)
...@@ -379,7 +381,7 @@ class TestCatalogObject(unittest.TestCase): ...@@ -379,7 +381,7 @@ class TestCatalogObject(unittest.TestCase):
rev.reverse() rev.reverse()
self.assertEqual([r.num for r in a], rev) self.assertEqual([r.num for r in a], rev)
self.assertEqual(a.actual_result_count, self.upper) self.assertEqual(a.actual_result_count, self.upper)
def testBigSortLimit(self): def testBigSortLimit(self):
a = self._catalog(sort_on='num', sort_limit=self.upper*3) a = self._catalog(sort_on='num', sort_limit=self.upper*3)
self.assertEqual(a.actual_result_count, self.upper) self.assertEqual(a.actual_result_count, self.upper)
...@@ -388,7 +390,7 @@ class TestCatalogObject(unittest.TestCase): ...@@ -388,7 +390,7 @@ class TestCatalogObject(unittest.TestCase):
sort_on='num', sort_limit=self.upper*3, sort_order='reverse') sort_on='num', sort_limit=self.upper*3, sort_order='reverse')
self.assertEqual(a.actual_result_count, self.upper) self.assertEqual(a.actual_result_count, self.upper)
self.assertEqual(a[0].num, self.upper - 1) self.assertEqual(a[0].num, self.upper - 1)
class objRS(ExtensionClass.Base): class objRS(ExtensionClass.Base):
...@@ -406,7 +408,7 @@ class testRS(unittest.TestCase): ...@@ -406,7 +408,7 @@ class testRS(unittest.TestCase):
self._catalog.addColumn('number') self._catalog.addColumn('number')
for i in range(5000): for i in range(5000):
obj = objRS(whrandom.randint(0,20000)) obj = objRS(random.randrange(0,20000))
self._catalog.catalogObject(obj,i) self._catalog.catalogObject(obj,i)
self._catalog.aq_parent = objRS(200) self._catalog.aq_parent = objRS(200)
...@@ -414,7 +416,7 @@ class testRS(unittest.TestCase): ...@@ -414,7 +416,7 @@ class testRS(unittest.TestCase):
def testRangeSearch(self): def testRangeSearch(self):
for i in range(10000): for i in range(10000):
m = whrandom.randint(0,20000) m = random.randrange(0,20000)
n = m + 1000 n = m + 1000
for r in self._catalog.searchResults( for r in self._catalog.searchResults(
...@@ -436,4 +438,3 @@ def test_suite(): ...@@ -436,4 +438,3 @@ def test_suite():
if __name__ == '__main__': if __name__ == '__main__':
unittest.main(defaultTest='test_suite') unittest.main(defaultTest='test_suite')
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