Skip to content

Instantly share code, notes, and snippets.

@benhosmer
Created November 7, 2012 15:26
Show Gist options
  • Save benhosmer/4032227 to your computer and use it in GitHub Desktop.
Save benhosmer/4032227 to your computer and use it in GitHub Desktop.
Python Unit Test Notes
import unittest
# Here's our "unit".
def IsOdd(n):
return n % 2 == 1
def IsaString(text):
#text = "Hello"
text = ['apples', 'bananas']
return type(text)
# Here's our "unit tests".
class IsOddTests(unittest.TestCase):
def testOne(self):
self.failUnless(IsOdd(1))
def testTwo(self):
self.failIf(IsOdd(2))
'''
class IsaStringTests(unittest.TestCase):
def testOne(self):
self.failUnless(IsaString(str))
def testTwo(self):
self.failIf(IsaString(list))
'''
class IsaStringTests(unittest.TestCase):
def testOne(self):
self.failUnless(not IsaString(str))
def main():
unittest.main()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment