SILENT KILLERPanel

Current Path: > > opt > cloudlinux > venv > lib > python3.11 > site-packages > > numpy > core > tests


Operation   : Linux premium131.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
Software     : Apache
Server IP    : 162.0.232.56 | Your IP: 216.73.216.111
Domains      : 1034 Domain(s)
Permission   : [ 0755 ]

Files and Folders in: //opt/cloudlinux/venv/lib/python3.11/site-packages//numpy/core/tests

NameTypeSizeLast ModifiedActions
__pycache__ Directory - -
data Directory - -
examples Directory - -
__init__.py File 0 bytes April 17 2025 13:10:58.
_locales.py File 2206 bytes April 17 2025 13:10:58.
test__exceptions.py File 2846 bytes April 17 2025 13:10:58.
test_abc.py File 2220 bytes April 17 2025 13:10:58.
test_api.py File 22995 bytes April 17 2025 13:10:58.
test_argparse.py File 1969 bytes April 17 2025 13:10:58.
test_array_coercion.py File 34379 bytes April 17 2025 13:10:58.
test_array_interface.py File 7596 bytes April 17 2025 13:10:58.
test_arraymethod.py File 3244 bytes April 17 2025 13:10:58.
test_arrayprint.py File 40462 bytes April 17 2025 13:10:58.
test_casting_floatingpoint_errors.py File 5063 bytes April 17 2025 13:10:58.
test_casting_unittests.py File 34298 bytes April 17 2025 13:10:58.
test_conversion_utils.py File 6559 bytes April 17 2025 13:10:58.
test_cpu_dispatcher.py File 1521 bytes April 17 2025 13:10:58.
test_cpu_features.py File 14858 bytes April 17 2025 13:10:58.
test_custom_dtypes.py File 9401 bytes April 17 2025 13:10:58.
test_cython.py File 3623 bytes April 17 2025 13:10:58.
test_datetime.py File 116211 bytes April 17 2025 13:10:58.
test_defchararray.py File 24997 bytes April 17 2025 13:10:58.
test_deprecations.py File 31076 bytes April 17 2025 13:10:58.
test_dlpack.py File 3522 bytes April 17 2025 13:10:58.
test_dtype.py File 75288 bytes April 17 2025 13:10:58.
test_einsum.py File 52960 bytes April 17 2025 13:10:58.
test_errstate.py File 2219 bytes April 17 2025 13:10:58.
test_extint128.py File 5643 bytes April 17 2025 13:10:58.
test_function_base.py File 15595 bytes April 17 2025 13:10:58.
test_getlimits.py File 6718 bytes April 17 2025 13:10:58.
test_half.py File 24226 bytes April 17 2025 13:10:58.
test_hashtable.py File 1011 bytes April 17 2025 13:10:58.
test_indexerrors.py File 5130 bytes April 17 2025 13:10:58.
test_indexing.py File 54314 bytes April 17 2025 13:10:58.
test_item_selection.py File 6458 bytes April 17 2025 13:10:58.
test_limited_api.py File 1172 bytes April 17 2025 13:10:58.
test_longdouble.py File 13905 bytes April 17 2025 13:10:58.
test_machar.py File 1067 bytes April 17 2025 13:10:58.
test_mem_overlap.py File 29086 bytes April 17 2025 13:10:58.
test_mem_policy.py File 16004 bytes April 17 2025 13:10:58.
test_memmap.py File 7477 bytes April 17 2025 13:10:58.
test_multiarray.py File 379320 bytes April 17 2025 13:10:58.
test_nditer.py File 130818 bytes April 17 2025 13:10:58.
test_nep50_promotions.py File 8840 bytes April 17 2025 13:10:58.
test_numeric.py File 136543 bytes April 17 2025 13:10:58.
test_numerictypes.py File 21687 bytes April 17 2025 13:10:58.
test_overrides.py File 26080 bytes April 17 2025 13:10:58.
test_print.py File 6837 bytes April 17 2025 13:10:58.
test_protocols.py File 1168 bytes April 17 2025 13:10:58.
test_records.py File 20269 bytes April 17 2025 13:10:58.
test_regression.py File 91447 bytes April 17 2025 13:10:58.
test_scalar_ctors.py File 6115 bytes April 17 2025 13:10:58.
test_scalar_methods.py File 7541 bytes April 17 2025 13:10:58.
test_scalarbuffer.py File 5580 bytes April 17 2025 13:10:58.
test_scalarinherit.py File 2368 bytes April 17 2025 13:10:58.
test_scalarmath.py File 42885 bytes April 17 2025 13:10:58.
test_scalarprint.py File 18771 bytes April 17 2025 13:10:58.
test_shape_base.py File 29723 bytes April 17 2025 13:10:58.
test_simd.py File 48696 bytes April 17 2025 13:10:58.
test_simd_module.py File 3805 bytes April 17 2025 13:10:58.
test_strings.py File 3835 bytes April 17 2025 13:10:58.
test_ufunc.py File 124145 bytes April 17 2025 13:10:58.
test_umath.py File 185129 bytes April 17 2025 13:10:58.
test_umath_accuracy.py File 3897 bytes April 17 2025 13:10:58.
test_umath_complex.py File 23243 bytes April 17 2025 13:10:58.
test_unicode.py File 12775 bytes April 17 2025 13:10:58.

Reading File: //opt/cloudlinux/venv/lib/python3.11/site-packages//numpy/core/tests/test_scalarbuffer.py

"""
Test scalar buffer interface adheres to PEP 3118
"""
import numpy as np
from numpy.core._rational_tests import rational
from numpy.core._multiarray_tests import get_buffer_info
import pytest

from numpy.testing import assert_, assert_equal, assert_raises

# PEP3118 format strings for native (standard alignment and byteorder) types
scalars_and_codes = [
    (np.bool_, '?'),
    (np.byte, 'b'),
    (np.short, 'h'),
    (np.intc, 'i'),
    (np.int_, 'l'),
    (np.longlong, 'q'),
    (np.ubyte, 'B'),
    (np.ushort, 'H'),
    (np.uintc, 'I'),
    (np.uint, 'L'),
    (np.ulonglong, 'Q'),
    (np.half, 'e'),
    (np.single, 'f'),
    (np.double, 'd'),
    (np.longdouble, 'g'),
    (np.csingle, 'Zf'),
    (np.cdouble, 'Zd'),
    (np.clongdouble, 'Zg'),
]
scalars_only, codes_only = zip(*scalars_and_codes)


class TestScalarPEP3118:

    @pytest.mark.parametrize('scalar', scalars_only, ids=codes_only)
    def test_scalar_match_array(self, scalar):
        x = scalar()
        a = np.array([], dtype=np.dtype(scalar))
        mv_x = memoryview(x)
        mv_a = memoryview(a)
        assert_equal(mv_x.format, mv_a.format)

    @pytest.mark.parametrize('scalar', scalars_only, ids=codes_only)
    def test_scalar_dim(self, scalar):
        x = scalar()
        mv_x = memoryview(x)
        assert_equal(mv_x.itemsize, np.dtype(scalar).itemsize)
        assert_equal(mv_x.ndim, 0)
        assert_equal(mv_x.shape, ())
        assert_equal(mv_x.strides, ())
        assert_equal(mv_x.suboffsets, ())

    @pytest.mark.parametrize('scalar, code', scalars_and_codes, ids=codes_only)
    def test_scalar_code_and_properties(self, scalar, code):
        x = scalar()
        expected = dict(strides=(), itemsize=x.dtype.itemsize, ndim=0,
                        shape=(), format=code, readonly=True)

        mv_x = memoryview(x)
        assert self._as_dict(mv_x) == expected

    @pytest.mark.parametrize('scalar', scalars_only, ids=codes_only)
    def test_scalar_buffers_readonly(self, scalar):
        x = scalar()
        with pytest.raises(BufferError, match="scalar buffer is readonly"):
            get_buffer_info(x, ["WRITABLE"])

    def test_void_scalar_structured_data(self):
        dt = np.dtype([('name', np.str_, 16), ('grades', np.float64, (2,))])
        x = np.array(('ndarray_scalar', (1.2, 3.0)), dtype=dt)[()]
        assert_(isinstance(x, np.void))
        mv_x = memoryview(x)
        expected_size = 16 * np.dtype((np.str_, 1)).itemsize
        expected_size += 2 * np.dtype(np.float64).itemsize
        assert_equal(mv_x.itemsize, expected_size)
        assert_equal(mv_x.ndim, 0)
        assert_equal(mv_x.shape, ())
        assert_equal(mv_x.strides, ())
        assert_equal(mv_x.suboffsets, ())

        # check scalar format string against ndarray format string
        a = np.array([('Sarah', (8.0, 7.0)), ('John', (6.0, 7.0))], dtype=dt)
        assert_(isinstance(a, np.ndarray))
        mv_a = memoryview(a)
        assert_equal(mv_x.itemsize, mv_a.itemsize)
        assert_equal(mv_x.format, mv_a.format)

        # Check that we do not allow writeable buffer export (technically
        # we could allow it sometimes here...)
        with pytest.raises(BufferError, match="scalar buffer is readonly"):
            get_buffer_info(x, ["WRITABLE"])

    def _as_dict(self, m):
        return dict(strides=m.strides, shape=m.shape, itemsize=m.itemsize,
                    ndim=m.ndim, format=m.format, readonly=m.readonly)

    def test_datetime_memoryview(self):
        # gh-11656
        # Values verified with v1.13.3, shape is not () as in test_scalar_dim

        dt1 = np.datetime64('2016-01-01')
        dt2 = np.datetime64('2017-01-01')
        expected = dict(strides=(1,), itemsize=1, ndim=1, shape=(8,),
                        format='B', readonly=True)
        v = memoryview(dt1)
        assert self._as_dict(v) == expected

        v = memoryview(dt2 - dt1)
        assert self._as_dict(v) == expected

        dt = np.dtype([('a', 'uint16'), ('b', 'M8[s]')])
        a = np.empty(1, dt)
        # Fails to create a PEP 3118 valid buffer
        assert_raises((ValueError, BufferError), memoryview, a[0])

        # Check that we do not allow writeable buffer export
        with pytest.raises(BufferError, match="scalar buffer is readonly"):
            get_buffer_info(dt1, ["WRITABLE"])

    @pytest.mark.parametrize('s', [
        pytest.param("\x32\x32", id="ascii"),
        pytest.param("\uFE0F\uFE0F", id="basic multilingual"),
        pytest.param("\U0001f4bb\U0001f4bb", id="non-BMP"),
    ])
    def test_str_ucs4(self, s):
        s = np.str_(s)  # only our subclass implements the buffer protocol

        # all the same, characters always encode as ucs4
        expected = dict(strides=(), itemsize=8, ndim=0, shape=(), format='2w',
                        readonly=True)

        v = memoryview(s)
        assert self._as_dict(v) == expected

        # integers of the paltform-appropriate endianness
        code_points = np.frombuffer(v, dtype='i4')

        assert_equal(code_points, [ord(c) for c in s])

        # Check that we do not allow writeable buffer export
        with pytest.raises(BufferError, match="scalar buffer is readonly"):
            get_buffer_info(s, ["WRITABLE"])

    def test_user_scalar_fails_buffer(self):
        r = rational(1)
        with assert_raises(TypeError):
            memoryview(r)

        # Check that we do not allow writeable buffer export
        with pytest.raises(BufferError, match="scalar buffer is readonly"):
            get_buffer_info(r, ["WRITABLE"])

SILENT KILLER Tool