MCPcopy Index your code
hub / github.com/python/cpython / test_ndarray_slice_assign_single

Method test_ndarray_slice_assign_single

Lib/test/test_buffer.py:1812–1864  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1810 self.assertEqual(ndsliced.tolist(), sliced)
1811
1812 def test_ndarray_slice_assign_single(self):
1813 for fmt, items, _ in iter_format(5):
1814 for lslice in genslices(5):
1815 for rslice in genslices(5):
1816 for flags in (0, ND_PIL):
1817
1818 f = flags|ND_WRITABLE
1819 nd = ndarray(items, shape=[5], format=fmt, flags=f)
1820 ex = ndarray(items, shape=[5], format=fmt, flags=f)
1821 mv = memoryview(ex)
1822
1823 lsterr = None
1824 diff_structure = None
1825 lst = items[:]
1826 try:
1827 lval = lst[lslice]
1828 rval = lst[rslice]
1829 lst[lslice] = lst[rslice]
1830 diff_structure = len(lval) != len(rval)
1831 except Exception as e:
1832 lsterr = e.__class__
1833
1834 nderr = None
1835 try:
1836 nd[lslice] = nd[rslice]
1837 except Exception as e:
1838 nderr = e.__class__
1839
1840 if diff_structure: # ndarray cannot change shape
1841 self.assertIs(nderr, ValueError)
1842 else:
1843 self.assertEqual(nd.tolist(), lst)
1844 self.assertIs(nderr, lsterr)
1845
1846 if not is_memoryview_format(fmt):
1847 continue
1848
1849 mverr = None
1850 try:
1851 mv[lslice] = mv[rslice]
1852 except Exception as e:
1853 mverr = e.__class__
1854
1855 if diff_structure: # memoryview cannot change shape
1856 self.assertIs(mverr, ValueError)
1857 else:
1858 self.assertEqual(mv.tolist(), lst)
1859 self.assertEqual(mv, nd)
1860 self.assertIs(mverr, lsterr)
1861 self.verify(mv, obj=ex,
1862 itemsize=nd.itemsize, fmt=fmt, readonly=False,
1863 ndim=nd.ndim, shape=nd.shape, strides=nd.strides,
1864 lst=nd.tolist())
1865
1866 def test_ndarray_slice_assign_multidim(self):
1867 shape_t = (2, 3, 5)

Callers

nothing calls this directly

Calls 6

verifyMethod · 0.95
iter_formatFunction · 0.85
genslicesFunction · 0.85
is_memoryview_formatFunction · 0.85
assertIsMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected