diff options
author | Matti Picus <matti.picus@gmail.com> | 2018-09-23 09:20:36 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-23 09:20:36 +0300 |
commit | b208593afa98e9281aa86e622ff67b232dba1ae9 (patch) | |
tree | 5d66cd476e3dc16f6ab980d17ad37de687f89491 /numpy | |
parent | 1b26c7e0998348a6bff3096686e836a8c2670549 (diff) | |
parent | 0412b2a59cd94ff58da5631f373526f36c4fef60 (diff) | |
download | numpy-b208593afa98e9281aa86e622ff67b232dba1ae9.tar.gz |
Merge pull request #12020 from eric-wieser/sctype2char-tests
TST: Add tests for np.sctype2char
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/tests/test_numerictypes.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/numpy/core/tests/test_numerictypes.py b/numpy/core/tests/test_numerictypes.py index 8b059de3d..70871774f 100644 --- a/numpy/core/tests/test_numerictypes.py +++ b/numpy/core/tests/test_numerictypes.py @@ -446,6 +446,36 @@ class TestMaximumSctype(object): assert_equal(np.maximum_sctype(t), t) +class Test_sctype2char(object): + # This function is old enough that we're really just documenting the quirks + # at this point. + + def test_scalar_type(self): + assert_equal(np.sctype2char(np.double), 'd') + assert_equal(np.sctype2char(np.int_), 'l') + assert_equal(np.sctype2char(np.unicode_), 'U') + assert_equal(np.sctype2char(np.bytes_), 'S') + + def test_other_type(self): + assert_equal(np.sctype2char(float), 'd') + assert_equal(np.sctype2char(list), 'O') + assert_equal(np.sctype2char(np.ndarray), 'O') + + def test_third_party_scalar_type(self): + from numpy.core._rational_tests import rational + assert_raises(KeyError, np.sctype2char, rational) + assert_raises(KeyError, np.sctype2char, rational(1)) + + def test_array_instance(self): + assert_equal(np.sctype2char(np.array([1.0, 2.0])), 'd') + + def test_abstract_type(self): + assert_raises(KeyError, np.sctype2char, np.floating) + + def test_non_type(self): + assert_raises(ValueError, np.sctype2char, 1) + + @pytest.mark.skipif(sys.flags.optimize > 1, reason="no docstrings present to inspect when PYTHONOPTIMIZE/Py_OptimizeFlag > 1") class TestDocStrings(object): |