def checkIDN(scpiObj): _printHeader("Test instrument identification") try: identity = InstrumentIdentification('ALBA', 'test', 0, _version()) scpiObj.addSpecialCommand('IDN', identity.idn) cmd = "*idn?" answer = _send2Input(scpiObj, cmd) print("\tRequest identification: %s\n\tAnswer: %r" % (cmd, answer)) result = True, "Identification test PASSED" except Exception as e: print("\tUnexpected kind of exception! %s" % e) print_exc() result = False, "Identification test FAILED" _printFooter(result[1]) return result
def testScpi(debug=False): start_t = _time() _printHeader("Testing scpi main class (version %s)" % (_version())) # ---- BuildSpecial('IDN',specialSet,identity.idn) with scpi(local=True, debug=debug, writeLock=True) as scpiObj: if debug: print(".") scpiObj.logLevel(_logger_DEBUG) scpiObj.log2File(True) scpiObj._debug("Log information: %s" % (scpiObj.loggingFile())) print("..") results = [] resultMsgs = [] for test in [checkIDN, addInvalidCmds, addValidCommands, checkCommandQueries, checkCommandWrites, checkNonexistingCommands, checkArrayAnswers, checkMultipleCommands, checkReadWithParams, checkWriteWithoutParams, checkLocks]: result, msg = test(scpiObj) results.append(result) tag, value = msg.rsplit(' ', 1) resultMsgs.append([tag, value]) _afterTestWait() if all(results): _printHeader("All tests passed: everything OK (%g s)" % (_time()-start_t)) else: _printHeader("ALERT!! NOT ALL THE TESTS HAS PASSED. Check the list " "(%g s)" % (_time()-start_t)) length = 0 for pair in resultMsgs: if len(pair[0]) > length: length = len(pair[0]) for result in resultMsgs: print("%s%s\t%s%s" % (result[0], " "*(length-len(result[0])), result[1], " *" if result[1] == 'FAILED' else "")) print("")
def testScpi(debug=False): start_t = _time() _printHeader("Testing scpi main class (version %s)" % (_version())) # ---- BuildSpecial('IDN',specialSet,identity.idn) with scpi(local=True, debug=debug, writeLock=True) as scpiObj: if debug: print(".") scpiObj.logLevel(_logger_DEBUG) scpiObj.log2File(True) scpiObj._debug("Log information: %s" % (scpiObj.loggingFile())) print("..") results = [] resultMsgs = [] for test in [ checkIDN, addInvalidCmds, addValidCommands, checkCommandQueries, checkCommandWrites, checkNonexistingCommands, checkArrayAnswers, checkMultipleCommands, checkReadWithParams, checkWriteWithoutParams, checkLocks ]: result, msg = test(scpiObj) results.append(result) tag, value = msg.rsplit(' ', 1) resultMsgs.append([tag, value]) _afterTestWait() if all(results): _printHeader("All tests passed: everything OK (%g s)" % (_time() - start_t)) else: _printHeader("ALERT!! NOT ALL THE TESTS HAS PASSED. Check the list " "(%g s)" % (_time() - start_t)) length = 0 for pair in resultMsgs: if len(pair[0]) > length: length = len(pair[0]) for result in resultMsgs: print("%s%s\t%s%s" % (result[0], " " * (length - len(result[0])), result[1], " *" if result[1] == 'FAILED' else "")) print("")