1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#!/usr/bin/python
import sys
sys.path.insert(0,"../")
import apt
import unittest
import xapian
from softwarecenter.enums import *
class testXapian(unittest.TestCase):
""" tests the xapian database """
def setUp(self):
# FIXME: create a fixture DB instead of using the system one
# but for now that does not matter that much, only if we
# call open the db is actually read and the path checked
dbpath = "/var/cache/software-center/xapian"
self.xapiandb = xapian.Database(dbpath)
self.enquire = xapian.Enquire(self.xapiandb)
def test_exact_query(self):
query = xapian.Query("APsoftware-center")
self.enquire.set_query(query)
matches = self.enquire.get_mset(0, 100)
self.assertEqual(len(matches), 1)
def test_search_term(self):
search_term = "apt"
parser = xapian.QueryParser()
query = parser.parse_query(search_term)
self.enquire.set_query(query)
matches = self.enquire.get_mset(0, 100)
self.assertTrue(len(matches) > 5)
def test_category_query(self):
search_term = "apt"
query = xapian.Query("ACaudiovideo")
self.enquire.set_query(query)
matches = self.enquire.get_mset(0, 100)
self.assertTrue(len(matches) > 5)
def test_mime_query(self):
query = xapian.Query("AMtext/html")
self.enquire.set_query(query)
matches = self.enquire.get_mset(0, 100)
self.assertTrue(len(matches) > 5)
pkgs = set()
for match in matches:
doc = match.get_document()
pkgs.add(doc.get_value(XAPIAN_VALUE_PKGNAME))
self.assertTrue("firefox" in pkgs)
if __name__ == "__main__":
import logging
logging.basicConfig(level=logging.DEBUG)
unittest.main()
|