define PLC_MAIL_FROM_ADDRESS
[tests.git] / federation / TestCases.py
1 #!/usr/bin/env python
2 import sys
3
4 class TestCases:
5
6     def __init__ (self):
7         pass
8
9     def initialize (self):
10         print "Performing : initialize"
11         print "current options",self.options
12         print "e.g. verbose=",self.options.verbose
13
14     def cleanup (self):
15         print "Cleaning up"
16
17     def testcase_1 (self):
18         print "\tRunning testcase 1"
19
20     def testcase_2 (self):
21         print "\tRunning testcase 2"
22
23     def testcase_3 (self):
24         print "\tRunning testcase 3"
25
26     def testcase_standard (self):
27         print "\tRunning testcase standard"
28
29     def main (self):
30
31         from optparse import OptionParser
32         usage="""Usage: %prog [options] steps
33 steps can include + like in %prog 1 2+3"""
34         parser = OptionParser (usage=usage)
35         parser.add_option ("-v","--verbose",action="store_true",
36                            dest="verbose",default=False,
37                            help="run in verbose mode")
38         parser.add_option ("-a","--all",action="store_true",
39                            dest="all",default=False,
40                            help="Run all known testcases")
41         (self.options, args)=parser.parse_args()
42         
43         ### get the list of steps to run
44         steps=[]
45         if self.options.all:
46             # locates all local methods starting with "testcase_"
47             for method_name in dir(self):
48                 # does it start with testcase_
49                 if (method_name.find('testcase_',0,len('testcase_'))==0):
50                     print 'considering method',method_name
51                     steps+=[method_name]
52         else:
53             for arg in args:
54                 # support for the 2+3 syntax
55                 steplist=arg.split("+")
56                 for step in steplist:
57                     steps += [ 'testcase_'+step]
58
59         ### run them
60         # args contains the steps to run
61         for method_name in steps:
62             method=getattr(self,method_name)
63             if method:
64                 print '============================== TestCases mainloop'
65                 self.initialize()
66                 method()
67                 self.cleanup()
68
69 if __name__ == "__main__":
70     TestCases().main()