Files
ncs/script/tests/templates/testTemplate.py
boccioli_m d5f7c95549 Startup
2015-09-02 09:01:33 +02:00

119 lines
5.4 KiB
Python

#Test name: $testName
#$testDescription
###### Init - DO NOT MODIFY THE CODE BELOW ######
global print_log, sendFeedback, inspect, log, sys, inspect, os, traceback
import sys, inspect, os, traceback
def print_log(testName, DEVICE, text):
time.ctime()
now = time.strftime('%Y.%m.%d %H:%M:%S')
print now + ' ' + DEVICE + ' - ' + testName + ': ' + str(text)
log (now + ' ' + DEVICE + ' - ' + testName + ': ' + text )
#prepare and send feedback to calling tool
def sendFeedback(testPath, testName, DEVICE, returnString, testPassed):
print_log(testName, DEVICE, 'End of test. Result:')
print_log(testName, DEVICE, 'Device: ' + DEVICE)
print_log(testName, DEVICE, 'Test name: ' + testName)
print_log(testName, DEVICE, 'Test path: ' + testPath)
print_log(testName, DEVICE, 'Test passed: ' + str(testPassed))
print_log(testName, DEVICE, 'Return string: ' + returnString)
ret = [testPath, DEVICE, returnString, testPassed]
set_return(ret)
def startTest(testName, DEVICE, params):
try:
import traceback
#get the path of this script
testPath = inspect.getfile(inspect.currentframe())
#by default, failed
ret = 'Test failed'
success = False
#plot name to be given to the scan. Use: scan.setPlotName(plotName)
plotName = DEVICE + ' - ' + testName
######### WRITE YOUR CODE HERE BELOW #############
#All the code here in this section ## ..YOUR CODE.. ## can be modified/deleted.
# INPUTS:
#If needed, the following variables are available:
#testPath string, path of this test file
#testName string, name of this test
#DEVICE string, device for which the test must run (typically it is the beginning of a process variable name)
#params dictionary, a set of key-value parameters specific to the test.
# Syntax: params["<key>"]["value"]
# Example: access the parameter called midPoint and store it in a new variable:
# middlePoint = params["midPoint"]["value"]
# OUTPUTS:
#ret string, a text summarizing the result of the test. It must be set before the end of your code.
#success bool, True = test successful. It must be set before the end of your code.
#Example (can be removed): print the list of parameters passed. If any error, stop and send feedback
print_log(testName, DEVICE, "Example - Test name: "+testName):
print_log(testName, DEVICE, "Example - Device name: "+DEVICE):
try:
print_log(testName, DEVICE, "Running test Initialise with the following parameters:")
print_log(testName, DEVICE, params )
#If present, use the parameters here below for your test script
#$testParameters
except:
ret = 'Could not retrieve testing parameters - ' + traceback.format_exc()
success = False
sendFeedback(testPath, testName, DEVICE, ret, success)
return
#example: loop to read channels for a while and plot the channels values.
#initialise plot tab with 2 plots
scan = ManualScan(['sample'], ['Motor Status (MSTA)', 'Motor Position (VAL)'] )
#set plot name(tab title)
scan.setPlotName(plotName)
#start plots. See further below how to add points to the plots
scan.start()
#IMPORTANT: if the test resulted with an error, write the following:
ret = "Example - Error, the test failed because...."
success = False
#IMPORTANT: if the test was successful, write the following:
ret = "Example - Test successful, here some detail: ..."
success = True
#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
ret = 'Unable to create channel - ' + traceback.format_exc()
#prepare return information: return success
success = False
#send return information
sendFeedback(testPath, testName, DEVICE, ret, success)
return
#take 100 samples of the channels
for sample in range(0, 100):
readback1 = sample
sleep( 0.1 ) # Settling time
#get value
motor_msta = pv_motor_msta.get()
#get value
motor_val = pv_motor_val.get()
#add values to plot
scan.append ([sample], [readback1], [detmotor_msta, motor_val] )
#Closing channels
pv_motor_msta.close()
pv_motor_val.close()
#once the test is finished, no need to do anything. The code below yours will do the rest.
################ END OF YOUR CODE ################
###### Final - DO NOT MODIFY THE CODE BELOW ######
sendFeedback(testPath, testName, DEVICE, ret, success)
except:
ret = traceback.format_exc()
success = False
sendFeedback(testPath, testName, DEVICE, ret, success)
return
#launch the test
startTest(test, device, parameters)