1.1 --- a/test.py Fri Jan 08 00:44:59 2010 +0100
1.2 +++ b/test.py Sun Jan 10 20:47:41 2010 +0100
1.3 @@ -26,7 +26,7 @@
1.4 if "clean" in sys.argv:
1.5 sys.exit(0)
1.6
1.7 -# Test basic data types.
1.8 +print "- Test basic data types."
1.9
1.10 numbers = [12345678, 0, 1, 127, 128, 255, 256]
1.11
1.12 @@ -43,7 +43,7 @@
1.13 print number == n, number, n
1.14 r.close()
1.15
1.16 -# Test positions.
1.17 +print "- Test positions."
1.18
1.19 all_doc_positions = [
1.20 [
1.21 @@ -77,7 +77,7 @@
1.22 r.reset()
1.23 r.close()
1.24
1.25 -# Test position index files.
1.26 +print "- Test position index files."
1.27
1.28 indexed_positions = [
1.29 [
1.30 @@ -105,7 +105,7 @@
1.31 offsets.append((offset, doc_frequency))
1.32 w.close()
1.33
1.34 -r = PositionIndexReader(open("testPI", "rb"))
1.35 +r = PositionIndexIterator(PositionIndexReader(open("testPI", "rb")))
1.36 offsets.reverse()
1.37 indexed_positions.reverse()
1.38 for (offset, doc_frequency), term_positions in zip(offsets, indexed_positions):
1.39 @@ -114,9 +114,9 @@
1.40 print docnum == dn, docnum, dn
1.41 print pos_offset == po, pos_offset, po
1.42 print count == c, count, c
1.43 -r.close()
1.44 +r.reader.close()
1.45
1.46 -# Test position dictionaries.
1.47 +print "- Test position dictionaries."
1.48
1.49 f = open("testP", "wb")
1.50 w = PositionWriter(f)
1.51 @@ -135,12 +135,12 @@
1.52 offsets.reverse()
1.53 all_doc_positions.reverse()
1.54 for (offset, doc_frequency), doc_positions in zip(offsets, all_doc_positions):
1.55 - rd.seek(offset, doc_frequency)
1.56 - dp = list(rd)
1.57 + it = rd.read_term_positions(offset, doc_frequency)
1.58 + dp = list(it)
1.59 print doc_positions == dp, doc_positions, dp
1.60 rd.close()
1.61
1.62 -# Test fields.
1.63 +print "- Test fields."
1.64
1.65 doc_fields = [
1.66 (123, ["testing", "fields", "stored", "compressed"]),
1.67 @@ -166,7 +166,7 @@
1.68 print list(enumerate(fields)) == df, list(enumerate(fields)), df
1.69 r.close()
1.70
1.71 -# Test field index files.
1.72 +print "- Test field index files."
1.73
1.74 indexed_docs = [
1.75 (123, 100000987),
1.76 @@ -188,7 +188,7 @@
1.77 print offset == o, offset, o
1.78 r.close()
1.79
1.80 -# Test field dictionaries.
1.81 +print "- Test field dictionaries."
1.82
1.83 f = open("testF", "wb")
1.84 w = FieldWriter(f)
1.85 @@ -213,7 +213,7 @@
1.86 df = rd.get_fields(docnum)
1.87 print df is None, df
1.88
1.89 -# (Test sequential access.)
1.90 +print "- (Test sequential access.)"
1.91
1.92 rd.rewind()
1.93 for docnum, fields in doc_fields:
1.94 @@ -222,7 +222,7 @@
1.95 print list(enumerate(fields)) == df, list(enumerate(fields)), df
1.96 rd.close()
1.97
1.98 -# Test terms.
1.99 +print "- Test terms."
1.100
1.101 terms = [
1.102 # term offset frequency doc_frequency
1.103 @@ -250,7 +250,7 @@
1.104 print doc_frequency == df, doc_frequency, df
1.105 r.close()
1.106
1.107 -# Test terms in index files.
1.108 +print "- Test terms in index files."
1.109
1.110 indexed_terms = [
1.111 # term offset frequency doc_frequency info_offset
1.112 @@ -279,7 +279,7 @@
1.113 print info_offset == i, info_offset, i
1.114 r.close()
1.115
1.116 -# Test dictionaries with only term data.
1.117 +print "- Test dictionaries with only term data."
1.118
1.119 f = open("test", "wb")
1.120 w = TermWriter(f)
1.121 @@ -314,7 +314,7 @@
1.122 t = rd._find_term(term)
1.123 print t is None, t
1.124
1.125 -# (Test term prefix searching.)
1.126 +print "- (Test term prefix searching.)"
1.127
1.128 print rd.find_terms("a") == ["aardvark", "anteater"], rd.find_terms("a"), ["aardvark", "anteater"]
1.129 print rd.find_terms("bu") == ["bull", "bulldog"], rd.find_terms("bu"), ["bull", "bulldog"]
1.130 @@ -322,7 +322,7 @@
1.131 print rd.find_terms("d") == [], rd.find_terms("d"), []
1.132 rd.close()
1.133
1.134 -# Test dictionaries with term and position data.
1.135 +print "- Test dictionaries with term and position data."
1.136
1.137 terms_with_positions = [
1.138 ("aardvark", [(1, [2, 45, 96]), (20, [13])]),
1.139 @@ -374,14 +374,14 @@
1.140 dp = rd.find_positions(term)
1.141 print dp == [], dp
1.142
1.143 -# (Test iterators.)
1.144 +print "- (Test iterators.)"
1.145
1.146 for term, docnum, positions in position_dict_tests:
1.147 dp = rd.find_positions(term)
1.148 pos = dp.from_document(docnum)
1.149 print positions is None and pos is None or pos is not None and positions == list(pos), positions, pos
1.150
1.151 -# (Test sequential access.)
1.152 +print "- (Test sequential access.)"
1.153
1.154 rd.rewind()
1.155 for term, doc_positions in terms_with_positions:
1.156 @@ -391,7 +391,7 @@
1.157 print doc_positions == dp, doc_positions, dp
1.158 rd.close()
1.159
1.160 -# Test high-level index operations (including merging).
1.161 +print "- Test high-level index operations (including merging)."
1.162
1.163 docs = [
1.164 (1, "The cat sat on the mat"),
1.165 @@ -434,7 +434,7 @@
1.166
1.167 rd = index.get_reader()
1.168
1.169 -# (Test searching.)
1.170 +print "- (Test searching.)"
1.171
1.172 for term, frequency, doc_positions in doc_tests:
1.173 dp = list(rd.find_positions(term))
1.174 @@ -442,20 +442,20 @@
1.175 fr = rd.get_frequency(term)
1.176 print frequency == fr, frequency, fr
1.177
1.178 -# (Test fields.)
1.179 +print "- (Test fields.)"
1.180
1.181 for docnum, text in docs:
1.182 df = dict(rd.get_fields(docnum))
1.183 print df[123] == text, text, df[123]
1.184
1.185 -# (Test navigation.)
1.186 +print "- (Test navigation.)"
1.187
1.188 for term, docnum, positions in position_tests:
1.189 dp = rd.find_positions(term)
1.190 pos = dp.from_document(docnum)
1.191 print positions is None and pos is None or pos is not None and positions == list(pos), positions, pos
1.192
1.193 -# (Test phrases.)
1.194 +print "- (Test phrases.)"
1.195
1.196 for terms, results in phrase_tests:
1.197 res = list(rd.find_common_positions(terms))
1.198 @@ -463,7 +463,7 @@
1.199
1.200 index.close()
1.201
1.202 -# Test index updates.
1.203 +print "- Test index updates."
1.204
1.205 index = Index("test_index")
1.206 index2 = Index("test_index2", 3, 2, 3, 6)
1.207 @@ -500,7 +500,7 @@
1.208 print frequency == fr, frequency, fr
1.209 index2.close()
1.210
1.211 -# (Test update of an empty index.)
1.212 +print "- (Test update of an empty index.)"
1.213
1.214 index = Index("test_index")
1.215 index3 = Index("test_index3")