From 835b8c45572d69780dfea0add7fa9722e0a5e0b7 Mon Sep 17 00:00:00 2001 From: boccioli_m Date: Tue, 12 Jan 2016 09:38:58 +0100 Subject: [PATCH] Improved documentation --- script/tests/templates/testTemplate.py | 71 +++++++++++++------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/script/tests/templates/testTemplate.py b/script/tests/templates/testTemplate.py index a54f175..e29854f 100644 --- a/script/tests/templates/testTemplate.py +++ b/script/tests/templates/testTemplate.py @@ -11,14 +11,14 @@ def startTest(testName, DEVICE, params): """ Main method running the test """ - # by default, assume the test failed + # by default, assume the test failed. ret = 'Test failed' status = False - # plot name to be given to the scan. Use: scan.setPlotName(plotName) + # plot name to be given to the scan. Use: scan.setPlotName(plotName). plotName = DEVICE + ' - ' + testName - # put the whole custom code under try/catch + # put the whole custom code under try/catch. try: - # get the path of this script + # get the path of this script. testPath = inspect.getfile(inspect.currentframe()) # init the testing tool class. It can be sued in the following ways: test = TestingTool(testName, testPath, DEVICE, params) @@ -47,29 +47,30 @@ def startTest(testName, DEVICE, params): test.sendFeedback(ret,success) method that ends the testing script and gives the report to the calling application. Examples: - whenever the code must quit (i.e. after an error), you must end with: - ret = 'here is some info on what failed on the test' - success = false - test.sendFeedback(ret, success) + whenever the code must quit (i.e. after an error), you must end with the following 3 lines: + ret = 'here is some info on what failed on the test' # This is your return message + success = False # The test did not complete successfully + test.sendFeedback(ret, success) # Return to pshell - whenever the code is finished successfully, you must end with: - ret = 'here is some info on the success of the test' - success = true - test.sendFeedback(ret, success) + whenever the code is finished successfully, you must end with the following 3 lines: + ret = 'here is some info on the success of the test' # This is your return message + success = True # The test complete successfully + test.sendFeedback(ret, success) # Return to pshell ----------------------------------- LOG INFO: - when some information must be shown on the log, use: - test.log('test to log') + when some information must be shown on the log on pshell, use the following line: + test.log('text to log') """ ########## Example (can be removed) ###### - # print the list of parameters passed. If any error, stop and send feedback + # print the list of parameters passed. If any error, stop and send feedback. test.log("Example - Test name: " + testName) test.log("Example - Device name: " + DEVICE) try: test.log("Running test with the following parameters:") test.log(params) - # If present, use the parameters here below for your test script. You might need to change the casting + # If present, use the parameters here below for your test script. + # These parameters were automatically generated: you might need to change the casting. #$testParameters except: ret = 'Could not retrieve testing parameters - ' + traceback.format_exc() @@ -78,41 +79,41 @@ def startTest(testName, DEVICE, params): return # loop to read channels for a while and plot the channels values. - # initialise plot tab with 2 plots + # initialise plot tab with 2 plots: pass here the axis names. scan = ManualScan(['sample'], ['Motor Status (MSTA)', 'Motor Position (VAL)']) - # set plot name(tab title) + # set plot name(tab title). scan.setPlotName(plotName) - # start plots. See further below how to add points to the plots + # start plots. See further below how to add points to the plots (scan). scan.start() # IMPORTANT: if the test failed, write the report into the variables ret and success. # for example, write the following: ret = "Example - Error, the test failed because...." success = False - # set up connection to channels. "type" of data can be "d" (= double), "l" (= long) + # set up connection to channels. "type" of data can be "d" (= double), "l" (= long). try: pv_motor_msta = Channel(DEVICE + ':MOTOR.MSTA', type='d') pv_motor_val = Channel(DEVICE + ':MOTOR.VAL', type='d') except: - # prepare return information: return text + # prepare return information: return text. ret = 'Unable to create channel - ' + traceback.format_exc() - # prepare return information: return success + # prepare return information: return success. success = False - # send return information + # send return information. test.sendFeedback(ret, success) return - # take 100 samples of the channels + # take 100 samples of the channels and plot them. for sample in range(0, 100): - readback1 = sample - sleep(0.1) # Settling time - # get value + readback1 = sample #the x axis. + sleep(0.1) # Settling time. + # get value. motor_msta = pv_motor_msta.get() - # get value + # get value. motor_val = pv_motor_val.get() - # add values to plot - scan.append([sample], [readback1], [motor_msta, motor_val]) + # add values to plot. + scan.append([readback1], [readback1], [motor_msta, motor_val]) - # Closing channels + # Closing channels: all channels that were opened with Channel() must be closed before exit. pv_motor_msta.close() pv_motor_val.close() @@ -127,21 +128,21 @@ def startTest(testName, DEVICE, params): ################ END OF YOUR CODE ################ ###### Final - DO NOT MODIFY THE CODE BELOW ###### - # just in case the feedback was forgotten + # just in case the feedback was forgotten. test.sendFeedback(ret, success) except (KeyboardInterrupt): - # user stop error handler + # user stop error handler. ret = 'Test stopped by user.' success = False test.sendFeedback(ret, success) except: - # generic error handler + # generic error handler. ret = traceback.format_exc() success = False test.sendFeedback(ret, success) -# launch the test +# launch the test. startTest(test, device, parameters) ################ END OF Final ####################