PATH:
opt
/
cloudlinux
/
venv
/
lib
/
python3.11
/
site-packages
/
numpy
/
core
/
tests
""" Test printing of scalar types. """ import pytest import numpy as np from numpy.testing import assert_, assert_raises class A: pass class B(A, np.float64): pass class C(B): pass class D(C, B): pass class B0(np.float64, A): pass class C0(B0): pass class HasNew: def __new__(cls, *args, **kwargs): return cls, args, kwargs class B1(np.float64, HasNew): pass class TestInherit: def test_init(self): x = B(1.0) assert_(str(x) == '1.0') y = C(2.0) assert_(str(y) == '2.0') z = D(3.0) assert_(str(z) == '3.0') def test_init2(self): x = B0(1.0) assert_(str(x) == '1.0') y = C0(2.0) assert_(str(y) == '2.0') def test_gh_15395(self): # HasNew is the second base, so `np.float64` should have priority x = B1(1.0) assert_(str(x) == '1.0') # previously caused RecursionError!? with pytest.raises(TypeError): B1(1.0, 2.0) class TestCharacter: def test_char_radd(self): # GH issue 9620, reached gentype_add and raise TypeError np_s = np.bytes_('abc') np_u = np.str_('abc') s = b'def' u = 'def' assert_(np_s.__radd__(np_s) is NotImplemented) assert_(np_s.__radd__(np_u) is NotImplemented) assert_(np_s.__radd__(s) is NotImplemented) assert_(np_s.__radd__(u) is NotImplemented) assert_(np_u.__radd__(np_s) is NotImplemented) assert_(np_u.__radd__(np_u) is NotImplemented) assert_(np_u.__radd__(s) is NotImplemented) assert_(np_u.__radd__(u) is NotImplemented) assert_(s + np_s == b'defabc') assert_(u + np_u == 'defabc') class MyStr(str, np.generic): # would segfault pass with assert_raises(TypeError): # Previously worked, but gave completely wrong result ret = s + MyStr('abc') class MyBytes(bytes, np.generic): # would segfault pass ret = s + MyBytes(b'abc') assert(type(ret) is type(s)) assert ret == b"defabc" def test_char_repeat(self): np_s = np.bytes_('abc') np_u = np.str_('abc') res_s = b'abc' * 5 res_u = 'abc' * 5 assert_(np_s * 5 == res_s) assert_(np_u * 5 == res_u)
[-] test_custom_dtypes.py
[open]
[-] test_array_interface.py
[open]
[-] test_mem_policy.py
[open]
[-] test_dlpack.py
[open]
[-] test_argparse.py
[open]
[-] test_getlimits.py
[open]
[+]
..
[-] test_machar.py
[open]
[-] _locales.py
[open]
[-] test_arraymethod.py
[open]
[-] test_scalarinherit.py
[open]
[-] test_shape_base.py
[open]
[-] test_scalar_ctors.py
[open]
[-] test_half.py
[open]
[-] test_conversion_utils.py
[open]
[+]
__pycache__
[+]
examples
[-] test_numerictypes.py
[open]
[-] test_datetime.py
[open]
[-] test_einsum.py
[open]
[-] test_abc.py
[open]
[-] test_print.py
[open]
[-] test_nep50_promotions.py
[open]
[-] test_indexerrors.py
[open]
[-] test_errstate.py
[open]
[-] test_simd_module.py
[open]
[-] test_umath_complex.py
[open]
[-] test_mem_overlap.py
[open]
[-] test_overrides.py
[open]
[-] test_records.py
[open]
[-] test_umath_accuracy.py
[open]
[-] test_cpu_dispatcher.py
[open]
[-] test_scalarbuffer.py
[open]
[-] test_numeric.py
[open]
[-] test_dtype.py
[open]
[-] test_multiarray.py
[open]
[-] test_extint128.py
[open]
[-] test__exceptions.py
[open]
[-] test_deprecations.py
[open]
[-] test_hashtable.py
[open]
[-] test_ufunc.py
[open]
[-] test_protocols.py
[open]
[-] test_regression.py
[open]
[-] test_casting_floatingpoint_errors.py
[open]
[-] test_item_selection.py
[open]
[-] test_indexing.py
[open]
[-] test_nditer.py
[open]
[-] test_scalar_methods.py
[open]
[+]
data
[-] test_simd.py
[open]
[-] test_arrayprint.py
[open]
[-] test_strings.py
[open]
[-] test_unicode.py
[open]
[-] test_cpu_features.py
[open]
[-] test_casting_unittests.py
[open]
[-] test_cython.py
[open]
[-] test_memmap.py
[open]
[-] __init__.py
[open]
[-] test_defchararray.py
[open]
[-] test_longdouble.py
[open]
[-] test_array_coercion.py
[open]
[-] test_function_base.py
[open]
[-] test_scalarmath.py
[open]
[-] test_api.py
[open]
[-] test_limited_api.py
[open]
[-] test_scalarprint.py
[open]
[-] test_umath.py
[open]