00001 #!/usr/local/bin/python 00002 # 00003 # Copyright 2002 00004 # by 00005 # The Board of Trustees of the 00006 # Leland Stanford Junior University. 00007 # All rights reserved. 00008 # 00009 00010 __facility__ = "Online" 00011 __abstract__ = "Example test suite" 00012 __author__ = "S. Tuvi <stuvi@SLAC.Stanford.edu> SLAC - GLAST LAT I&T/Online" 00013 __date__ = ("$Date: 2005/05/17 01:33:03 $").split(' ')[1] 00014 __version__ = "$Revision: 1.5 $" 00015 __credits__ = "SLAC" 00016 00017 import LATTE.copyright_SLAC 00018 00019 # History: 00020 # $Log: testSuite.py,v $ 00021 # Revision 1.5 2005/05/17 01:33:03 stuvi 00022 # As per LTE-264, added support for standalone suites and scripts. 00023 # 00024 # Revision 1.4 2005/01/27 23:06:48 stuvi 00025 # Removed the lastScript parameter from the second scriptRun 00026 # We don't have to check if the script was stopped in order to call doStopRun method. 00027 # 00028 # Revision 1.3 2005/01/11 22:39:55 stuvi 00029 # no message 00030 # 00031 # Revision 1.2 2004/10/20 03:44:55 stuvi 00032 # Commented out the selection of another schema since we want to use the one selected by RunControl. 00033 # 00034 # Revision 1.1 2004/08/07 02:10:42 stuvi 00035 # Test suite examples. 00036 # 00037 # Revision 1.5 2004/01/24 00:27:17 stuvi 00038 # Modified to use the appdir from preferences 00039 # 00040 # Revision 1.4 2003/12/11 01:53:00 stuvi 00041 # Now calling the regular test applications to show that there is no need to change the tests to run them in suites. 00042 # 00043 # Revision 1.3 2003/12/11 01:23:27 stuvi 00044 # Modified and documented the code according to the new rcSuite implementation. 00045 # 00046 # Revision 1.2 2003/07/26 04:15:30 stuvi 00047 # Fixed schema path 00048 # 00049 # Revision 1.1 2003/03/28 03:21:41 stuvi 00050 # Fixed FITS file status display 00051 # Added test suite capability 00052 # 00053 00054 from LATTE.runcontrol.rcSuite import rcSuite 00055 import logging as log 00056 import os 00057 00058 00059 class userSuite(rcSuite): 00060 "Implmentation class for a user application" 00061 def __init__(self, gui, userId, debug): 00062 rcSuite.__init__(self, gui, userId, debug) 00063 log.debug("userSuite.__init__()") 00064 00065 def getName(self): 00066 return __name__ 00067 00068 def setupSuite(self): 00069 # This method is executed after rcStartSuite successfully loads a schema (either 00070 # through the RunControl GUI or by reusing a previously loaded schema) 00071 #self.__schema = os.path.join(os.environ['ONLINE_ROOT'], 'LATTE/repos/simpleTemSchema.xml') 00072 pass 00073 00074 def pauseSuite(self): 00075 # This method is executed before the currently running application is paused. 00076 # Note that there is currently no way to pause a suite, meaning if there is some 00077 # lengthy code that executes between scriptRun calls, that can not be paused. 00078 # Pause can be rejected by not returning None 00079 log.debug("userSuite.pauseSuite") 00080 return None 00081 00082 def startSuite(self): 00083 try: 00084 00085 # We pass the sesssion variables using a dictionary. 00086 # The set/getSessionVar methods can also be used. 00087 # Please do not use session variables which start with the "_" (underscore) 00088 # character as these are reserved for RunControl use 00089 sessionContext = {"test":"abc"} 00090 00091 # The module name can either be a python file name or a module name 00092 # If a full path is specified then the module at that location is used 00093 # otherwise the PYTHONPATH is searched 00094 00095 # The following script will change the value of session var "test" 00096 appDir = self.gui.preferences()['appdir'] 00097 sessionStateAfterTest1 = self.scriptRun(module=os.path.join(appDir,'testAppCal'), 00098 context=sessionContext) 00099 00100 # The following script will print the value of session var "test" and modify it 00101 sessionStateAfterTest2 = self.scriptRun(module=os.path.join(appDir,'testAppEvt')) 00102 00103 print sessionStateAfterTest1 00104 print sessionStateAfterTest2 00105 00106 # The schema for subsequent tests or suites can be changed using the following methods. 00107 # The schema chosen when the top level suite was selected in RunControl is still saved 00108 # in case the operator checked the "Reuse schema" checkbox on the load application dialog 00109 #self.readSchema(self.__schema) 00110 #self.applyConfig() 00111 00112 # When the stop button is clicked a StopRequestedException is thrown after which 00113 # the current executing application is interrupted and rcStoprun and rcTeardown 00114 # is called. The suite calling the application should trap the exception using 00115 # a try block as demonstrated below and take the appropriate action. 00116 # 00117 # StopRequestedException class has three members. "msg" contains a generic message, 00118 # "suite" contains the name of the suite that was executing when the stop button was 00119 # clicked. Note that currently only the immediate parent suite name is recorded in 00120 # the exception. The third member is the "module" which contains the name of the 00121 # application that was executing at the time. 00122 self.scriptRun(module=os.path.join(appDir,'testSuite2')) 00123 except rcSuite.StopRequestedException, e: 00124 log.info("%s, suite: %s, module: %s" % (e.msg, e.suite, e.module)) 00125 00126 # Normally the suite appears to be running even after all the tests have been completed. 00127 # In order to stop the suite the operator must click on the stop button. Alternatively 00128 # the suite can issue the stop by calling self.gui.doStopRun similar to the way it is 00129 # done with applications. Note that a flag is being used to make sure that rcStopSuite 00130 # hasn't already been called (ie. the suite was interrupted before it completed). 00131 if self.gui is not None: 00132 self.gui.doStopRun() 00133 00134 # stopSuite is called after rcStopSuite has been executed. If a sub-suite within the suite 00135 # is currently executing then the sub-suite's rcStopSuite is called and then this method 00136 # is called. 00137 def stopSuite(self): 00138 log.info("End of suite 1") 00139 00140 class userSuiteCallbacks(rcSuite.SuiteCallbacks): 00141 def __init__(self): 00142 pass 00143 00144 def beforeSetupSuite(self, suite): 00145 log.info("Before setupSuite") 00146 00147 def beforeStartSuite(self, suite): 00148 log.info("Before startSuite") 00149 00150 def afterStopSuite(self, suite): 00151 log.info("After stopSuite") 00152 00153 # Standalone mode: 00154 if __name__ == "__main__": 00155 00156 mycb = userSuiteCallbacks() 00157 usl = rcSuite.StandaloneLauncher(logLevel="INFO") 00158 usl.launch(suiteClass=userSuite, user=321, callbacks=mycb) 00159