annotate tests/example.py @ 8:109627b7db9f

add ability to have mandatory class arguments
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 30 Mar 2012 10:37:39 -0700
parents 005e073dc590
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 #!/usr/bin/env python
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 from commandparser import CommandParser
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6 class Example(object):
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7 """
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8 a random example
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 """
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 def __init__(self, foo=1, bar='fleem'):
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12 """
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 - foo: a number
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14 - bar: a string
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 """
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16 self.foo = foo
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17 self.bar = bar
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19 def execute(self, number):
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20 """
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21 do some stupid math
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
22 - number: a number to multiply by foo
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23 """
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
24 return self.foo * int(number)
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
25
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
26 if __name__ == '__main__':
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
27 import sys
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
28 parser = CommandParser(Example)
005e073dc590 basic POC
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
29 parser.invoke(sys.argv[1:])