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 # ====================================================================
 
  17 from unittest import TestCase
 
  19     SimpleFSDirectory, Document, \
 
  20     System, SimpleDateFormat, File
 
  23 class LiaTestCase(TestCase):
 
  25     def __init__(self, *args):
 
  27         super(LiaTestCase, self).__init__(*args)
 
  28         self.indexDir = System.getProperty("index.dir")
 
  32         self.directory = SimpleFSDirectory(File(self.indexDir))
 
  36         self.directory.close()
 
  41     def dumpHits(self, searcher, scoreDocs):
 
  46             for scoreDoc in scoreDocs:
 
  47                 print "%s: %s" %(scoreDoc.score,
 
  48                                  searcher.doc(scoreDoc.doc).get('title'))
 
  50     def assertHitsIncludeTitle(self, searcher, scoreDocs, title,
 
  53         for scoreDoc in scoreDocs:
 
  54             doc = searcher.doc(scoreDoc.doc)
 
  55             if title == doc.get("title"):
 
  57                     self.fail("title '%s' found" %(title))
 
  61             self.fail("title '%s' not found" %(title))
 
  63     def parseDate(self, s):
 
  65         return SimpleDateFormat("yyyy-MM-dd").parse(s)