f2py_testing.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import sys
  2. import re
  3. from numpy.testing import jiffies, memusage
  4. def cmdline():
  5. m = re.compile(r'\A\d+\Z')
  6. args = []
  7. repeat = 1
  8. for a in sys.argv[1:]:
  9. if m.match(a):
  10. repeat = eval(a)
  11. else:
  12. args.append(a)
  13. f2py_opts = ' '.join(args)
  14. return repeat, f2py_opts
  15. def run(runtest, test_functions, repeat=1):
  16. l = [(t, repr(t.__doc__.split('\n')[1].strip())) for t in test_functions]
  17. start_memusage = memusage()
  18. diff_memusage = None
  19. start_jiffies = jiffies()
  20. i = 0
  21. while i < repeat:
  22. i += 1
  23. for t, fname in l:
  24. runtest(t)
  25. if start_memusage is None:
  26. continue
  27. if diff_memusage is None:
  28. diff_memusage = memusage() - start_memusage
  29. else:
  30. diff_memusage2 = memusage() - start_memusage
  31. if diff_memusage2 != diff_memusage:
  32. print('memory usage change at step %i:' % i,
  33. diff_memusage2 - diff_memusage,
  34. fname)
  35. diff_memusage = diff_memusage2
  36. current_memusage = memusage()
  37. print('run', repeat * len(test_functions), 'tests',
  38. 'in %.2f seconds' % ((jiffies() - start_jiffies) / 100.0))
  39. if start_memusage:
  40. print('initial virtual memory size:', start_memusage, 'bytes')
  41. print('current virtual memory size:', current_memusage, 'bytes')