How to use _check_index method in hypothesis

Best Python code snippet using hypothesis

test_localrolesindex.py

Source:test_localrolesindex.py Github

copy

Full Screen

...42 }43 })44 self.assertEqual(used, (self._index.id,))45 return list(result)46 def _check_index(self, local_roles, expected, operator='or'):47 actual = set(self._query_index(local_roles, operator=operator))48 self.assertEqual(actual, set(expected))49 def _effect_change(self, document_id, obj):50 self._values[document_id] = obj51 self._index.index_object(52 document_id,53 obj54 )55 def test_interfaces(self):56 from Products.PluginIndexes.interfaces import IPluggableIndex57 from Products.PluginIndexes.interfaces import ISortIndex58 from Products.PluginIndexes.interfaces import IUniqueValueIndex59 from zope.interface.verify import verifyClass60 LocalRolesIndex = self._get_target_class()61 verifyClass(IPluggableIndex, LocalRolesIndex)62 verifyClass(ISortIndex, LocalRolesIndex)63 verifyClass(IUniqueValueIndex, LocalRolesIndex)64 def test_index_populated(self):65 self._populate_index()66 values = self._values67 self.assertEqual(len(self._index.referencedObjects()), len(values))68 def test_index_clear(self):69 self._populate_index()70 values = self._values71 self.assertEqual(len(self._index.referencedObjects()), len(values))72 self._index.clear()73 self.assertEqual(len(self._index.referencedObjects()), 0)74 self.assertEqual(list(self._index.shadowtree.descendants()), [])75 def test_index_object_noop(self):76 self._populate_index()77 try:78 self._index.index_object(999, None)79 except Exception:80 self.fail('Should not raise (see KeywordIndex tests)')81 def test_index_empty(self):82 self.assertEqual(len(self._index), 0)83 assert len(self._index.referencedObjects()) == 084 self.assertEqual(self._index.numObjects(), 0)85 self.assertIsNone(self._index.getEntryForObject(1234))86 self.assertEqual(self._index.getEntryForObject(1234, self._marker),87 self._marker)88 self._index.unindex_object(1234)89 assert self._index.hasUniqueValuesFor('allowedRolesAndUsers')90 assert not self._index.hasUniqueValuesFor('notAnIndex')91 assert len(self._index.uniqueValues('allowedRolesAndUsers')) == 092 def test_index_object(self):93 self._populate_index()94 self._check_index(['Anonymous'], (0, 1, 2, 3, 4, 5))95 self._check_index(['Authenticated'], (2, 3, 4, 5, 6))96 self._check_index(['Member'], ())97 def test__index_object_on_change_no_recurse(self):98 self._populate_index()99 result = self._query_index(['Anonymous', 'Authenticated'],100 operator='and')101 self.assertEqual(list(result), [2, 3, 4, 5])102 self._effect_change(103 4,104 Dummy('/a/b/c/d', ['Anonymous', 'Authenticated', 'Editor'])105 )106 self._check_index(['Anonymous', 'Authenticated'],107 [2, 3, 4, 5],108 operator='and')109 self._check_index(['Editor'], [4], operator='and')110 self._effect_change(111 2,112 Dummy('/a/b/c', ['Contributor'])113 )114 self._check_index(['Contributor'], {2})115 self._check_index(['Anonymous', 'Authenticated'], {3, 4, 5},116 operator='and')117 def test__index_object_on_change_recurse(self):118 self._populate_index()119 self._values[2].aru = ['Contributor']120 dummy = self._values[2]121 zope.interface.alsoProvides(dummy, IDecendantLocalRolesAware)122 self._effect_change(2, dummy)123 self._check_index(['Contributor'], {2, 3, 4})124 self._check_index(['Anonymous', 'Authenticated'], {0, 1, 5, 6})125 def test_reindex_no_change(self):126 self._populate_index()127 obj = self._values[7]128 self._effect_change(7, obj)129 self._check_index(['Reviewer'], {7})130 self._effect_change(7, obj)131 self._check_index(['Reviewer'], {7})132 def test_index_object_when_raising_attributeerror(self):133 class FauxObject(Dummy):134 def allowedRolesAndUsers(self):135 raise AttributeError136 to_index = FauxObject('/a/b', ['Role'])137 self._index.index_object(10, to_index)138 self.assertFalse(self._index._unindex.get(10))139 self.assertFalse(self._index.getEntryForObject(10))140 def test_index_object_when_raising_typeeror(self):141 class FauxObject(Dummy):142 def allowedRolesAndUsers(self, name):143 return 'allowedRolesAndUsers'144 to_index = FauxObject('/a/b', ['Role'])145 self._index.index_object(10, to_index)...

Full Screen

Full Screen

reindexed_list.py

Source:reindexed_list.py Github

copy

Full Screen

...4 def __init__(self, shift=1, *vargs, **kwargs):5 super(ReindexedList, self).__init__(*vargs, **kwargs)6 self._shift = shift7 def __getitem__(self, i):8 self._check_index(i)9 return super(ReindexedList, self).__getitem__(i - self._shift)10 def __getslice__(self, i, j):11 self._check_index(i)12 self._check_index(j)13 return ReindexedList(self._shift, \14 super(ReindexedList, self).__getslice__( \15 i - self._shift, j - self._shift))16 def __setitem__(self, i, y):17 self._check_index(i)18 return super(ReindexedList, self).__setitem__(i - self._shift, y)19 def __setslice__(self, i, j, y):20 self._check_index(i)21 self._check_index(j)22 return super(ReindexedList, self).__setslice__(i - self._shift, j - self._shift, y)23 def __delitem__(self, i):24 self._check_index(i)25 return super(ReindexedList, self).__delitem__(i - self._shift)26 def __delslice__(self, i, j):27 self._check_index(i)28 self._check_index(j)29 return super(ReindexedList, self).__delslice__(i - self._shift, \30 j - self._shift)31 def __repr__(self):32 return 'ReindexedList(%s, %r)' % \33 (self._shift, super(ReindexedList, self))34 def index(self, o):35 return super(ReindexedList, self).index(o) + self._shift36 def _check_index(self, i):37 if i < self._shift:38 raise IndexError('got index %d for list with starting index %d' % (i, self._shift))39def Seq(x):40 '''Turn a 0-indexed list into a 1-indexed one.'''...

Full Screen

Full Screen

array.py

Source:array.py Github

copy

Full Screen

...12 self._array = [13 [value for i in range(self._width)]14 for j in range(self._height)15 ]16 def _check_index(self, x, y):17 if (18 x < 1 or19 x > self._width or20 y < 1 or21 y > self._height22 ):23 raise ArrayError('Index is not within array dimensions {w}x{h}'.format(24 x=x, y=y, w=self._width, h=self._height25 ))26 def _zero_index(cls, x, y):27 return x - 1, y - 128 def __getitem__(self, i):29 self._check_index(*i)30 x, y = self._zero_index(*i)31 return self._array[y][x]32 def __setitem__(self, i, value):33 self._check_index(*i)34 x, y = self._zero_index(*i)35 self._array[y][x] = value36 def __eq__(self, other):37 return self._array == other._array38 @property39 def copy(self):40 new = copy(self)41 new._array = [copy(row) for row in self._array]...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run hypothesis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful