You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.4 KiB

4 years ago
  1. #!/usr/bin/env python
  2. """
  3. A simple testrunner for nose (or anything else).
  4. Watch for changes in all file types specified in 'EXTENSIONS'.
  5. If changes, run test executable in 'EXECUTABLE', with default
  6. arguments 'DEFAULTARGS'.
  7. The --with-color option needs the "rudolf" nose plugin. See:
  8. http://pypi.python.org/pypi/rudolf/
  9. Originally by Jeff Winkler, http://jeffwinkler.net
  10. Forked from wkral http://github.com/wkral/Nosy
  11. """
  12. import os
  13. import stat
  14. import time
  15. import datetime
  16. import sys
  17. import fnmatch
  18. EXTENSIONS = ['*.py']
  19. EXECUTABLE = 'nosetests test/'
  20. DEFAULTARGS = '--with-color -exe' # -w tests'
  21. def check_sum():
  22. """
  23. Return a long which can be used to know if any .py files have changed.
  24. """
  25. val = 0
  26. for root, dirs, files in os.walk(os.getcwd()):
  27. for extension in EXTENSIONS:
  28. for f in fnmatch.filter(files, extension):
  29. stats = os.stat(os.path.join(root, f))
  30. val += stats[stat.ST_SIZE] + stats[stat.ST_MTIME]
  31. return val
  32. if __name__ == '__main__':
  33. val = 0
  34. try:
  35. while True:
  36. if check_sum() != val:
  37. val = check_sum()
  38. os.system('%s %s %s' % (EXECUTABLE, DEFAULTARGS, ' '.join(sys.argv[1:])))
  39. print(datetime.datetime.now().__str__())
  40. print('=' * 77)
  41. time.sleep(1)
  42. except KeyboardInterrupt:
  43. print('Goodbye')