test_doctesting.py 1.3 KB

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