class QueryTest(unittest.TestCase): def setUp(self): self.library = Library('/tmp/parser.test', 'w') self.library.append(Document(code="200", plateform="linux", browser="khtml")) self.library.append(Document(code="200", plateform="winxp", browser="ie")) def testSimple(self): query = Query('plateform:winxp') self.assertEquals(set([1]), value(query, self.library).results()) def testNot(self): query = Query('not plateform:winxp') self.assertEquals(set([0]), value(query, self.library).results()) def testOr(self): query = Query(' plateform:winxp or plateform:linux') self.assertEquals(set([0, 1]), value(query, self.library).results()) def testDummy(self): query = Query('not (plateform:winxp)') self.assertEquals(set([0]), value(query, self.library).results()) def testOr(self): try: query = Query(" or toto:machin") except ParseException: pass query = Query(' plateform:winxp or plateform:linux') #print query.asXML() def testAll(self): q = """ not plateform:winxp or ( code:200 and browser:firefox )""" query = Query(q) #print query.asXML() #print value(query, self.library) self.assertEquals(set([0]), value(query, self.library).results())
class DocumentTest(unittest.TestCase): def setUp(self): self.l = Library("/tmp/index.test", "w") for data in datas: d = Document() for k, v in data.iteritems(): d[k] = v self.l.append(d) def testKargs(self): d = Document(name="Bob", score=42) self.assertEquals(42, d["score"]) def testNot(self): b = -self.l.get("score", 42) self.assertEquals(set([0]), b.results()) def testAnd(self): b = self.l.get("score", 42) & self.l.get("tags", "simple") for document in self.l.documents(self.l.query("score:42 and tags:simple")): pass # print document self.assertEquals(1, b.cardinality()) self.assertEquals(set([1]), b.results()) for doc in self.l.documents(b): self.assertEquals("casimir", doc["nom"]) def testStart(self): self.assertEquals(set([2]), self.l.start("nom", "an").results()) def testRange(self): self.assertEquals(set([0, 2]), self.l.range("nom", "adrien", "brigitte").results())
def _testMulti(self): libraries = [] for a in range(4): print a library = Library("/tmp/index_%i.test" % a, "w") for b in range(10): document = Document(value=b, name=random.choice(("Pim", "Pam", "Poum"))) print "\t", b, document library.append(document) libraries.append(library) multi = MultiLibrary(libraries) print multi.query("name:pim")
def testReadWrite(self): library = Library("/tmp/index_rw", "w") self.assertEquals(0, len(library)) doc = Document(name="Bob", score=42) library.append(doc) library.warmup() library.close() libRead = Library("/tmp/index_rw", "r") self.assertEquals(1, len(libRead)) self.assertEquals("bob", libRead.store[0]["name"]) self.assertEquals(set([0]), libRead.get("name", "bob").results())
def setUp(self): self.l = Library("/tmp/index.test", "w") for data in datas: d = Document() for k, v in data.iteritems(): d[k] = v self.l.append(d)
def setUp(self): self.library = Library('/tmp/parser.test', 'w') self.library.append(Document(code="200", plateform="linux", browser="khtml")) self.library.append(Document(code="200", plateform="winxp", browser="ie"))