Skip to content

Instantly share code, notes, and snippets.

@audy
Created March 13, 2012 16:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save audy/2029866 to your computer and use it in GitHub Desktop.
Save audy/2029866 to your computer and use it in GitHub Desktop.
A testing framework?
#!/usr/bin/env python
from __future__ import with_statement
class It:
def __init__(self, s):
''' make a new test '''
self.s = s
self.status = None
def __enter__(self, *stuff):
''' return self for use in with statement '''
return self
def __exit__(self, type, value, traceback):
''' print test status '''
if self.status:
print 'PASS:',
else:
print 'FAIL:',
print self.s
def should_be_equal(self, a, b):
self.status = (a == b)
def should_not_be_equal(self, a, b):
self.status = (a != b)
with It('passes') as test:
test.should_be_equal(1, 1)
with It('also passes') as test:
test.should_not_be_equal(0, 1)
with It('does not pass') as test:
test.should_be_equal(0, 1)
with It('also does not pass') as test:
test.should_not_be_equal(0, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment