1 # ====================================================================
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13 # ====================================================================
15 from unittest import TestCase, main
19 class CachingWrapperFilterTestCase(TestCase):
21 Unit tests ported from Java Lucene
24 def testCachingWorks(self):
27 writer = IndexWriter(dir, StandardAnalyzer(Version.LUCENE_CURRENT),
28 True, IndexWriter.MaxFieldLength.LIMITED)
31 reader = IndexReader.open(dir, True)
33 class mockFilter(PythonFilter):
35 super(mockFilter, self).__init__()
36 self._wasCalled = False
37 def getDocIdSet(self, reader):
38 self._wasCalled = True;
39 return DocIdBitSet(BitSet())
41 self._wasCalled = False
43 return self._wasCalled
46 cacher = CachingWrapperFilter(filter)
48 # first time, nested filter is called
49 cacher.getDocIdSet(reader)
50 self.assert_(filter.wasCalled(), "first time")
52 # second time, nested filter should not be called
54 cacher.getDocIdSet(reader)
55 self.assert_(not filter.wasCalled(), "second time")
60 if __name__ == "__main__":
63 if '-loop' in sys.argv:
64 sys.argv.remove('-loop')