Skip to content

Instantly share code, notes, and snippets.

Forked from k0emt/
Created September 2, 2011 23:20
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save justinvoss/1190189 to your computer and use it in GitHub Desktop.
Overloading constructor example
class Greeter:
def __init__(self, greeting=None):
self.myGreeting = greeting or 'Hello World!'
def greeting(self):
return self.myGreeting
import unittest
from spike import Greeter
class GreeterTest(unittest.TestCase):
def test_greetingReturnsDefault(self):
mw = Greeter()
self.assertEqual(mw.greeting(),'Hello World!','greeting is not as expected')
def test_greetingReturnsConstructorProvidedContent(self):
mw = Greeter('booyah!')
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment