From 349600b34d654888fbac6abf780a6ce1d2ab54c5 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sat, 16 Jun 2012 10:40:24 -0400 Subject: [PATCH] ditch deprecated path2 index --- hypatia/indexes/path2.py | 393 ----------- hypatia/indexes/tests/test_path2.py | 997 ---------------------------- hypatia/tests/test_catalog.py | 20 +- 3 files changed, 5 insertions(+), 1405 deletions(-) delete mode 100644 hypatia/indexes/path2.py delete mode 100644 hypatia/indexes/tests/test_path2.py diff --git a/hypatia/indexes/path2.py b/hypatia/indexes/path2.py deleted file mode 100644 index 9d110b0..0000000 --- a/hypatia/indexes/path2.py +++ /dev/null @@ -1,393 +0,0 @@ -from zope.interface import implementer - -from ..interfaces import ICatalogIndex -from .common import CatalogIndex - -_marker = object() - - -@implementer(ICatalogIndex) -class CatalogPathIndex2(CatalogIndex): #pragma NO COVERAGE - """ - DEPRECATED - - Index for model paths (tokens separated by '/' characters or - tuples representing a model path). - - A path index may be queried to obtain all subobjects (optionally - limited by depth) of a certain path. - - This index differs from the original - ``hypatia.indexes.path.CatalogPath`` index inasmuch as it - actually retains a graph representation of the objects in the path - space instead of relying on 'level' information; query results - relying on this level information may or may not be correct for - any given tree. Use of this index is suggested rather than the - ``path`` index. - - Query types supported: - - Eq - - """ - attr_discriminator = None # b/w compat - - def __init__(self, discriminator, attr_discriminator=None, - family=None): - if family is not None: - self.family = family - if not callable(discriminator): - if not isinstance(discriminator, basestring): - raise ValueError('discriminator value must be callable or a ' - 'string') - self.discriminator = discriminator - if attr_discriminator is not None and not callable(attr_discriminator): - if not isinstance(attr_discriminator, basestring): - raise ValueError('attr_discriminator value must be callable ' - 'or a string') - self.attr_discriminator = attr_discriminator - self._not_indexed = self.family.IF.TreeSet() - self.clear() - - def clear(self): - self.docid_to_path = self.family.IO.BTree() - self.path_to_docid = self.family.OI.BTree() - self.adjacency = self.family.IO.BTree() - self.disjoint = self.family.OO.BTree() - self.docid_to_attr = self.family.IO.BTree() - - def __len__(self): - return len(self.docid_to_path) - - def __nonzero__(self): - return True - - def _getPathTuple(self, path): - if not path: - raise ValueError('path must be nonempty (not %s)' % str(path)) - - if isinstance(path, basestring): - path = path.rstrip('/') - path = tuple(path.split('/')) - - if path[0] != '': - raise ValueError('Path must be absolute (not %s)' % str(path)) - - return tuple(path) - - def _getObjectPath(self, object): - if callable(self.discriminator): - path = self.discriminator(object, _marker) - else: - path = getattr(object, self.discriminator, _marker) - - return path - - def _getObjectAttr(self, object): - if callable(self.attr_discriminator): - attr = self.attr_discriminator(object, _marker) - else: - attr = getattr(object, self.attr_discriminator, _marker) - return attr - - def index_doc(self, docid, object): - - path = self._getObjectPath(object) - - if path is _marker: - self.unindex_doc(docid) - return None - - path = self._getPathTuple(path) - - if self.attr_discriminator is not None: - attr = self._getObjectAttr(object) - if attr is not _marker: - self.docid_to_attr[docid] = attr - - self.docid_to_path[docid] = path - self.path_to_docid[path] = docid - - if path in self.disjoint: - self.adjacency[docid] = self.disjoint[path] - del self.disjoint[path] - - if len(path) > 1: - parent_path = tuple(path[:-1]) - parent_docid = self.path_to_docid.get(parent_path) - if parent_docid is None: - theset = self.disjoint.get(parent_path) - if theset is None: - theset = self.family.IF.Set() - self.disjoint[parent_path] = theset - else: - theset = self.adjacency.get(parent_docid) - if theset is None: - theset = self.family.IF.Set() - self.adjacency[parent_docid] = theset - theset.insert(docid) - - def unindex_doc(self, docid): - path = self.docid_to_path.get(docid) - if path is None: - return - - if len(path) > 1: - parent_path = tuple(path[:-1]) - parent_docid = self.path_to_docid.get(parent_path) - if parent_docid is not None: # might be disjoint - self.adjacency[parent_docid].remove(docid) - if not self.adjacency[parent_docid]: - del self.adjacency[parent_docid] - else: - self.disjoint[parent_path].remove(docid) - if not self.disjoint[parent_path]: - del self.disjoint[parent_path] - - stack = [docid] - - while stack: - docid = stack.pop() - path = self.docid_to_path[docid] - del self.path_to_docid[path] - del self.docid_to_path[docid] - if docid in self.docid_to_attr: - del self.docid_to_attr[docid] - next_docids = self.adjacency.get(docid) - if next_docids is None: - next_docids = self.disjoint.get(path) - if next_docids is not None: - del self.disjoint[path] - stack.extend(next_docids) - else: - del self.adjacency[docid] - stack.extend(next_docids) - - def reindex_doc(self, docid, object): - path = self._getPathTuple(self._getObjectPath(object)) - - if self.docid_to_path.get(docid) != path: - self.unindex_doc(docid) - self.index_doc(docid, object) - return True - - else: - if self.attr_discriminator is not None: - attr = self._getObjectAttr(object) - if docid in self.docid_to_attr: - if attr is _marker: - del self.docid_to_attr[docid] - return True - elif attr != self.docid_to_attr[docid]: - self.docid_to_attr[docid] = attr - return True - else: - if attr is not _marker: - self.docid_to_attr[docid] = attr - return True - return False - - def _indexed(self): - return self.docid_to_path.keys() - - def search(self, path, depth=None, include_path=False, attr_checker=None): - """ Provided a path string (e.g. ``/path/to/object``) or a - path tuple (e.g. ``('', 'path', 'to', 'object')``, or a path - list (e.g. ``['', 'path', 'to' object'])``), search the index - for document ids representing subelements of the path - specified by the path argument. - - If the ``path`` argment is specified as a tuple or list, its - first element must be the empty string. If the ``path`` - argument is specified as a string, it must begin with a ``/`` - character. In other words, paths passed to the ``search`` - method must be absolute. - - If the ``depth`` argument is specified, return only documents - at this depth and below. Depth ``0`` will returns the empty - set (or only the docid for the ``path`` specified if - ``include_path`` is also True). Depth ``1`` will return - docids related to direct subobjects of the path (plus the - docid for the ``path`` specified if ``include_path`` is also - True). Depth ``2`` will return docids related to direct - subobjects and the docids of the children of those subobjects, - and so on. - - If ``include_path`` is False, the docid of the object - specified by the ``path`` argument is *not* returned as part - of the search results. If ``include_path`` is True, the - object specified by the ``path`` argument *is* returned as - part of the search results. - - If ``attr_checker`` is not None, it must be a callback that - accepts two arguments: the first argument will be the - attribute value found, the second argument is a sequence of - all previous attributes encountered during this search (in - path order). If ``attr_checker`` returns True, traversal will - continue; otherwise, traversal will cease. - """ - if attr_checker is None: - return self._simple_search(path, depth, include_path) - else: - return self._attr_search(path, depth, include_path, attr_checker) - - def _simple_search(self, path, depth, include_path): - """ Codepath taken when no attr checker is used """ - path = self._getPathTuple(path) - sets = [] - - if include_path: - try: - docid = self.path_to_docid[path] - except KeyError: - pass # XXX should we just return an empty set? - else: - sets.append(self.family.IF.Set([docid])) - - stack = [path] - plen = len(path) - - while stack: - nextpath = stack.pop() - if depth is not None and len(nextpath) - plen >= depth: - continue - try: - docid = self.path_to_docid[nextpath] - except KeyError: - continue # XXX we can't search from an unindexed root path? - try: - theset = self.adjacency[docid] - except KeyError: - pass - else: - sets.append(theset) - for docid in theset: - try: - newpath = self.docid_to_path[docid] - except KeyError: - continue - stack.append(newpath) - - return self.family.IF.multiunion(sets) - - def _attr_search(self, path, depth, include_path, attr_checker): - """ Codepath taken when an attr checker is used """ - path = self._getPathTuple(path) - - leading_attrs = [] - result = {} - plen = len(path) - - # make sure we get "leading" attrs - for p in range(plen-1): - subpath = path[:p+1] - try: - docid = self.path_to_docid[subpath] - except KeyError: - continue # XXX should we just return an empty set? - attr = self.docid_to_attr.get(docid, _marker) - if attr is not _marker: - remove_from_closest(result, subpath, docid) - leading_attrs.append(attr) - result[subpath] = ((docid, leading_attrs[:]), - self.family.IF.Set()) - - stack = [(path, leading_attrs)] - attrset = self.family.IF.Set() - - while stack: - nextpath, attrs = stack.pop() - try: - docid = self.path_to_docid[nextpath] - except KeyError: - continue # XXX we can't search from an unindexed root path? - attr = self.docid_to_attr.get(docid, _marker) - if attr is _marker: - if include_path and nextpath == path: - add_to_closest( - result, nextpath, self.family.IF.Set([docid])) - if depth is not None and len(nextpath) - plen >= depth: - continue - else: - remove_from_closest(result, nextpath, docid) - attrs.append(attr) - if nextpath == path: - if include_path: - attrset = self.family.IF.Set([docid]) - else: - attrset = self.family.IF.Set() - else: - attrset = self.family.IF.Set([docid]) - result[nextpath] = ((docid, attrs), attrset) - if depth is not None and len(nextpath) - plen >= depth: - continue - try: - theset = self.adjacency[docid] - except KeyError: - pass - else: - add_to_closest(result, nextpath, theset) - for docid in theset: - try: - newpath = self.docid_to_path[docid] - except KeyError: - continue - stack.append((newpath, attrs[:])) - - return attr_checker(result.values()) - - def apply_intersect(self, query, docids): - """ Default apply_intersect implementation """ - result = self.apply(query) - if docids is None: - return result - return self.family.IF.weightedIntersection(result, docids)[1] - - def apply(self, query): - """ Search the path index using the query. If ``query`` is a - string, a tuple, or a list, it is treated as the ``path`` - argument to use to search. If it is any other object, it is - assumed to be a dictionary with at least a value for the - ``query`` key, which is treated as a path. The dictionary can - also optionally specify the ``depth`` and whether to include - the docid referenced by the path argument (the ``query`` key) - in the set of docids returned (``include_path``). See the - documentation for the ``search`` method of this class to - understand paths, depths, and the ``include_path`` argument. - """ - if isinstance(query, (basestring, tuple, list)): - path = query - depth = None - include_path = False - attr_checker = None - else: - path = query['query'] - depth = query.get('depth', None) - include_path = query.get('include_path', False) - attr_checker = query.get('attr_checker', None) - - return self.search(path, depth, include_path, attr_checker) - - def applyEq(self, query): - return self.apply(query) - -def add_to_closest(sofar, thispath, theset): - paths = sofar.keys() - paths.reverse() - for path in paths: - pathlen = len(path) - if thispath[:pathlen] == path: - sofar[path][1].update(theset) - break - -def remove_from_closest(sofar, thispath, docid): - paths = sofar.keys() - paths.reverse() - for path in paths: - pathlen = len(path) - if thispath[:pathlen] == path: - theset = sofar[path][1] - if docid in theset: - theset.remove(docid) - break - diff --git a/hypatia/indexes/tests/test_path2.py b/hypatia/indexes/tests/test_path2.py deleted file mode 100644 index 2590f8b..0000000 --- a/hypatia/indexes/tests/test_path2.py +++ /dev/null @@ -1,997 +0,0 @@ -import unittest - -_marker = object() - -class CatalogPathIndex2Tests(unittest.TestCase): - def _getTargetClass(self): - from ..path2 import CatalogPathIndex2 - return CatalogPathIndex2 - - def _makeOne(self, values=None, - discriminator='path', attr_discriminator=_marker): - if values is None: - values = {} - def _attr_discriminator(obj, default): - return obj.path - if attr_discriminator is _marker: - attr_discriminator = _attr_discriminator - index = self._getTargetClass()(discriminator, - attr_discriminator=attr_discriminator) - for doc_id, path in values.items(): - index.index_doc(doc_id, path) - return index - - def test_class_conforms_to_ICatalogIndex(self): - from zope.interface.verify import verifyClass - from ...interfaces import ICatalogIndex - verifyClass(ICatalogIndex, self._getTargetClass()) - - def test_instance_conforms_to_ICatalogIndex(self): - from zope.interface.verify import verifyObject - from ...interfaces import ICatalogIndex - verifyObject(ICatalogIndex, self._makeOne()) - - def test_ctor_callback_discriminator(self): - def _discriminator(obj, default): - """ """ - index = self._makeOne(discriminator=_discriminator) - self.failUnless(index.discriminator is _discriminator) - - def test_ctor_string_discriminator(self): - index = self._makeOne(discriminator='abc') - self.assertEqual(index.discriminator, 'abc') - - def test_ctor_bad_discriminator(self): - self.assertRaises(ValueError, self._makeOne, discriminator=object()) - - def test_ctor_callback_attr_discriminator(self): - def _attr_discriminator(obj, default): - """ """ - index = self._makeOne(attr_discriminator=_attr_discriminator) - self.failUnless(index.attr_discriminator is _attr_discriminator) - - def test_ctor_string_attr_discriminator(self): - index = self._makeOne(attr_discriminator='abc') - self.assertEqual(index.attr_discriminator, 'abc') - - def test_ctor_no_attr_discriminator(self): - index = self._makeOne(attr_discriminator=None) - self.assertEqual(index.attr_discriminator, None) - - def test_ctor_bad_attr_discriminator(self): - self.assertRaises(ValueError, self._makeOne, - attr_discriminator=object()) - - def test_throws_on_no_query(self): - index = self._makeOne({}) - self.assertRaises(KeyError, index.apply, {}) - - def test_empty_index(self): - index = self._makeOne({}) - self.assertEqual(len(index), 0) - self.failUnless(index) # True even if empty - - def test_nonempty_index(self): - index = self._makeOne(VALUES) - self.assertEqual(len(index), 22) - self.failUnless(index) - - def test_index_object_bad_path(self): - index = self._makeOne() - class Dummy: - path = () - self.assertRaises(ValueError, index.index_doc, 1, Dummy()) - - def test_index_object_simple(self): - index = self._makeOne() - class Dummy: - path = '/abc' - index.index_doc(1, Dummy()) - self.assertEqual(index.path_to_docid[('', 'abc')], 1) - self.assertEqual(index.docid_to_path[1], ('', 'abc')) - - def test_index_object_callback_discriminator(self): - def _discriminator(obj, default): - return '/abc' - index = self._makeOne(discriminator=_discriminator) - class Dummy: - path = '/foo' - index.index_doc(1, Dummy()) - self.assertEqual(index.path_to_docid[('', 'abc')], 1) - self.assertEqual(index.docid_to_path[1], ('', 'abc')) - - def test_index_object_missing_value_unindexes(self): - index = self._makeOne() - class Dummy: - pass - dummy = Dummy() - dummy.path = '/abc' - index.index_doc(1, Dummy()) - del dummy.path - index.index_doc(1, Dummy()) - self.failIf(('', 'abc') in index.path_to_docid) - self.failIf(1 in index.docid_to_path) - - def test_unindex_nonesuch(self): - index = self._makeOne({}) - index.unindex_doc(1234) # nothrow - - def test_unindex_doc(self): - index = self._makeOne(VALUES) - docids = VALUES.keys() - - for doc_id in docids: - index.unindex_doc(doc_id) - - self.assertEqual(len(index), 0) - self.assertEqual(list(index.adjacency.keys()), []) - self.assertEqual(list(index.disjoint.keys()), []) - self.assertEqual(list(index.path_to_docid.keys()), []) - self.assertEqual(list(index.docid_to_path.keys()), []) - - index = self._makeOne(VALUES) - # randomize the order - import random - random.shuffle(docids) - for doc_id in docids: - index.unindex_doc(doc_id) - - self.assertEqual(len(index), 0) - self.assertEqual(list(index.adjacency.keys()), []) - self.assertEqual(list(index.disjoint.keys()), []) - self.assertEqual(list(index.path_to_docid.keys()), []) - self.assertEqual(list(index.docid_to_path.keys()), []) - - def test_unindex_then_index_doesnt_dupe(self): - index = self._makeOne() - o = Dummy('/foo/bar') - index.index_doc(1, o) - self.assertEqual(len(index), 1) - index.index_doc(1, o) - self.assertEqual(len(index), 1) - - # This test fails, but I can't see why it should. - #def XXX_test_search_from_unindexed_root(self): - # index = self._makeOne() - # index.index_doc(1, '/abc/def') - # index.index_doc(2, '/abc/ghi') - # result = index.search('/abc', depth=1, include_path=True) - # self.assertEqual(sorted(result), [1, 2]) - - def test_search_root_nodepth(self): - index = self._makeOne(VALUES) - result = index.search('/') - self.assertEqual(sorted(result), range(1, 21)) - - def test_search_root_nodepth_include_path(self): - index = self._makeOne(VALUES) - result = index.search('/', include_path=True) - self.assertEqual(sorted(result), range(0, 21)) - - def test_search_root_depth_0(self): - index = self._makeOne(VALUES) - result = index.search('/', depth=0) - self.assertEqual(sorted(result), []) - - def test_search_depth_0_include_path(self): - index = self._makeOne(VALUES) - result = index.search('/', depth=0, include_path=True) - self.assertEqual(sorted(result), [0]) - - def test_search_root_depth_1(self): - index = self._makeOne(VALUES) - result = index.search('/', depth=1) - self.assertEqual(sorted(result), [1,5]) - - def test_search_depth_1_include_path(self): - index = self._makeOne(VALUES) - result = index.search('/', depth=1, include_path=True) - self.assertEqual(sorted(result), [0, 1, 5]) - - def test_search_root_depth_2(self): - index = self._makeOne(VALUES) - result = index.search('/', depth=2) - self.assertEqual(sorted(result), [1, 2, 3, 4, 5, 6, 7, 8]) - - def test_search_depth_2_include_path(self): - index = self._makeOne(VALUES) - result = index.search('/', depth=2, include_path=True) - self.assertEqual(sorted(result), [0, 1, 2, 3, 4, 5, 6, 7, 8]) - - def test_search_root_depth_3(self): - index = self._makeOne(VALUES) - result = index.search('/', depth=3) - self.assertEqual(sorted(result), range(1, 21)) - - def test_search_root_depth_3_include_path(self): - index = self._makeOne(VALUES) - result = index.search('/', depth=3, include_path=True) - self.assertEqual(sorted(result), range(0, 21)) - - def test_search_aa_nodepth(self): - index = self._makeOne(VALUES) - result = index.search('/aa') - self.assertEqual(sorted(result), [2, 3, 4, 9, 10, 11, 12, 13, 14]) - - def test_search_aa_nodepth_include_path(self): - index = self._makeOne(VALUES) - result = index.search('/aa', include_path=True) - self.assertEqual(sorted(result), [1, 2, 3, 4, 9, 10, 11, 12, 13, 14]) - - def test_search_aa_depth_0(self): - index = self._makeOne(VALUES) - result = index.search('/aa', depth=0) - self.assertEqual(sorted(result), []) - - def test_search_aa_depth_0_include_path(self): - index = self._makeOne(VALUES) - result = index.search('/aa', depth=0, include_path=True) - self.assertEqual(sorted(result), [1]) - - def test_search_aa_depth_1(self): - index = self._makeOne(VALUES) - result = index.search('/aa', depth=1) - self.assertEqual(sorted(result), [2,3,4]) - - def test_search_aa_depth_1_include_path(self): - index = self._makeOne(VALUES) - result = index.search('/aa', depth=1, include_path=True) - self.assertEqual(sorted(result), [1, 2, 3, 4]) - - def test_search_bb_nodepth(self): - index = self._makeOne(VALUES) - result = index.search('/bb') - self.assertEqual(sorted(result), [6, 7, 8, 15, 16, 17, 18, 19, 20]) - - def test_search_bb_nodepth_include_path(self): - index = self._makeOne(VALUES) - result = index.search('/bb', include_path=True) - self.assertEqual(sorted(result), [5, 6, 7, 8, 15, 16, 17, 18, 19, 20]) - - def test_search_bb_depth_0(self): - index = self._makeOne(VALUES) - result = index.search('/bb', depth=0) - self.assertEqual(sorted(result), []) - - def test_search_bb_depth_0_include_path(self): - index = self._makeOne(VALUES) - result = index.search('/bb', depth=0, include_path=True) - self.assertEqual(sorted(result), [5]) - - def test_search_bb_depth_1(self): - index = self._makeOne(VALUES) - result = index.search('/bb', depth=1) - self.assertEqual(sorted(result), [6, 7, 8]) - - def test_search_bb_depth_1_include_path(self): - index = self._makeOne(VALUES) - result = index.search('/bb', depth=1, include_path=True) - self.assertEqual(sorted(result), [5, 6, 7, 8]) - - def test_search_with_tuple(self): - index = self._makeOne(VALUES) - result = index.search(('', 'bb')) - self.assertEqual(sorted(result), [6, 7, 8, 15, 16, 17, 18, 19, 20]) - - def test_disjoint_resolved(self): - index = self._makeOne(VALUES) - result = index.search('/disjoint') - self.assertEqual(sorted(result), []) - index.index_doc(22, Dummy('/disjoint')) - result = index.search('/disjoint') - self.assertEqual(sorted(result), [21]) - result = index.search('/') - self.failUnless(22 in result) - - def test_disjoint_resolved_random_order(self): - index = self._makeOne({}) - - index.index_doc(0, Dummy('/disjoint/path/element/1')) - index.index_doc(1, Dummy('/disjoint/path/element/2')) - - result = index.search('/') - self.assertEqual(sorted(result), []) - - index.index_doc(2, Dummy('/disjoint')) - - result = index.search('/') - self.assertEqual(sorted(result), []) - - index.index_doc(3, Dummy('/disjoint/path')) - - result = index.search('/') - self.assertEqual(sorted(result), []) - - index.index_doc(4, Dummy('/')) - - result = index.search('/') - self.assertEqual(sorted(result), [2, 3]) - - index.index_doc(5, Dummy('/disjoint/path/element')) - - result = index.search('/') - self.assertEqual(sorted(result), [0, 1, 2, 3, 5]) - - def test_apply_intersect_wo_docids(self): - index = self._makeOne(VALUES) - result = index.apply_intersect('/aa', None) - self.assertEqual(sorted(result), [2, 3, 4, 9, 10, 11, 12, 13, 14]) - - def test_apply_intersect_w_docids(self): - index = self._makeOne(VALUES) - to_intersect = index.family.IF.Set([2, 3, 4, 7, 8]) - result = index.apply_intersect('/aa', to_intersect) - self.assertEqual(sorted(result), [2, 3, 4]) - - def test_apply_path_string(self): - index = self._makeOne(VALUES) - result = index.apply('/aa') - self.assertEqual(sorted(result), [2, 3, 4, 9, 10, 11, 12, 13, 14]) - - def test_apply_path_string_relative_raises(self): - index = self._makeOne(VALUES) - result = self.assertRaises(ValueError, index.apply, 'aa') - - def test_apply_path_tuple_absolute(self): - index = self._makeOne(VALUES) - result = index.apply(('', 'aa')) - self.assertEqual(sorted(result), [2, 3, 4, 9, 10, 11, 12, 13, 14]) - - def test_apply_path_tuple_relative_raises(self): - index = self._makeOne(VALUES) - result = self.assertRaises(ValueError, index.apply, ('aa',)) - - def test_apply_path_list_absolute(self): - index = self._makeOne(VALUES) - result = index.apply(['', 'aa']) - self.assertEqual(sorted(result), [2, 3, 4, 9, 10, 11, 12, 13, 14]) - - def test_apply_path_list_relative_raises(self): - index = self._makeOne(VALUES) - result = self.assertRaises(ValueError, index.apply, ['aa']) - - def test_apply_path_dict_with_string_query(self): - index = self._makeOne(VALUES) - result = index.apply({'query':'/aa', 'depth':1}) - self.assertEqual(sorted(result), [2, 3, 4]) - - def test_apply_path_dict_with_tuple_query(self): - index = self._makeOne(VALUES) - result = index.apply({'query':('', 'aa'), 'depth':1}) - self.assertEqual(sorted(result), [2, 3, 4]) - - def test_apply_path_dict_with_list_query(self): - index = self._makeOne(VALUES) - result = index.apply({'query':['', 'aa'], 'depth':1}) - self.assertEqual(sorted(result), [2, 3, 4]) - - def test_apply_path_dict_with_include_path_true(self): - index = self._makeOne(VALUES) - result = index.apply({'query':('', 'aa'), 'depth':1, - 'include_path':True}) - self.assertEqual(sorted(result), [1, 2, 3, 4]) - - def test_apply_path_dict_with_include_path_false(self): - index = self._makeOne(VALUES) - result = index.apply({'query':('', 'aa'), 'depth':1, - 'include_path':False}) - self.assertEqual(sorted(result), [2, 3, 4]) - - def test_reindex_doc_nochange(self): - index = self._makeOne(VALUES) - result = index.reindex_doc(1, VALUES[1]) - self.assertEqual(result, False) - - def test_reindex_doc_attradd(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - self.assertEqual(index.docid_to_attr.get(1), None) - result = index.reindex_doc(1, Dummy('/aa', 'acl5')) - self.assertEqual(result, True) - self.assertEqual(index.docid_to_attr[1], 'acl5') - - def test_reindex_doc_attrchange(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - self.assertEqual(index.docid_to_attr[0], 'acl1') - result = index.reindex_doc(0, Dummy('/', 'acl11')) - self.assertEqual(result, True) - self.assertEqual(index.docid_to_attr[0], 'acl11') - - def test_reindex_doc_attrdel(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - self.assertEqual(index.docid_to_attr[0], 'acl1') - result = index.reindex_doc(0, Dummy('/')) - self.assertEqual(result, True) - self.assertEqual(index.docid_to_attr.get(0), None) - - def test_reindex_doc_pathchange(self): - index = self._makeOne(VALUES) - result = index.reindex_doc(1, Dummy('/abcdef')) - self.assertEqual(result, True) - self.assertEqual(index.docid_to_path[1], ('', 'abcdef')) - - def test_index_doc_unindex_doc_with_attr_discriminator(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - attr_keys = sorted(index.docid_to_attr.keys()) - self.assertEqual(attr_keys, [0, 2, 8, 12]) - - docids = VALUES.keys() - - for doc_id in docids: - index.unindex_doc(doc_id) - - self.assertEqual(len(index), 0) - self.assertEqual(list(index.adjacency.keys()), []) - self.assertEqual(list(index.disjoint.keys()), []) - self.assertEqual(list(index.path_to_docid.keys()), []) - self.assertEqual(list(index.docid_to_path.keys()), []) - self.assertEqual(list(index.docid_to_attr.keys()), []) - - index = self._makeOne(VALUES, attr_discriminator='attr') - # randomize the order - import random - random.shuffle(docids) - for doc_id in docids: - index.unindex_doc(doc_id) - - self.assertEqual(len(index), 0) - self.assertEqual(list(index.adjacency.keys()), []) - self.assertEqual(list(index.disjoint.keys()), []) - self.assertEqual(list(index.path_to_docid.keys()), []) - self.assertEqual(list(index.docid_to_path.keys()), []) - self.assertEqual(list(index.docid_to_attr.keys()), []) - - def test_search_root_nodepth_with_attrchecker(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/', attr_checker=attr_checker) - self.assertEqual(sorted(result), range(1, 21)) - results = attr_checker.results - self.assertEqual(len(results), 4) - attrs, theset = results[0] - self.assertEqual(attrs, (12, ['acl1', 'acl4'])) - self.assertEqual(sorted(theset), [12]) - attrs, theset = results[1] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), [1,3,4,5,6,7,11,13,14,15,16,17,18]) - attrs, theset = results[2] - self.assertEqual(attrs, (8, ['acl1', 'acl2'])) - self.assertEqual(sorted(theset), [8, 19, 20]) - attrs, theset = results[3] - self.assertEqual(attrs, (2, ['acl1', 'acl3'])) - self.assertEqual(sorted(theset), [2,9, 10]) - - def test_search_root_nodepth_with_attrchecker_and_include_path(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/', include_path=True, attr_checker=attr_checker) - self.assertEqual(sorted(result), range(0, 21)) - results = attr_checker.results - self.assertEqual(len(results), 4) - attrs, theset = results[0] - self.assertEqual(attrs, (12, ['acl1', 'acl4'])) - self.assertEqual(sorted(theset), [12]) - attrs, theset = results[1] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), [0,1,3,4,5,6,7,11,13,14,15,16,17,18]) - attrs, theset = results[2] - self.assertEqual(attrs, (8, ['acl1', 'acl2'])) - self.assertEqual(sorted(theset), [8, 19, 20]) - attrs, theset = results[3] - self.assertEqual(attrs, (2, ['acl1', 'acl3'])) - self.assertEqual(sorted(theset), [2,9, 10]) - - def test_search_root_depth0_with_attrchecker(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/', depth=0, attr_checker=attr_checker) - self.assertEqual(sorted(result), []) - results = attr_checker.results - self.assertEqual(len(results), 1) - attrs, theset = results[0] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), []) - - def test_search_root_depth0_with_attrchecker_and_include_path(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/', depth=0, include_path=True, - attr_checker=attr_checker) - self.assertEqual(sorted(result), [0]) - results = attr_checker.results - self.assertEqual(len(results), 1) - attrs, theset = results[0] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), [0]) - - def test_search_root_depth1_with_attrchecker(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/', depth=1, attr_checker=attr_checker) - self.assertEqual(sorted(result), [1, 5]) - results = attr_checker.results - self.assertEqual(len(results), 1) - attrs, theset = results[0] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), [1,5]) - - def test_search_root_depth1_with_attrchecker_and_include_path(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/', depth=1, include_path=True, - attr_checker=attr_checker) - self.assertEqual(sorted(result), [0, 1, 5]) - results = attr_checker.results - self.assertEqual(len(results), 1) - attrs, theset = results[0] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), [0, 1, 5]) - - def test_search_root_depth2_with_attrchecker(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/', depth=2, attr_checker=attr_checker) - self.assertEqual(sorted(result), [1, 2, 3, 4, 5, 6, 7, 8]) - results = attr_checker.results - self.assertEqual(len(results), 3) - attrs, theset = results[0] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), [1,3,4,5,6,7]) - attrs, theset = results[1] - self.assertEqual(attrs, (8, ['acl1', 'acl2'])) - self.assertEqual(list(theset), [8]) - attrs, theset = results[2] - self.assertEqual(attrs, (2, ['acl1', 'acl3'])) - self.assertEqual(list(theset), [2]) - - def test_search_root_depth2_with_attrchecker_and_include_path(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/', depth=2, include_path=True, - attr_checker=attr_checker) - self.assertEqual(sorted(result), [0, 1, 2, 3, 4, 5, 6, 7, 8]) - results = attr_checker.results - self.assertEqual(len(results), 3) - attrs, theset = results[0] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), [0,1,3,4,5,6,7]) - attrs, theset = results[1] - self.assertEqual(attrs, (8, ['acl1', 'acl2'])) - self.assertEqual(list(theset), [8]) - attrs, theset = results[2] - self.assertEqual(attrs, (2, ['acl1', 'acl3'])) - self.assertEqual(list(theset), [2]) - - - def test_search_root_depth3_with_attrchecker(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/', depth=3, attr_checker=attr_checker) - self.assertEqual(sorted(result), range(1, 21)) - results = attr_checker.results - self.assertEqual(len(results), 4) - attrs, theset = results[0] - self.assertEqual(attrs, (12, ['acl1', 'acl4'])) - self.assertEqual(list(theset), [12]) - attrs, theset = results[1] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), [1,3,4,5,6,7,11,13,14,15,16,17,18]) - attrs, theset = results[2] - self.assertEqual(attrs, (8, ['acl1', 'acl2'])) - self.assertEqual(list(theset), [8, 19, 20]) - attrs, theset = results[3] - self.assertEqual(attrs, (2, ['acl1', 'acl3'])) - self.assertEqual(list(theset), [2, 9, 10]) - - def test_search_root_depth3_with_attrchecker_and_include_path(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/', depth=3, include_path=True, - attr_checker=attr_checker) - self.assertEqual(sorted(result), range(0, 21)) - results = attr_checker.results - self.assertEqual(len(results), 4) - attrs, theset = results[0] - self.assertEqual(attrs, (12, ['acl1', 'acl4'])) - self.assertEqual(list(theset), [12]) - attrs, theset = results[1] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), [0,1,3,4,5,6,7,11,13,14,15,16,17,18]) - attrs, theset = results[2] - self.assertEqual(attrs, (8, ['acl1', 'acl2'])) - self.assertEqual(list(theset), [8, 19, 20]) - attrs, theset = results[3] - self.assertEqual(attrs, (2, ['acl1', 'acl3'])) - self.assertEqual(list(theset), [2, 9, 10]) - - def test_search_bb_nodepth_with_attrchecker(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/bb', attr_checker=attr_checker) - self.assertEqual(sorted(result), [6, 7, 8, 15, 16, 17, 18, 19, 20]) - results = attr_checker.results - self.assertEqual(len(results), 2) - attrs, theset = results[0] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), [6, 7, 15, 16, 17, 18]) - attrs, theset = results[1] - self.assertEqual(attrs, (8, ['acl1', 'acl2'])) - self.assertEqual(list(theset), [8, 19, 20]) - - def test_search_bb_nodepth_with_attrchecker_and_include_path(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/bb', include_path=True, - attr_checker=attr_checker) - self.assertEqual(sorted(result), [5, 6, 7, 8, 15, 16, 17, 18, 19, 20]) - results = attr_checker.results - self.assertEqual(len(results), 2) - attrs, theset = results[0] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), [5, 6, 7, 15, 16, 17, 18]) - attrs, theset = results[1] - self.assertEqual(attrs, (8, ['acl1', 'acl2'])) - self.assertEqual(list(theset), [8, 19, 20]) - - def test_search_bb_depth0_with_attrchecker(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/bb', depth=0, attr_checker=attr_checker) - self.assertEqual(sorted(result), []) - results = attr_checker.results - self.assertEqual(len(results), 1) - attrs, theset = results[0] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), []) - - def test_search_bb_depth1_with_attrchecker(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/bb', depth=1, attr_checker=attr_checker) - self.assertEqual(sorted(result), [6,7,8]) - results = attr_checker.results - self.assertEqual(len(results), 2) - attrs, theset = results[0] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), [6,7]) - attrs, theset = results[1] - self.assertEqual(attrs, (8, ['acl1', 'acl2'])) - self.assertEqual(list(theset), [8]) - - def test_search_bb_depth2_with_attrchecker(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/bb', depth=2, attr_checker=attr_checker) - self.assertEqual(sorted(result), [6, 7, 8, 15, 16, 17, 18, 19, 20]) - results = attr_checker.results - self.assertEqual(len(results), 2) - attrs, theset = results[0] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), [6, 7, 15, 16, 17, 18]) - attrs, theset = results[1] - self.assertEqual(attrs, (8, ['acl1', 'acl2'])) - self.assertEqual(list(theset), [8, 19, 20]) - - def test_search_bb_depth3_with_attrchecker(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/bb', depth=3, attr_checker=attr_checker) - self.assertEqual(sorted(result), [6, 7, 8, 15, 16, 17, 18, 19, 20]) - results = attr_checker.results - self.assertEqual(len(results), 2) - attrs, theset = results[0] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), [6, 7, 15, 16, 17, 18]) - attrs, theset = results[1] - self.assertEqual(attrs, (8, ['acl1', 'acl2'])) - self.assertEqual(list(theset), [8, 19, 20]) - - def test_search_bb_cc_nodepth_with_attrchecker(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/bb/cc', attr_checker=attr_checker) - self.assertEqual(sorted(result), [19, 20]) - results = attr_checker.results - self.assertEqual(len(results), 2) - attrs, theset = results[0] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), []) - attrs, theset = results[1] - self.assertEqual(attrs, (8, ['acl1', 'acl2'])) - self.assertEqual(list(theset), [19, 20]) - - def test_search_bb_cc_nodepth_with_attrchecker_and_include_path(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/bb/cc', include_path=True, - attr_checker=attr_checker) - self.assertEqual(sorted(result), [8, 19, 20]) - results = attr_checker.results - self.assertEqual(len(results), 2) - attrs, theset = results[0] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), []) - attrs, theset = results[1] - self.assertEqual(attrs, (8, ['acl1', 'acl2'])) - self.assertEqual(list(theset), [8, 19, 20]) - - def test_search_bb_cc_depth0_with_attrchecker(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/bb/cc', depth=0, attr_checker=attr_checker) - self.assertEqual(sorted(result), []) - results = attr_checker.results - self.assertEqual(len(results), 2) - attrs, theset = results[0] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), []) - attrs, theset = results[1] - self.assertEqual(attrs, (8, ['acl1', 'acl2'])) - self.assertEqual(list(theset), []) - - def test_search_bb_cc_depth1_with_attrchecker(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/bb/cc', depth=1, attr_checker=attr_checker) - self.assertEqual(sorted(result), [19, 20]) - results = attr_checker.results - self.assertEqual(len(results), 2) - attrs, theset = results[0] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), []) - attrs, theset = results[1] - self.assertEqual(attrs, (8, ['acl1', 'acl2'])) - self.assertEqual(list(theset), [19, 20]) - - def test_search_bb_cc_depth2_with_attrchecker(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/bb/cc', depth=2, attr_checker=attr_checker) - self.assertEqual(sorted(result), [19, 20]) - results = attr_checker.results - self.assertEqual(len(results), 2) - attrs, theset = results[0] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), []) - attrs, theset = results[1] - self.assertEqual(attrs, (8, ['acl1', 'acl2'])) - self.assertEqual(list(theset), [19, 20]) - - def test_search_bb_cc_11_nodepth_with_attrchecker(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/bb/cc/11.html', attr_checker=attr_checker) - self.assertEqual(sorted(result), []) - results = attr_checker.results - self.assertEqual(len(results), 2) - attrs, theset = results[0] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), []) - attrs, theset = results[1] - self.assertEqual(attrs, (8, ['acl1', 'acl2'])) - self.assertEqual(list(theset), []) - - def test_search_bb_cc_11_nodepth_with_attrchecker_include_path(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/bb/cc/11.html', include_path=True, - attr_checker=attr_checker) - self.assertEqual(sorted(result), [19]) - results = attr_checker.results - self.assertEqual(len(results), 2) - attrs, theset = results[0] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), []) - attrs, theset = results[1] - self.assertEqual(attrs, (8, ['acl1', 'acl2'])) - self.assertEqual(list(theset), [19]) - - def test_search_bb_cc_11_depth0_with_attrchecker(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/bb/cc/11.html', depth=0, - attr_checker=attr_checker) - self.assertEqual(sorted(result), []) - results = attr_checker.results - self.assertEqual(len(results), 2) - attrs, theset = results[0] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), []) - attrs, theset = results[1] - self.assertEqual(attrs, (8, ['acl1', 'acl2'])) - self.assertEqual(list(theset), []) - - def test_search_bb_cc_11_depth1_with_attrchecker(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/bb/cc/11.html', depth=1, - attr_checker=attr_checker) - self.assertEqual(sorted(result), []) - results = attr_checker.results - self.assertEqual(len(results), 2) - attrs, theset = results[0] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), []) - attrs, theset = results[1] - self.assertEqual(attrs, (8, ['acl1', 'acl2'])) - self.assertEqual(list(theset), []) - - def test_search_bb_cc_11_depth1_with_attrchecker_and_includepath(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/bb/cc/11.html', depth=1, include_path=True, - attr_checker=attr_checker) - self.assertEqual(sorted(result), [19]) - results = attr_checker.results - self.assertEqual(len(results), 2) - attrs, theset = results[0] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), []) - attrs, theset = results[1] - self.assertEqual(attrs, (8, ['acl1', 'acl2'])) - self.assertEqual(list(theset), [19]) - - def test_search_root_nodepth_with_attrchecker_values2(self): - index = self._makeOne(VALUES2, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/', attr_checker=attr_checker) - self.assertEqual(sorted(result), range(1, 6)) - results = attr_checker.results - self.assertEqual(len(results), 6) - attrs, theset = results[0] - self.assertEqual(attrs, (1, ['acl1', 'acl2'])) - self.assertEqual(list(theset), [1]) - attrs, theset = results[1] - self.assertEqual(attrs, (3, ['acl1', 'acl2', 'acl4'])) - self.assertEqual(list(theset), [3]) - attrs, theset = results[2] - self.assertEqual(attrs, (4, ['acl1', 'acl2', 'acl5'])) - self.assertEqual(list(theset), [4]) - attrs, theset = results[3] - self.assertEqual(attrs, (2, ['acl1', 'acl2', 'acl3'])) - self.assertEqual(list(theset), [2]) - attrs, theset = results[4] - self.assertEqual(attrs, (5, ['acl1', 'acl6'])) - self.assertEqual(list(theset), [5]) - attrs, theset = results[5] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), []) - - def test_search_root_nodepth_with_attrchecker_incpath_values2(self): - index = self._makeOne(VALUES2, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/', include_path=True, attr_checker=attr_checker) - self.assertEqual(sorted(result), range(0, 6)) - results = attr_checker.results - self.assertEqual(len(results), 6) - attrs, theset = results[0] - self.assertEqual(attrs, (1, ['acl1', 'acl2'])) - self.assertEqual(list(theset), [1]) - attrs, theset = results[1] - self.assertEqual(attrs, (3, ['acl1', 'acl2', 'acl4'])) - self.assertEqual(list(theset), [3]) - attrs, theset = results[2] - self.assertEqual(attrs, (4, ['acl1', 'acl2', 'acl5'])) - self.assertEqual(list(theset), [4]) - attrs, theset = results[3] - self.assertEqual(attrs, (2, ['acl1', 'acl2', 'acl3'])) - self.assertEqual(list(theset), [2]) - attrs, theset = results[4] - self.assertEqual(attrs, (5, ['acl1', 'acl6'])) - self.assertEqual(list(theset), [5]) - attrs, theset = results[5] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), [0]) - - def test_search_root_depth0_with_attrchecker_values2(self): - index = self._makeOne(VALUES2, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/', depth=0, attr_checker=attr_checker) - self.assertEqual(sorted(result), []) - results = attr_checker.results - self.assertEqual(len(results), 1) - attrs, theset = results[0] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), []) - - def test_search_root_depth0_with_attrchecker_incpath_values2(self): - index = self._makeOne(VALUES2, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/', include_path=True, depth=0, - attr_checker=attr_checker) - self.assertEqual(sorted(result), [0]) - results = attr_checker.results - self.assertEqual(len(results), 1) - attrs, theset = results[0] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), [0]) - - def test_search_root_depth1_with_attrchecker_values2(self): - index = self._makeOne(VALUES2, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/', depth=1, attr_checker=attr_checker) - self.assertEqual(sorted(result), [1,5]) - results = attr_checker.results - self.assertEqual(len(results), 3) - attrs, theset = results[0] - self.assertEqual(attrs, (5, ['acl1', 'acl6'])) - self.assertEqual(list(theset), [5]) - attrs, theset = results[1] - self.assertEqual(attrs, (1, ['acl1', 'acl2'])) - self.assertEqual(list(theset), [1]) - attrs, theset = results[2] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), []) - - def test_search_root_depth1_with_attrchecker_incpath_values2(self): - index = self._makeOne(VALUES2, attr_discriminator='attr') - attr_checker = DummyAttrChecker() - result = index.search('/', include_path=True, depth=1, - attr_checker=attr_checker) - self.assertEqual(sorted(result), [0, 1, 5]) - results = attr_checker.results - self.assertEqual(len(results), 3) - attrs, theset = results[0] - self.assertEqual(attrs, (5, ['acl1', 'acl6'])) - self.assertEqual(list(theset), [5]) - attrs, theset = results[1] - self.assertEqual(attrs, (1, ['acl1', 'acl2'])) - self.assertEqual(list(theset), [1]) - attrs, theset = results[2] - self.assertEqual(attrs, (0, ['acl1'])) - self.assertEqual(list(theset), [0]) - - def test__indexed(self): - index = self._makeOne(VALUES, attr_discriminator='attr') - self.assertEqual( - set(index._indexed()), - set(range(22))) - -class DummyAttrChecker(object): - def __init__(self): - pass - - def __call__(self, results): - import BTrees - self.results = results - return BTrees.family64.IF.multiunion([x[1] for x in results]) - -class Dummy: - - def __init__( self, path, attr=None): - self.path = path - if attr is not None: - self.attr = attr - -VALUES = { - 0 : Dummy('/', 'acl1'), - 1 : Dummy('/aa'), - 2 : Dummy('/aa/aa', 'acl3'), - 3 : Dummy('/aa/bb'), - 4 : Dummy('/aa/cc'), - 5 : Dummy('/bb'), - 6 : Dummy('/bb/aa'), - 7 : Dummy('/bb/bb'), - 8 : Dummy('/bb/cc', 'acl2'), - 9 : Dummy("/aa/aa/1.html"), - 10 : Dummy("/aa/aa/2.html"), - 11 : Dummy("/aa/bb/3.html"), - 12 : Dummy("/aa/bb/4.html", 'acl4'), - 13 : Dummy("/aa/cc/5.html"), - 14 : Dummy("/aa/cc/6.html"), - 15 : Dummy("/bb/aa/7.html"), - 16 : Dummy("/bb/aa/8.html"), - 17 : Dummy("/bb/bb/9.html"), - 18 : Dummy("/bb/bb/10.html"), - 19 : Dummy("/bb/cc/11.html"), - 20 : Dummy("/bb/cc/12.html"), - 21 : Dummy('/disjoint/entry') - } - -VALUES2 = { - 0 : Dummy('/', 'acl1'), - 1 : Dummy('/aa', 'acl2'), - 2 : Dummy('/aa/aa', 'acl3'), - 3 : Dummy('/aa/bb', 'acl4'), - 4 : Dummy('/aa/cc', 'acl5'), - 5 : Dummy('/bb', 'acl6'), - } diff --git a/hypatia/tests/test_catalog.py b/hypatia/tests/test_catalog.py index c9d07e9..a5ca58f 100644 --- a/hypatia/tests/test_catalog.py +++ b/hypatia/tests/test_catalog.py @@ -220,27 +220,21 @@ def _test_functional_merge(self, **extra): from ..indexes.field import FieldIndex from ..indexes.keyword import KeywordIndex from ..indexes.text import TextIndex - from ..indexes.path2 import CatalogPathIndex2 class Content(object): - def __init__(self, field, keyword, text, path): + def __init__(self, field, keyword, text): self.field = field self.keyword = keyword self.text = text - self.path = path field = FieldIndex('field') keyword = KeywordIndex('keyword') text = TextIndex('text') - path = CatalogPathIndex2('path') catalog['field'] = field catalog['keyword'] = keyword catalog['text'] = text - catalog['path'] = path map = { - 1:Content('field1', ['keyword1', 'same'], 'text one', '/path1'), - 2:Content('field2', ['keyword2', 'same'], 'text two', - '/path1/path2'), - 3:Content('field3', ['keyword3', 'same'], 'text three', - '/path1/path2/path3'), + 1:Content('field1', ['keyword1', 'same'], 'text one'), + 2:Content('field2', ['keyword2', 'same'], 'text two'), + 3:Content('field3', ['keyword3', 'same'], 'text three'), } for num, doc in map.items(): catalog.index_doc(num, doc) @@ -262,16 +256,12 @@ def __init__(self, field, keyword, text, path): self.assertEqual(num, 3) self.assertEqual(list(result), [1,2,3]) - num, result = catalog.search(text='text', path='/path1', **extra) - self.assertEqual(num, 2) - self.assertEqual(list(result), [2,3]) - def test_functional_index_merge_unordered(self): return self._test_functional_merge() def test_functional_index_merge_ordered(self): return self._test_functional_merge( - index_query_order=['field', 'keyword', 'text', 'path']) + index_query_order=['field', 'keyword', 'text']) class TestFileStorageCatalogFactory(unittest.TestCase): def _getTargetClass(self):