mirror of
https://github.com/python/cpython.git
synced 2025-10-16 19:57:59 +00:00
gh-125420: implement Sequence.index
API on memoryview
objects (#125446)
This commit is contained in:
parent
3b18af964d
commit
58c753827a
5 changed files with 171 additions and 1 deletions
|
@ -15,6 +15,7 @@ import copy
|
|||
import pickle
|
||||
import struct
|
||||
|
||||
from itertools import product
|
||||
from test.support import import_helper
|
||||
|
||||
|
||||
|
@ -58,6 +59,31 @@ class AbstractMemoryTests:
|
|||
for tp in self._types:
|
||||
self.check_getitem_with_type(tp)
|
||||
|
||||
def test_index(self):
|
||||
for tp in self._types:
|
||||
b = tp(self._source)
|
||||
m = self._view(b) # may be a sub-view
|
||||
l = m.tolist()
|
||||
k = 2 * len(self._source)
|
||||
|
||||
for chi in self._source:
|
||||
if chi in l:
|
||||
self.assertEqual(m.index(chi), l.index(chi))
|
||||
else:
|
||||
self.assertRaises(ValueError, m.index, chi)
|
||||
|
||||
for start, stop in product(range(-k, k), range(-k, k)):
|
||||
index = -1
|
||||
try:
|
||||
index = l.index(chi, start, stop)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
if index == -1:
|
||||
self.assertRaises(ValueError, m.index, chi, start, stop)
|
||||
else:
|
||||
self.assertEqual(m.index(chi, start, stop), index)
|
||||
|
||||
def test_iter(self):
|
||||
for tp in self._types:
|
||||
b = tp(self._source)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue