Files
ncs/script/tests/templates/testTemplate.py
boccioli_m 104d203536 Startup
2015-08-28 17:35:28 +02:00

85 lines
4.0 KiB
Python

#$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
#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
#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)