java..python..eclipse..and whatever else interests me.

Thursday, April 27, 2006

Keeping your Nose Green

Mark of pywinauto fame told me about nose, a unit testing tool with autodiscovery. I was slinging some python over the weekend, and needed coverage as my codebase got bigger.. so I whipped this up. I run this on a DOS window under windows. Basically every time you change any .py file, it runs tests. I call it nosy.

import glob,os,stat,time

def checkSum():
''' Return a long which can be used to know if any .py files have changed.
Only looks in the current directory. '''
val = 0
for f in glob.glob ('*.py'):
stats = os.stat (f)
val += stats [stat.ST_SIZE] + stats [stat.ST_MTIME]
return val

while (True):
if checkSum() != val:
os.system ('nosetests')

I didn't get cute with lambda to squash it into a single line. This is simplistic, but gets the job done. I've sent it to Jason for improvement.

Update: A video of this is here.


Post a Comment

Links to this post:

Create a Link

<< Home