示例#1
0
 def test_idmapping(self):
     result = SearchResult(
         rids=[rid for rid, uid in _DOCMAP.items() if uid in ITEMS],
         idmapper=DMAP,
         resolver=RESOLVE_ALL,
         )
     for uidkey in result.keys():
         assert result.uid_for(result.rid_for(uidkey)) == uidkey
示例#2
0
 def test_len(self):
     result = SearchResult(
         rids=[rid for rid, uid in _DOCMAP.items() if uid in ITEMS],
         idmapper=DMAP,
         resolver=RESOLVE_ALL,
         )
     assert len(result) == len(result.keys())
     assert len(result) == len(ITEMS)
示例#3
0
 def test_contains(self):
     result = SearchResult(
         rids=[rid for rid, uid in _DOCMAP.items() if uid in ITEMS],
         idmapper=DMAP,
         resolver=RESOLVE_ALL,
         )
     # all keys present
     for uid in result.keys():
         assert uid in result
示例#4
0
 def test_set_difference(self):
     result1 = SearchResult(
         rids=[rid for rid, uid in _DOCMAP.items() if uid in ITEMS],
         idmapper=DMAP,
         resolver=RESOLVE_ALL,
         )
     result2 = SearchResult(
         rids=[rid for rid, uid in _DOCMAP.items() if uid in ITEMS2],
         idmapper=DMAP,
         resolver=RESOLVE_ALL,
         )
     disjoint = SearchResult(
         rids=[rid for rid, uid in _DOCMAP.items() if uid in ITEMS3],
         idmapper=DMAP,
         resolver=RESOLVE_ALL,
         )
     self.assertIsInstance(
         result2.difference(result1),
         SearchResult,
         )
     result3 = result2 - result1
     for k in result1.keys():
         assert k not in result3
     for k in [key for key in result2 if key not in result1]:
         assert k in result3
     result4 = result1 - disjoint
     assert set(result4.keys()) == set(result1.keys())  # nothing removed
示例#5
0
 def test_interfaces(self):
     result = SearchResult(
         rids=[rid for rid, uid in _DOCMAP.items() if uid in ITEMS],
         idmapper=DMAP,
         resolver=RESOLVE_ALL,
         )
     assert IItemCollection.providedBy(result)
     assert ICollectionSetOperations.providedBy(result)
     assert IUIDItemCollection.providedBy(result)
     assert ISearchResult.providedBy(result)
示例#6
0
 def _make_result(self, result):
     """
     Given a result as tuple of length, integer docids,
     construct a search result keyed by UUID.
     """
     size, docids = result  # unpack, but we do not care about size
     t = tuple((docid, self.uidmap.uuid_for(docid))
               for docid in docids)  # iterate into pairs of docid, uid
     result = SearchResult.fromtuples(t, resolver=self.resolver)
     result.__parent__ = self
     result.__name__ = 'result'
     return result
示例#7
0
 def test_set_union(self):
     result1 = SearchResult(
         rids=[rid for rid, uid in _DOCMAP.items() if uid in ITEMS],
         idmapper=DMAP,
         resolver=RESOLVE_ALL,
         )
     result2 = SearchResult(
         rids=[rid for rid, uid in _DOCMAP.items() if uid in ITEMS2],
         idmapper=DMAP,
         resolver=RESOLVE_ALL,
         )
     result3 = result1.union(result2)
     self.assertIsInstance(result3, SearchResult)
     assert len(result3) == len(result2) == 3
     assert len(result3) - 1 == len(result1)
     for k in result1:
         assert k in result3
     for k in result2:
         assert k in result3
     # de-dupe means not strictly concatentation (length):
     assert len(result1) + len(result2) > len(result3)
     # operator and union() equivalent:
     self.assertEqual(
         set((result1 | result2).keys()),
         set(result1.union(result2).keys())
         )
     self.assertEqual(
         set((result1 + result2).keys()),
         set(result1.union(result2).keys())
         )
示例#8
0
 def test_fromtuples_ctor(self):
     result = SearchResult.fromtuples(
         idtuples=[
             (rid, uid) for rid, uid in _DOCMAP.items()
             if uid in ITEMS
             ],
         resolver=RESOLVE_ALL,
         )
     self.assertIsInstance(result, SearchResult)
     assert set(result.keys()) == set(ITEMS.keys())
     assert len(result.record_ids()) == len(result.keys())
     assert result.resolver is RESOLVE_ALL
     assert result._idmapper is None  # ununsed when constructed this way
示例#9
0
 def _make_result(self, result):
     """
     Given a result as tuple of length, integer docids,
     construct a search result keyed by UUID.
     """
     size, docids = result  # unpack, but we do not care about size
     t = tuple(
         (docid, self.uidmap.uuid_for(docid)) for docid in docids
         )  # iterate into pairs of docid, uid
     result = SearchResult.fromtuples(t, resolver=self.resolver)
     result.__parent__ = self
     result.__name__ = 'result'
     return result
示例#10
0
 def test_record_ids(self):
     result = SearchResult(
         rids=[rid for rid, uid in _DOCMAP.items() if uid in ITEMS],
         idmapper=DMAP,
         resolver=RESOLVE_ALL,
         )
     rids = result.record_ids()
     assert isinstance(rids, frozenset)
     seq_rids = result.record_ids(ordered=True)
     assert isinstance(seq_rids, list)
     assert len(rids) == len(seq_rids) == len(result.keys())
     assert frozenset([result.rid_for(k) for k in result.keys()]) == rids
示例#11
0
 def test_get(self):
     """Test get/__getitem__ methods"""
     k = ITEMS.keys()[0]
     result = SearchResult(
         rids=[rid for rid, uid in _DOCMAP.items() if uid in ITEMS],
         idmapper=DMAP,
         resolver=RESOLVE_ALL,
         )
     assert result.get(k) is not None
     assert result.get(k) is result[k]
     assert result.get(k) is ITEMS.get(k)
     # key normalization:
     assert result.get(uuid.UUID(k)) is result.get(k)
     # all keys present
     for uid in result.keys():
         assert result.get(uid) is ITEMS.get(uid)
示例#12
0
 def test_enumeration(self):
     """Test mapping enumeration: keys(), values(), items()"""
     result = SearchResult(
         rids=[rid for rid, uid in _DOCMAP.items() if uid in ITEMS],
         idmapper=DMAP,
         resolver=RESOLVE_ALL,
         )
     assert set(result.keys()) == set(ITEMS.keys())  # sufficient
     # all keys present
     for uid in result.keys():
         assert uid in result
         item = ITEMS.get(uid)
         assert ITEMS.get(uid) in result.values()
         assert (uid, item) in result.items()
示例#13
0
 def test_set_intersection(self):
     result1 = SearchResult(
         rids=[rid for rid, uid in _DOCMAP.items() if uid in ITEMS],
         idmapper=DMAP,
         resolver=RESOLVE_ALL,
         )
     result2 = SearchResult(
         rids=[rid for rid, uid in _DOCMAP.items() if uid in ITEMS2],
         idmapper=DMAP,
         resolver=RESOLVE_ALL,
         )
     disjoint = SearchResult(
         rids=[rid for rid, uid in _DOCMAP.items() if uid in ITEMS3],
         idmapper=DMAP,
         resolver=RESOLVE_ALL,
         )
     self.assertIsInstance(
         result2.intersection(result1),
         SearchResult,
         )
     # result1 is subset, common elements
     assert set((result1 & result2).keys()) == set(result1.keys())
     # intersection of disjoint set is null set, empty mapping:
     assert not (result1 & disjoint).keys()