test_doctesting.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """ Doctests for NumPy-specific nose/doctest modifications
  2. """
  3. from __future__ import division, absolute_import, print_function
  4. #FIXME: None of these tests is run, because 'check' is not a recognized
  5. # testing prefix.
  6. # try the #random directive on the output line
  7. def check_random_directive():
  8. '''
  9. >>> 2+2
  10. <BadExample object at 0x084D05AC> #random: may vary on your system
  11. '''
  12. # check the implicit "import numpy as np"
  13. def check_implicit_np():
  14. '''
  15. >>> np.array([1,2,3])
  16. array([1, 2, 3])
  17. '''
  18. # there's some extraneous whitespace around the correct responses
  19. def check_whitespace_enabled():
  20. '''
  21. # whitespace after the 3
  22. >>> 1+2
  23. 3
  24. # whitespace before the 7
  25. >>> 3+4
  26. 7
  27. '''
  28. def check_empty_output():
  29. """ Check that no output does not cause an error.
  30. This is related to nose bug 445; the numpy plugin changed the
  31. doctest-result-variable default and therefore hit this bug:
  32. http://code.google.com/p/python-nose/issues/detail?id=445
  33. >>> a = 10
  34. """
  35. def check_skip():
  36. """ Check skip directive
  37. The test below should not run
  38. >>> 1/0 #doctest: +SKIP
  39. """
  40. if __name__ == '__main__':
  41. # Run tests outside numpy test rig
  42. import nose
  43. from numpy.testing.noseclasses import NumpyDoctest
  44. argv = ['', __file__, '--with-numpydoctest']
  45. nose.core.TestProgram(argv=argv, addplugins=[NumpyDoctest()])