diff options
author | Matti Picus <matti.picus@gmail.com> | 2020-05-20 18:14:08 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-20 18:14:08 +0300 |
commit | 78d7ab3d0c35cb8aa0cdf449e0db1472e6ad60dc (patch) | |
tree | b42ceb6a82d8035d5cd5a299a04a6726db1974d5 /numpy/lib/tests/test_function_base.py | |
parent | dcf1614dfc11f9004e408ed8c833980c951c541e (diff) | |
parent | ffdce8b4ddf725d9f4329a745d6bfad9b5716774 (diff) | |
download | numpy-78d7ab3d0c35cb8aa0cdf449e0db1472e6ad60dc.tar.gz |
Merge pull request #16239 from seberg/reimport-do-not-set-docs
BUG,DOC: Allow attach docs twice but error if wrong
Diffstat (limited to 'numpy/lib/tests/test_function_base.py')
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index b4e928273..008ea0759 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -3350,12 +3350,50 @@ class TestAdd_newdoc: @pytest.mark.skipif(sys.flags.optimize == 2, reason="Python running -OO") @pytest.mark.xfail(IS_PYPY, reason="PyPy does not modify tp_doc") def test_add_doc(self): - # test np.add_newdoc + # test that np.add_newdoc did attach a docstring successfully: tgt = "Current flat index into the array." assert_equal(np.core.flatiter.index.__doc__[:len(tgt)], tgt) assert_(len(np.core.ufunc.identity.__doc__) > 300) assert_(len(np.lib.index_tricks.mgrid.__doc__) > 300) + @pytest.mark.skipif(sys.flags.optimize == 2, reason="Python running -OO") + def test_errors_are_ignored(self): + prev_doc = np.core.flatiter.index.__doc__ + # nothing changed, but error ignored, this should probably + # give a warning (or even error) in the future. + np.add_newdoc("numpy.core", "flatiter", ("index", "bad docstring")) + assert prev_doc == np.core.flatiter.index.__doc__ + + +class TestAddDocstring(): + # Test should possibly be moved, but it also fits to be close to + # the newdoc tests... + @pytest.mark.skipif(sys.flags.optimize == 2, reason="Python running -OO") + @pytest.mark.skipif(IS_PYPY, reason="PyPy does not modify tp_doc") + def test_add_same_docstring(self): + # test for attributes (which are C-level defined) + np.add_docstring(np.ndarray.flat, np.ndarray.flat.__doc__) + # And typical functions: + def func(): + """docstring""" + return + + np.add_docstring(func, func.__doc__) + + @pytest.mark.skipif(sys.flags.optimize == 2, reason="Python running -OO") + def test_different_docstring_fails(self): + # test for attributes (which are C-level defined) + with assert_raises(RuntimeError): + np.add_docstring(np.ndarray.flat, "different docstring") + # And typical functions: + def func(): + """docstring""" + return + + with assert_raises(RuntimeError): + np.add_docstring(func, "different docstring") + + class TestSortComplex: @pytest.mark.parametrize("type_in, type_out", [ |