| 1 | """App-level tests for support.py""" |
| 2 | import sys |
| 3 | import py |
| 4 | |
| 5 | from pypy.module.micronumpy.test.test_base import BaseNumpyAppTest |
| 6 | from pypy.conftest import option |
| 7 | |
| 8 | class AppTestSupport(BaseNumpyAppTest): |
| 9 | def setup_class(cls): |
| 10 | if option.runappdirect and '__pypy__' not in sys.builtin_module_names: |
| 11 | py.test.skip("pypy only test") |
| 12 | BaseNumpyAppTest.setup_class.im_func(cls) |
| 13 | |
| 14 | def test_add_docstring(self): |
| 15 | import numpy as np |
| 16 | foo = lambda: None |
| 17 | np.add_docstring(foo, "Does a thing") |
| 18 | assert foo.__doc__ == "Does a thing" |
| 19 | |
| 20 | def test_type_docstring(self): |
| 21 | import numpy as np |
| 22 | import types |
| 23 | obj = types.ModuleType |
| 24 | doc = obj.__doc__ |
| 25 | try: |
| 26 | np.set_docstring(obj, 'foo') |
| 27 | assert obj.__doc__ == 'foo' |
| 28 | finally: |
| 29 | np.set_docstring(obj, doc) |
| 30 | |
| 31 | raises(RuntimeError, np.add_docstring, obj, 'foo') |
| 32 | |
| 33 | def test_method_docstring(self): |
| 34 | import numpy as np |
| 35 | doc = int.bit_length.__doc__ |
| 36 | try: |
| 37 | np.set_docstring(np.ndarray.shape, 'foo') |
| 38 | assert np.ndarray.shape.__doc__ == 'foo' |
| 39 | finally: |
| 40 | np.set_docstring(np.ndarray.shape, doc) |
| 41 | |
| 42 | def test_property_docstring(self): |
| 43 | import numpy as np |
| 44 | doc = np.flatiter.base.__doc__ |
| 45 | try: |
| 46 | np.set_docstring(np.flatiter.base, 'foo') |
| 47 | assert np.flatiter.base.__doc__ == 'foo' |
| 48 | finally: |
| 49 | np.set_docstring(np.flatiter.base, doc) |