Ticket #505: testcase-505-fixed.py

File testcase-505-fixed.py, 1.6 KB (added by Olly Betts, 13 years ago)

Testcase which doesn't list all the refers to None

Line 
1import xapian
2
3class TestMatchDecider(xapian.MatchDecider):
4 def __init__(self):
5 super(TestMatchDecider, self).__init__()
6
7 def __call__(self, doc):
8 return True
9
10if __name__ == '__main__':
11 import gc
12 import xapian
13 import weakref
14 db = xapian.WritableDatabase('test', xapian.DB_CREATE_OR_OPEN)
15 doc = xapian.Document()
16 doc.set_data('test')
17 db.replace_document(1, doc)
18 enq = xapian.Enquire(db)
19 enq.set_query(xapian.Query.MatchAll)
20 print "new dec (decider)"
21 dec = TestMatchDecider()
22 decref = weakref.ref(dec)
23 print "decref:", decref()
24 print "removing dec"
25 del dec
26 print "decref:", decref()
27 print "new dec"
28 dec = TestMatchDecider()
29 decref = weakref.ref(dec)
30 print "decref:", decref()
31 print "decref referrer count:", len(gc.get_referrers(decref()))
32 print "type of decref referrer 1:", type(gc.get_referrers(decref())[0])
33 print "decref referrer == locals()?", gc.get_referrers(decref())[0] == locals()
34 mset = enq.get_mset(0, 1, 1, None, dec)
35 print "removing local variables and garbage collecting"
36 del db, doc, enq, dec
37 gc.collect()
38 print "decref:", decref()
39 if decref() != None:
40 print "decref referrer count:", len(gc.get_referrers(decref()))
41 print "decref referrers:", gc.get_referrers(decref())
42 print "type of decref referrer 1", type(gc.get_referrers(decref())[0])
43 print "referrers of decref referrer 1:", gc.get_referrers(gc.get_referrers(decref())[0])
44 #import pdb
45 #pdb.set_trace()
46