<s> import unittest <EOL> from pyramid import testing <EOL> import BTrees <EOL> from ... _compat import u <EOL> _BLANK = u ( '<STR_LIT>' ) <EOL> _A = u ( '<STR_LIT:a>' ) <EOL> _ABC = u ( '<STR_LIT:abc>' ) <EOL> def _makeSite ( ** kw ) : <EOL> from ... interfaces import IFolder <EOL> from ... interfaces import IService <EOL> from zope . interface import alsoProvides <EOL> site = testing . DummyResource ( __provides__ = kw . pop ( '<STR_LIT>' , None ) ) <EOL> alsoProvides ( site , IFolder ) <EOL> for k , v in kw . items ( ) : <EOL> site [ k ] = v <EOL> alsoProvides ( v , IService ) <EOL> return site <EOL> class TestFakeIndex ( unittest . TestCase ) : <EOL> def _makeOne ( self ) : <EOL> from . . indexes import FakeIndex <EOL> return FakeIndex ( ) <EOL> def test_reset ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> inst . reset ( ) <EOL> self . assertEqual ( list ( inst . _not_indexed ) , [ ] ) <EOL> def test_index_doc ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> self . assertEqual ( inst . index_doc ( <NUM_LIT:1> , None ) , None ) <EOL> def test_unindex_doc ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> self . assertEqual ( inst . unindex_doc ( <NUM_LIT:1> ) , None ) <EOL> def test_reindex_doc ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> self . assertEqual ( inst . reindex_doc ( <NUM_LIT:1> , None ) , None ) <EOL> def test_docids ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> fake_catalog = Dummy ( ) <EOL> fake_catalog . objectids = [ <NUM_LIT:1> ] <EOL> inst . __parent__ = fake_catalog <EOL> self . assertEqual ( inst . docids ( ) , [ <NUM_LIT:1> ] ) <EOL> def test_indexed ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> fake_catalog = Dummy ( ) <EOL> fake_catalog . objectids = [ <NUM_LIT:1> ] <EOL> inst . __parent__ = fake_catalog <EOL> self . assertEqual ( inst . indexed ( ) , [ <NUM_LIT:1> ] ) <EOL> def test_not_indexed ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> inst . _not_indexed = [ <NUM_LIT:1> ] <EOL> self . assertEqual ( inst . not_indexed ( ) , [ <NUM_LIT:1> ] ) <EOL> class TestSDIndex ( unittest . TestCase ) : <EOL> def _makeOne ( self , oid = <NUM_LIT:1> ) : <EOL> from . . indexes import SDIndex <EOL> index = SDIndex ( ) <EOL> index . __oid__ = oid <EOL> return index <EOL> def test_resultset_from_query_no_resolver ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> inst . __objectmap__ = DummyObjectmap ( ) <EOL> query = DummyQuery ( ) <EOL> resultset = inst . resultset_from_query ( query ) <EOL> self . assertEqual ( resultset . ids , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> self . assertEqual ( resultset . resolver , inst . __objectmap__ . object_for ) <EOL> self . assertTrue ( query . flushed ) <EOL> def test_resultset_from_query_with_resolver ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> inst . __objectmap__ = DummyObjectmap ( ) <EOL> query = DummyQuery ( ) <EOL> resolver = object ( ) <EOL> resultset = inst . resultset_from_query ( query , resolver = resolver ) <EOL> self . assertEqual ( resultset . ids , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> self . assertEqual ( resultset . resolver , resolver ) <EOL> self . assertTrue ( query . flushed ) <EOL> def test_get_action_tm_existing_action_tm ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> tm = DummyActionTM ( None ) <EOL> inst . _p_action_tm = tm <EOL> self . assertEqual ( inst . get_action_tm ( ) , tm ) <EOL> def test_get_action_tm_no_existing_action_tm ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> inst . tm_class = DummyActionTM <EOL> result = inst . get_action_tm ( ) <EOL> self . assertEqual ( result . __class__ , DummyActionTM ) <EOL> self . assertEqual ( result . index , inst ) <EOL> self . assertTrue ( result . registered ) <EOL> def test_flush ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> tm = DummyActionTM ( None ) <EOL> inst . _p_action_tm = tm <EOL> inst . flush ( '<STR_LIT:abc>' ) <EOL> self . assertEqual ( tm . flushed , '<STR_LIT:abc>' ) <EOL> def test_flush_no_tm ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> inst . _p_action_tm = None <EOL> self . assertEqual ( inst . flush ( ) , None ) <EOL> def test_add_action ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> tm = DummyActionTM ( None ) <EOL> inst . _p_action_tm = tm <EOL> inst . add_action ( True ) <EOL> self . assertEqual ( tm . actions , [ True ] ) <EOL> def test_index_resource_default_action_mode_is_MODE_ATCOMMIT ( self ) : <EOL> resource = testing . DummyResource ( ) <EOL> inst = self . _makeOne ( ) <EOL> tm = DummyActionTM ( None ) <EOL> inst . _p_action_tm = tm <EOL> inst . index_resource ( resource , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( tm . actions ) , <NUM_LIT:1> ) <EOL> def test_index_resource_action_MODE_IMMEDIATE ( self ) : <EOL> from substanced . interfaces import MODE_IMMEDIATE <EOL> resource = testing . DummyResource ( ) <EOL> inst = self . _makeOne ( ) <EOL> L = [ ] <EOL> inst . index_doc = lambda oid , resource : L . append ( ( oid , resource ) ) <EOL> inst . index_resource ( resource , <NUM_LIT:1> , action_mode = MODE_IMMEDIATE ) <EOL> self . assertEqual ( L , [ ( <NUM_LIT:1> , resource ) ] ) <EOL> def test_index_resource_action_MODE_ATCOMMIT ( self ) : <EOL> from substanced . interfaces import MODE_ATCOMMIT <EOL> resource = testing . DummyResource ( ) <EOL> inst = self . _makeOne ( ) <EOL> tm = DummyActionTM ( None ) <EOL> inst . _p_action_tm = tm <EOL> inst . index_resource ( resource , <NUM_LIT:1> , action_mode = MODE_ATCOMMIT ) <EOL> self . assertEqual ( len ( tm . actions ) , <NUM_LIT:1> ) <EOL> action = tm . actions [ <NUM_LIT:0> ] <EOL> self . assertEqual ( action . __class__ . __name__ , '<STR_LIT>' ) <EOL> self . assertEqual ( action . oid , <NUM_LIT:1> ) <EOL> self . assertEqual ( action . mode , MODE_ATCOMMIT ) <EOL> self . assertEqual ( action . index , inst ) <EOL> def test_index_resource_oid_is_None ( self ) : <EOL> from substanced . interfaces import MODE_IMMEDIATE <EOL> resource = testing . DummyResource ( ) <EOL> resource . __oid__ = <NUM_LIT:1> <EOL> inst = self . _makeOne ( ) <EOL> L = [ ] <EOL> inst . index_doc = lambda oid , resource : L . append ( ( oid , resource ) ) <EOL> inst . index_resource ( resource , action_mode = MODE_IMMEDIATE ) <EOL> self . assertEqual ( L , [ ( <NUM_LIT:1> , resource ) ] ) <EOL> def test_reindex_resource_default_action_mode_is_MODE_ATCOMMIT ( self ) : <EOL> resource = testing . DummyResource ( ) <EOL> inst = self . _makeOne ( ) <EOL> inst = self . _makeOne ( ) <EOL> tm = DummyActionTM ( None ) <EOL> inst . _p_action_tm = tm <EOL> inst . reindex_resource ( resource , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( tm . actions ) , <NUM_LIT:1> ) <EOL> def test_reindex_resource_action_MODE_IMMEDIATE ( self ) : <EOL> from substanced . interfaces import MODE_IMMEDIATE <EOL> resource = testing . DummyResource ( ) <EOL> inst = self . _makeOne ( ) <EOL> L = [ ] <EOL> inst . reindex_doc = lambda oid , resource : L . append ( ( oid , resource ) ) <EOL> inst . reindex_resource ( resource , <NUM_LIT:1> , action_mode = MODE_IMMEDIATE ) <EOL> self . assertEqual ( L , [ ( <NUM_LIT:1> , resource ) ] ) <EOL> def test_reindex_resource_action_MODE_ATCOMMIT ( self ) : <EOL> from substanced . interfaces import MODE_ATCOMMIT <EOL> resource = testing . DummyResource ( ) <EOL> inst = self . _makeOne ( ) <EOL> tm = DummyActionTM ( None ) <EOL> inst . _p_action_tm = tm <EOL> inst . reindex_resource ( resource , <NUM_LIT:1> , action_mode = MODE_ATCOMMIT ) <EOL> self . assertEqual ( len ( tm . actions ) , <NUM_LIT:1> ) <EOL> action = tm . actions [ <NUM_LIT:0> ] <EOL> self . assertEqual ( action . __class__ . __name__ , '<STR_LIT>' ) <EOL> self . assertEqual ( action . oid , <NUM_LIT:1> ) <EOL> self . assertEqual ( action . mode , MODE_ATCOMMIT ) <EOL> self . assertEqual ( action . index , inst ) <EOL> def test_reindex_resource_no_oid ( self ) : <EOL> from substanced . interfaces import MODE_IMMEDIATE <EOL> resource = testing . DummyResource ( ) <EOL> resource . __oid__ = <NUM_LIT:1> <EOL> inst = self . _makeOne ( ) <EOL> L = [ ] <EOL> inst . reindex_doc = lambda oid , resource : L . append ( ( oid , resource ) ) <EOL> inst . reindex_resource ( resource , action_mode = MODE_IMMEDIATE ) <EOL> self . assertEqual ( L , [ ( <NUM_LIT:1> , resource ) ] ) <EOL> def test_unindex_resource_default_mode_is_MODE_ATCOMMIT ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> tm = DummyActionTM ( None ) <EOL> inst . _p_action_tm = tm <EOL> inst . unindex_resource ( <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( tm . actions ) , <NUM_LIT:1> ) <EOL> def test_unindex_resource_action_MODE_IMMEDIATE ( self ) : <EOL> from substanced . interfaces import MODE_IMMEDIATE <EOL> inst = self . _makeOne ( ) <EOL> L = [ ] <EOL> inst . unindex_doc = lambda oid : L . append ( oid ) <EOL> inst . unindex_resource ( <NUM_LIT:1> , action_mode = MODE_IMMEDIATE ) <EOL> self . assertEqual ( L , [ <NUM_LIT:1> ] ) <EOL> def test_unindex_resource_action_MODE_ATCOMMIT ( self ) : <EOL> from substanced . interfaces import MODE_ATCOMMIT <EOL> inst = self . _makeOne ( ) <EOL> tm = DummyActionTM ( None ) <EOL> inst . _p_action_tm = tm <EOL> inst . unindex_resource ( <NUM_LIT:1> , action_mode = MODE_ATCOMMIT ) <EOL> self . assertEqual ( len ( tm . actions ) , <NUM_LIT:1> ) <EOL> action = tm . actions [ <NUM_LIT:0> ] <EOL> self . assertEqual ( action . __class__ . __name__ , '<STR_LIT>' ) <EOL> self . assertEqual ( action . oid , <NUM_LIT:1> ) <EOL> self . assertEqual ( action . mode , MODE_ATCOMMIT ) <EOL> self . assertEqual ( action . index , inst ) <EOL> def test_unindex_resource_resource_is_not_oid ( self ) : <EOL> from substanced . interfaces import MODE_IMMEDIATE <EOL> resource = testing . DummyResource ( ) <EOL> resource . __oid__ = <NUM_LIT:1> <EOL> inst = self . _makeOne ( ) <EOL> L = [ ] <EOL> inst . unindex_doc = lambda oid : L . append ( oid ) <EOL> inst . unindex_resource ( resource , action_mode = MODE_IMMEDIATE ) <EOL> self . assertEqual ( L , [ <NUM_LIT:1> ] ) <EOL> def test_repr ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> inst . __name__ = '<STR_LIT>' <EOL> r = repr ( inst ) <EOL> self . assertTrue ( r . startswith ( <EOL> "<STR_LIT>" ) ) <EOL> class TestPathIndex ( unittest . TestCase ) : <EOL> def _makeOne ( self , family = None ) : <EOL> from . . indexes import PathIndex <EOL> from ... objectmap import ObjectMap <EOL> catalog = DummyCatalog ( ) <EOL> index = PathIndex ( family = family ) <EOL> index . __parent__ = catalog <EOL> site = _makeSite ( catalog = catalog ) <EOL> objectmap = ObjectMap ( site ) <EOL> site . __objectmap__ = objectmap <EOL> return index <EOL> def _acquire ( self , inst , name ) : <EOL> from substanced . util import acquire <EOL> return acquire ( inst , name ) <EOL> def test_document_repr ( self ) : <EOL> from substanced . util import get_oid <EOL> inst = self . _makeOne ( ) <EOL> obj = testing . DummyResource ( ) <EOL> objectmap = self . _acquire ( inst , '<STR_LIT>' ) <EOL> objectmap . add ( obj , ( _BLANK , ) ) <EOL> result = inst . document_repr ( get_oid ( obj ) ) <EOL> self . assertEqual ( result , ( _BLANK , ) ) <EOL> def test_document_repr_missing ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> result = inst . document_repr ( <NUM_LIT:1> ) <EOL> self . assertEqual ( result , None ) <EOL> def test_ctor_alternate_family ( self ) : <EOL> inst = self . _makeOne ( family = BTrees . family32 ) <EOL> self . assertEqual ( inst . family , BTrees . family32 ) <EOL> def test_index_doc ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> result = inst . index_doc ( <NUM_LIT:1> , None ) <EOL> self . assertEqual ( result , None ) <EOL> def test_unindex_doc ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> result = inst . unindex_doc ( <NUM_LIT:1> ) <EOL> self . assertEqual ( result , None ) <EOL> def test_reindex_doc ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> result = inst . reindex_doc ( <NUM_LIT:1> , None ) <EOL> self . assertEqual ( result , None ) <EOL> def test_docids ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> result = inst . docids ( ) <EOL> self . assertEqual ( list ( result ) , [ ] ) <EOL> def test_not_indexed ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> result = inst . not_indexed ( ) <EOL> self . assertEqual ( list ( result ) , [ ] ) <EOL> def test_search ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> obj = testing . DummyResource ( ) <EOL> objectmap = self . _acquire ( inst , '<STR_LIT>' ) <EOL> objectmap . _v_nextid = <NUM_LIT:1> <EOL> objectmap . add ( obj , ( _BLANK , ) ) <EOL> result = inst . search ( ( _BLANK , ) ) <EOL> self . assertEqual ( list ( result ) , [ <NUM_LIT:1> ] ) <EOL> def test_apply_obj ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> obj = testing . DummyResource ( ) <EOL> objectmap = self . _acquire ( inst , '<STR_LIT>' ) <EOL> objectmap . _v_nextid = <NUM_LIT:1> <EOL> objectmap . add ( obj , ( _BLANK , ) ) <EOL> result = inst . apply ( obj ) <EOL> self . assertEqual ( list ( result ) , [ <NUM_LIT:1> ] ) <EOL> def test_apply_obj_noresults ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> obj = testing . DummyResource ( ) <EOL> result = inst . apply ( obj ) <EOL> self . assertEqual ( list ( result ) , [ ] ) <EOL> def test_apply_path ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> obj = testing . DummyResource ( ) <EOL> objectmap = self . _acquire ( inst , '<STR_LIT>' ) <EOL> objectmap . _v_nextid = <NUM_LIT:1> <EOL> objectmap . add ( obj , ( _BLANK , ) ) <EOL> result = inst . apply ( ( _BLANK , ) ) <EOL> self . assertEqual ( list ( result ) , [ <NUM_LIT:1> ] ) <EOL> def test_apply_dict ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> obj = testing . DummyResource ( ) <EOL> objectmap = self . _acquire ( inst , '<STR_LIT>' ) <EOL> objectmap . _v_nextid = <NUM_LIT:1> <EOL> objectmap . add ( obj , ( _BLANK , ) ) <EOL> obj2 = testing . DummyResource ( __name__ = '<STR_LIT:a>' ) <EOL> obj2 . __parent__ = obj <EOL> objectmap . add ( obj2 , ( _BLANK , _A ) ) <EOL> result = inst . apply ( { '<STR_LIT:path>' : obj } ) <EOL> self . assertEqual ( list ( result ) , [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> def test_apply_dict_withdepth ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> obj = testing . DummyResource ( ) <EOL> objectmap = self . _acquire ( inst , '<STR_LIT>' ) <EOL> objectmap . _v_nextid = <NUM_LIT:1> <EOL> objectmap . add ( obj , ( _BLANK , ) ) <EOL> obj2 = testing . DummyResource ( __name__ = '<STR_LIT:a>' ) <EOL> obj2 . __parent__ = obj <EOL> objectmap . add ( obj2 , ( _BLANK , _A ) ) <EOL> result = inst . apply ( { '<STR_LIT:path>' : obj , '<STR_LIT>' : <NUM_LIT:0> } ) <EOL> self . assertEqual ( list ( result ) , [ <NUM_LIT:1> ] ) <EOL> def test_apply_dict_with_include_origin_false ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> obj = testing . DummyResource ( ) <EOL> objectmap = self . _acquire ( inst , '<STR_LIT>' ) <EOL> objectmap . _v_nextid = <NUM_LIT:1> <EOL> objectmap . add ( obj , ( _BLANK , ) ) <EOL> obj2 = testing . DummyResource ( __name__ = '<STR_LIT:a>' ) <EOL> obj2 . __parent__ = obj <EOL> objectmap . add ( obj2 , ( _BLANK , _A ) ) <EOL> result = inst . apply ( { '<STR_LIT:path>' : obj , '<STR_LIT>' : False } ) <EOL> self . assertEqual ( list ( result ) , [ <NUM_LIT:2> ] ) <EOL> def test_applyNotEq ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> catalog = inst . __parent__ <EOL> obj = testing . DummyResource ( ) <EOL> objectmap = self . _acquire ( inst , '<STR_LIT>' ) <EOL> objectmap . _v_nextid = <NUM_LIT:1> <EOL> objectmap . add ( obj , ( _BLANK , ) ) <EOL> catalog . objectids = catalog . family . IF . TreeSet ( [ <NUM_LIT:1> ] ) <EOL> result = inst . applyNotEq ( obj ) <EOL> self . assertEqual ( list ( result ) , [ ] ) <EOL> def test__parse_path_obj ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> obj = testing . DummyResource ( ) <EOL> result = inst . _parse_path ( obj ) <EOL> self . assertEqual ( result , ( ( _BLANK , ) , None , True ) ) <EOL> def test__parse_path_path_tuple ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> result = inst . _parse_path ( ( _BLANK , ) ) <EOL> self . assertEqual ( result , ( ( _BLANK , ) , None , True ) ) <EOL> def test__parse_path_path_str ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> result = inst . _parse_path ( '<STR_LIT:/>' ) <EOL> self . assertEqual ( result , ( ( _BLANK , ) , None , True ) ) <EOL> def test__parse_path_path_str_with_depth ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> result = inst . _parse_path ( '<STR_LIT>' ) <EOL> self . assertEqual ( result , ( ( _BLANK , _ABC ) , <NUM_LIT:2> , True ) ) <EOL> def test__parse_path_path_str_with_origin_false ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> result = inst . _parse_path ( '<STR_LIT>' ) <EOL> self . assertEqual ( result , ( ( _BLANK , _ABC ) , None , False ) ) <EOL> def test__parse_path_path_str_with_depth_and_origin ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> result = inst . _parse_path ( '<STR_LIT>' ) <EOL> self . assertEqual ( result , ( ( _BLANK , _ABC ) , <NUM_LIT:2> , False ) ) <EOL> def test__parse_path_path_str_with_depth_and_origin_no_val ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> result = inst . _parse_path ( '<STR_LIT>' ) <EOL> self . assertEqual ( result , ( ( _BLANK , _ABC ) , <NUM_LIT:2> , True ) ) <EOL> def test__parse_path_path_invalid ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> self . assertRaises ( ValueError , inst . _parse_path , None ) <EOL> def test__parse_path_path_invalid_string_no_begin_slash ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> self . assertRaises ( ValueError , inst . _parse_path , '<STR_LIT>' ) <EOL> def test_apply_intersect ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> obj = testing . DummyResource ( ) <EOL> objectmap = self . _acquire ( inst , '<STR_LIT>' ) <EOL> objectmap . _v_nextid = <NUM_LIT:1> <EOL> objectmap . add ( obj , ( _BLANK , ) ) <EOL> result = inst . apply_intersect ( obj , objectmap . family . IF . Set ( [ <NUM_LIT:1> ] ) ) <EOL> self . assertEqual ( list ( result ) , [ <NUM_LIT:1> ] ) <EOL> def test_eq_defaults ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> result = inst . eq ( '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> result . _value , <EOL> { '<STR_LIT:path>' : '<STR_LIT>' } <EOL> ) <EOL> def test_eq_include_origin_is_False ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> inst . depth = <NUM_LIT:10> <EOL> result = inst . eq ( '<STR_LIT>' , include_origin = False ) <EOL> self . assertEqual ( <EOL> result . _value , <EOL> { '<STR_LIT:path>' : '<STR_LIT>' , '<STR_LIT>' : False } <EOL> ) <EOL> def test_eq_include_depth_is_not_None ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> inst . depth = <NUM_LIT:10> <EOL> result = inst . eq ( '<STR_LIT>' , depth = <NUM_LIT:1> ) <EOL> self . assertEqual ( <EOL> result . _value , <EOL> { '<STR_LIT:path>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:1> } <EOL> ) <EOL> def test_noteq_defaults ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> result = inst . noteq ( '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> result . _value , <EOL> { '<STR_LIT:path>' : '<STR_LIT>' } <EOL> ) <EOL> def test_noteq_include_origin_is_False ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> inst . depth = <NUM_LIT:10> <EOL> result = inst . noteq ( '<STR_LIT>' , include_origin = False ) <EOL> self . assertEqual ( <EOL> result . _value , <EOL> { '<STR_LIT:path>' : '<STR_LIT>' , '<STR_LIT>' : False } <EOL> ) <EOL> def test_noteq_include_depth_is_not_None ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> inst . depth = <NUM_LIT:10> <EOL> result = inst . noteq ( '<STR_LIT>' , depth = <NUM_LIT:1> ) <EOL> self . assertEqual ( <EOL> result . _value , <EOL> { '<STR_LIT:path>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:1> } <EOL> ) <EOL> class TestFieldIndex ( unittest . TestCase ) : <EOL> def _makeOne ( self , discriminator = None , family = None , action_mode = None ) : <EOL> from . . indexes import FieldIndex <EOL> return FieldIndex ( discriminator , family , action_mode = action_mode ) <EOL> def test_ctor_with_discriminator ( self ) : <EOL> inst = self . _makeOne ( '<STR_LIT:abc>' ) <EOL> self . assertEqual ( inst . discriminator , '<STR_LIT:abc>' ) <EOL> def test_ctor_without_discriminator ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> self . assertEqual ( inst . discriminator . __class__ , type ( lambda x : True ) ) <EOL> def test_ctor_with_action_mode ( self ) : <EOL> from substanced . interfaces import MODE_IMMEDIATE <EOL> inst = self . _makeOne ( '<STR_LIT:abc>' , action_mode = MODE_IMMEDIATE ) <EOL> self . assertEqual ( inst . action_mode , MODE_IMMEDIATE ) <EOL> def test_ctor_without_action_mode ( self ) : <EOL> from substanced . interfaces import MODE_ATCOMMIT <EOL> inst = self . _makeOne ( '<STR_LIT:abc>' ) <EOL> self . assertEqual ( inst . action_mode , MODE_ATCOMMIT ) <EOL> class TestKeywordIndex ( unittest . TestCase ) : <EOL> def _makeOne ( self , discriminator = None , family = None , action_mode = None ) : <EOL> from . . indexes import KeywordIndex <EOL> return KeywordIndex ( discriminator , family , action_mode = action_mode ) <EOL> def test_ctor_with_discriminator ( self ) : <EOL> inst = self . _makeOne ( '<STR_LIT:abc>' ) <EOL> self . assertEqual ( inst . discriminator , '<STR_LIT:abc>' ) <EOL> def test_ctor_without_discriminator ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> self . assertEqual ( inst . discriminator . __class__ , type ( lambda x : True ) ) <EOL> def test_ctor_with_action_mode ( self ) : <EOL> from substanced . interfaces import MODE_IMMEDIATE <EOL> inst = self . _makeOne ( '<STR_LIT:abc>' , action_mode = MODE_IMMEDIATE ) <EOL> self . assertEqual ( inst . action_mode , MODE_IMMEDIATE ) <EOL> def test_ctor_without_action_mode ( self ) : <EOL> from substanced . interfaces import MODE_ATCOMMIT <EOL> inst = self . _makeOne ( '<STR_LIT:abc>' ) <EOL> self . assertEqual ( inst . action_mode , MODE_ATCOMMIT ) <EOL> class TestFacetIndex ( unittest . TestCase ) : <EOL> def _makeOne ( self , discriminator = None , facets = None , family = None , <EOL> action_mode = None ) : <EOL> from . . indexes import FacetIndex <EOL> return FacetIndex ( discriminator , facets , family , <EOL> action_mode = action_mode ) <EOL> def test_ctor_with_discriminator ( self ) : <EOL> inst = self . _makeOne ( '<STR_LIT:abc>' ) <EOL> self . assertEqual ( inst . discriminator , '<STR_LIT:abc>' ) <EOL> self . assertEqual ( list ( inst . facets ) , [ ] ) <EOL> def test_ctor_without_discriminator ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> self . assertEqual ( inst . discriminator . __class__ , type ( lambda x : True ) ) <EOL> def test_ctor_with_action_mode ( self ) : <EOL> from substanced . interfaces import MODE_IMMEDIATE <EOL> inst = self . _makeOne ( '<STR_LIT:abc>' , action_mode = MODE_IMMEDIATE ) <EOL> self . assertEqual ( inst . action_mode , MODE_IMMEDIATE ) <EOL> def test_ctor_without_action_mode ( self ) : <EOL> from substanced . interfaces import MODE_ATCOMMIT <EOL> inst = self . _makeOne ( '<STR_LIT:abc>' ) <EOL> self . assertEqual ( inst . action_mode , MODE_ATCOMMIT ) <EOL> class TestTextIndex ( unittest . TestCase ) : <EOL> def _makeOne ( <EOL> self , <EOL> discriminator = None , <EOL> lexicon = None , <EOL> index = None , <EOL> family = None , <EOL> action_mode = None , <EOL> ) : <EOL> from . . indexes import TextIndex <EOL> return TextIndex ( discriminator , family , action_mode = action_mode ) <EOL> def test_ctor_with_discriminator ( self ) : <EOL> inst = self . _makeOne ( '<STR_LIT:abc>' ) <EOL> self . assertEqual ( inst . discriminator , '<STR_LIT:abc>' ) <EOL> def test_ctor_without_discriminator ( self ) : <EOL> inst = self . _makeOne ( ) <EOL> self . assertEqual ( inst . discriminator . __class__ , type ( lambda x : True ) ) <EOL> def test_ctor_with_action_mode ( self ) : <EOL> from substanced . interfaces import MODE_IMMEDIATE <EOL> inst = self . _makeOne ( action_mode = MODE_IMMEDIATE ) <EOL> self . assertEqual ( inst . action_mode , MODE_IMMEDIATE ) <EOL> def test_ctor_without_action_mode ( self ) : <EOL> from substanced . interfaces import MODE_ATCOMMIT <EOL> inst = self . _makeOne ( ) <EOL> self . assertEqual ( inst . action_mode , MODE_ATCOMMIT ) <EOL> class TestAllowedIndex ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . config = testing . setUp ( ) <EOL> def tearDown ( self ) : <EOL> testing . tearDown ( ) <EOL> def _makeOne ( self , discriminator = None , family = None ) : <EOL> from . . indexes import AllowedIndex <EOL> index = AllowedIndex ( discriminator , family = family ) <EOL> return index <EOL> def test_alt_family ( self ) : <EOL> index = self . _makeOne ( None , family = '<STR_LIT:foo>' ) <EOL> self . assertEqual ( index . family , '<STR_LIT:foo>' ) <EOL> def test_document_repr ( self ) : <EOL> index = self . _makeOne ( None ) <EOL> self . assertEqual ( index . document_repr ( None ) , '<STR_LIT>' ) <EOL> def test_allows_request ( self ) : <EOL> index = self . _makeOne ( None ) <EOL> request = testing . DummyRequest ( ) <EOL> q = index . allows ( request , '<STR_LIT>' ) <EOL> self . assertEqual ( q . _value , ( [ '<STR_LIT>' ] , '<STR_LIT>' ) ) <EOL> def test_allows_iterable ( self ) : <EOL> index = self . _makeOne ( None ) <EOL> q = index . allows ( [ '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( q . _value , ( [ '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT>' ) ) <EOL> def test_allows_single ( self ) : <EOL> index = self . _makeOne ( None ) <EOL> q = index . allows ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( q . _value , ( ( '<STR_LIT>' , ) , '<STR_LIT>' ) ) <EOL> class TestAllowsComparator ( unittest . TestCase ) : <EOL> def _makeOne ( self , index , value ) : <EOL> from . . indexes import AllowsComparator <EOL> return AllowsComparator ( index , value ) <EOL> def test_union ( self ) : <EOL> inst = self . _makeOne ( None , None ) <EOL> self . assertRaises ( NotImplementedError , inst . union , None , None ) <EOL> def test__apply ( self ) : <EOL> inst = self . _makeOne ( None , None ) <EOL> self . assertRaises ( NotImplementedError , inst . _apply , None ) <EOL> def test_negate ( self ) : <EOL> inst = self . _makeOne ( None , None ) <EOL> self . assertRaises ( NotImplementedError , inst . negate ) <EOL> def test___str__ ( self ) : <EOL> inst = self . _makeOne ( None , None ) <EOL> self . assertEqual ( inst . __str__ ( ) , '<STR_LIT>' ) <EOL> def test_intersect ( self ) : <EOL> objectmap = DummyObjectmap ( ) <EOL> context = Dummy ( ) <EOL> context . __objectmap__ = objectmap <EOL> inst = self . _makeOne ( context , ( ( '<STR_LIT>' , ) , '<STR_LIT>' ) ) <EOL> result = inst . intersect ( [ <NUM_LIT:1> ] , [ ] ) <EOL> self . assertEqual ( list ( result ) , [ <NUM_LIT:1> ] ) <EOL> class TestIndexPropertySheet ( unittest . TestCase ) : <EOL> def _makeOne ( self , context , request ) : <EOL> from . . indexes import IndexPropertySheet <EOL> return IndexPropertySheet ( context , request ) <EOL> def test_set_action_mode_different ( self ) : <EOL> from substanced . interfaces import ( <EOL> MODE_IMMEDIATE , <EOL> MODE_ATCOMMIT , <EOL> ) <EOL> context = testing . DummyResource ( ) <EOL> context . action_mode = MODE_ATCOMMIT <EOL> inst = self . _makeOne ( context , None ) <EOL> inst . set ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( context . action_mode , MODE_IMMEDIATE ) <EOL> def test_set_action_mode_same ( self ) : <EOL> from substanced . interfaces import MODE_ATCOMMIT <EOL> context = testing . DummyResource ( ) <EOL> context . action_mode = MODE_ATCOMMIT <EOL> inst = self . _makeOne ( context , None ) <EOL> inst . set ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( context . action_mode , MODE_ATCOMMIT ) <EOL> def test_get_action_mode ( self ) : <EOL> from substanced . interfaces import MODE_IMMEDIATE <EOL> context = testing . DummyResource ( ) <EOL> context . action_mode = MODE_IMMEDIATE <EOL> inst = self . _makeOne ( context , None ) <EOL> result = inst . get ( ) <EOL> self . assertEqual ( result [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> class Dummy ( object ) : <EOL> pass <EOL> class DummyCatalog ( object ) : <EOL> family = BTrees . family64 <EOL> def __init__ ( self , objectids = None ) : <EOL> if objectids is None : <EOL> objectids = self . family . II . TreeSet ( ) <EOL> self . objectids = objectids <EOL> class DummyObjectmap ( object ) : <EOL> def object_for ( self , docid ) : return '<STR_LIT:a>' <EOL> def allowed ( self , theset , principals , permission ) : return theset <EOL> class DummyQuery ( object ) : <EOL> def flush ( self , * arg , ** kw ) : <EOL> self . flushed = True <EOL> def _apply ( self , names ) : <EOL> return [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> class DummyDiscriminator ( object ) : <EOL> permissions = ( <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> def __call__ ( self ) : pass <EOL> class DummyActionTM ( object ) : <EOL> def __init__ ( self , index ) : <EOL> self . index = index <EOL> self . actions = [ ] <EOL> def register ( self ) : <EOL> self . registered = True <EOL> def flush ( self , all ) : <EOL> self . flushed = all <EOL> def add ( self , action ) : <EOL> self . actions . append ( action ) </s>
