| 1119 | def test_serialise_document(): |
| 1120 | """Test serialisation of documents. |
| 1121 | |
| 1122 | """ |
| 1123 | doc = xapian.Document() |
| 1124 | doc.add_term('foo', 2) |
| 1125 | doc.add_value(1, 'bar') |
| 1126 | doc.set_data('baz') |
| 1127 | s = doc.serialise() |
| 1128 | doc2 = xapian.Document.unserialise(s) |
| 1129 | expect(len(list(doc.termlist())), len(list(doc2.termlist()))) |
| 1130 | expect(len(list(doc.termlist())), 1) |
| 1131 | expect([(item.term, item.wdf) for item in doc.termlist()], |
| 1132 | [(item.term, item.wdf) for item in doc2.termlist()]) |
| 1133 | expect([(item.num, item.value) for item in doc.values()], |
| 1134 | [(item.num, item.value) for item in doc2.values()]) |
| 1135 | expect(doc.get_data(), doc2.get_data()) |
| 1136 | expect(doc.get_data(), 'baz') |
| 1137 | |
| 1138 | db = setup_database() |
| 1139 | doc = db.get_document(1) |
| 1140 | s = doc.serialise() |
| 1141 | doc2 = xapian.Document.unserialise(s) |
| 1142 | expect(len(list(doc.termlist())), len(list(doc2.termlist()))) |
| 1143 | expect(len(list(doc.termlist())), 3) |
| 1144 | expect([(item.term, item.wdf) for item in doc.termlist()], |
| 1145 | [(item.term, item.wdf) for item in doc2.termlist()]) |
| 1146 | expect([(item.num, item.value) for item in doc.values()], |
| 1147 | [(item.num, item.value) for item in doc2.values()]) |
| 1148 | expect(doc.get_data(), doc2.get_data()) |
| 1149 | expect(doc.get_data(), 'is it cold?') |
| 1150 | |
| 1151 | def test_serialise_query(): |
| 1152 | """Test serialisation of queries. |
| 1153 | |
| 1154 | """ |
| 1155 | q = xapian.Query() |
| 1156 | q2 = xapian.Query.unserialise(q.serialise()) |
| 1157 | expect(str(q), str(q2)) |
| 1158 | expect(str(q), 'Xapian::Query()') |
| 1159 | |
| 1160 | q = xapian.Query('hello') |
| 1161 | q2 = xapian.Query.unserialise(q.serialise()) |
| 1162 | expect(str(q), str(q2)) |
| 1163 | expect(str(q), 'Xapian::Query(hello)') |
| 1164 | |
| 1165 | q = xapian.Query(xapian.Query.OP_OR, ('hello', 'world')) |
| 1166 | q2 = xapian.Query.unserialise(q.serialise()) |
| 1167 | expect(str(q), str(q2)) |
| 1168 | expect(str(q), 'Xapian::Query((hello OR world))') |
| 1169 | |