from myutils import scanner def firstword(line): print line.split()[0] file = open('data') scanner(file, firstword)
from cStringIO import StringIO from myutils import scanner def firstword(line): print line.split()[0] string = StringIO('one\ntwo xxx\nthree\n') scanner(string, firstword)
for line in input: pricess(line) def scanner(file, handler): for line in file: handler(line) from myutils import scanner def firstword(line): print line.split()[0] file = open('data.txt') scanner(file, firstword) from cStringIO import StringIO from myutils import scanner def firstword(line): print line.split()[0] string = StringIO('one\nTwo xxx\nthree\n') scanner(string, firstword) def scanner(file, handler): for line in file: handler(line)
def runTestCase(testListFile, testID, grp=0): global U print "\n*** Running Test - %s *** \n" % testID initFile = ReadMapFile(testListFile, testID, "!") testFile = ReadMapFile(testListFile, testID, "!", 2) if initFile == -1 or testFile == -1: print "Invalid test case - %s" % testID exit(1) setattr(U, "initFile", initFile) #init Logging init_logging(U.testID, 1, grp) tmsPacket.ProgramName = U.progName logging.info("\n Test Info %s" % U) uccPath = U.cmdPath if uccPath.endswith('\\') == 0: uccPath = uccPath + '\\' setUCCPath(uccPath) initFile = uccPath + initFile testFile = uccPath + testFile # Run Init Env if not re.search("WMM-", testID): if U.qual: InitTestEnv(U.testID, U.cmdPath, U.progName, U.initFile, U.TBFile, U.qual, U.TB_QUAL_AP, U.TB_QUAL_STA) else: InitTestEnv(U.testID, U.cmdPath, U.progName, U.initFile, U.TBFile) #Run UCC Core if os.path.exists(initFile) == 0: logging.error("Invalid file name - %s" % initFile) wfa_print_result("1") if os.path.exists(testFile) == 0: logging.error("Invalid file name - %s" % testFile) wfa_print_result("1") logging.info("\n %7s Testcase Init File = %s \n" % ("", initFile)) logging.info("\n %7s Testcase Command File = %s \n" % ("", testFile)) if U.qual: fileW = open("%s\DUTParam.txt" % (U.cmdPath), 'w') print "- DUT NAME [%s]" % U.DUT_NAME.lower() dut_ca = ReadMapFile(initFile, "wfa_control_agent_%s" % U.DUT_NAME.lower(), "!") # Following assumes that $Channel is the first parmater in InitEnv.txt channel = ReadMapFile("%s\InitEnv.txt" % U.cmdPath, "define", "!", 2) band = "24G" if int(channel) > 35: band = "5G" fileW.write("wfa_control_agent_dut!%s!\n" % dut_ca) fileW.write("define!$DUT_Name!%s!\n" % (U.DUT_NAME)) fileW.write("define!$DutMacAddress!$%sMACAddress_%s!\n" % (U.DUT_NAME, band)) fileW.write("define!$APUT_uname!%sUserName!\n" % (U.DUT_NAME)) fileW.write("define!$APUT_pword!%sAPPassword!\n" % (U.DUT_NAME)) fileW.write("define!$APUT_hostname!%sHostName!\n" % (U.DUT_NAME)) fileW.close() logging.info("START: TEST CASE [%s] " % testID) try: expt_msg = "" fileInit = open(initFile) print "\n-------------------\n" scanner(fileInit, firstword) print "\n-------------------\n" process_cmdfile(testFile) except Exception: expt_msg = "%s" % sys.exc_info()[1] finally: if expt_msg != "": wfa_print_result(0, expt_msg) else: wfa_print_result(1) logging.info("END: TEST CASE [%s] " % testID) fileInit.close() reset()
def runTestCase(testListFile, testID, grp=0): global U, starttime print "\n*** Running Test - %s *** \n" % testID initFile = ReadMapFile(testListFile, testID, "!") testFile = ReadMapFile(testListFile, testID, "!", 2) if initFile == -1 or testFile == -1: print "Invalid test case - %s" % testID exit(1) setattr(U, "initFile", initFile) #init Logging init_logging(U.testID, 1, grp) tmsPacket.ProgramName = U.progName tmsPacket.TestResult = "FAIL" tmsPrint() logging.info("\n Test Info %s" % U) uccPath = U.cmdPath if uccPath.endswith('\\') == 0: uccPath = uccPath + '\\' setUCCPath(uccPath) initFile = uccPath + initFile testFile = uccPath + testFile # Run Init Env if not re.search("WMM-", testID): if U.qual: InitTestEnv(U.testID, U.cmdPath, U.progName, U.initFile, U.TBFile, U.qual, U.TB_QUAL_AP, U.TB_QUAL_STA) else: InitTestEnv(U.testID, U.cmdPath, U.progName, U.initFile, U.TBFile) #Run UCC Core if os.path.exists(initFile) == 0: logging.error("Invalid file name - %s" % initFile) wfa_print_result("1") if os.path.exists(testFile) == 0: logging.error("Invalid file name - %s" % testFile) wfa_print_result("1") logging.info("\n %7s Testcase Init File = %s \n" % ("", initFile)) logging.info("\n %7s Testcase Command File = %s \n" % ("", testFile)) if U.qual: fileW = open("%s\DUTParam.txt" % (U.cmdPath), 'w') print "- DUT NAME [%s]" % U.DUT_NAME.lower() dut_ca = ReadMapFile(initFile, "wfa_control_agent_%s" % U.DUT_NAME.lower(), "!") # Following assumes that $Channel is the first parmater in InitEnv.txt channel = ReadMapFile("%s\InitEnv.txt" % U.cmdPath, "define", "!", 2) band = "24G" if int(channel) > 35: band = "5G" fileW.write("wfa_control_agent_dut!%s!\n" % dut_ca) fileW.write("define!$DUT_Name!%s!\n" % (U.DUT_NAME)) fileW.write("define!$DutMacAddress!$%sMACAddress_%s!\n" % (U.DUT_NAME, band)) fileW.write("define!$APUT_uname!%sUserName!\n" % (U.DUT_NAME)) fileW.write("define!$APUT_pword!%sAPPassword!\n" % (U.DUT_NAME)) fileW.write("define!$APUT_hostname!%sHostName!\n" % (U.DUT_NAME)) fileW.close() logging.info("START: TEST CASE [%s] " % testID) try: expt_msg = "" fileInit = open(initFile) print "\n-------------------\n" scanner(fileInit, firstword) print "\n-------------------\n" process_cmdfile(testFile) except Exception: expt_msg = "%s" % sys.exc_info()[1] finally: if expt_msg != "": if re.search("r_info", expt_msg): wfa_print_result(1) else: wfa_print_result(0, expt_msg) else: wfa_print_result(1) if tmsPacket.TestResult != "PASS" and re.search("60G", U.testID): logging.info("#####Resetting the devices to their 60GHz defaults.....#####") resetFile = get_reset_default_file() if resetFile is None: logging.info("Reset file not found, skip resetting.....") else: resetFile= uccPath + resetFile process_cmdfile(resetFile) logging.info("END: TEST CASE [%s] " % testID) elapsed = (time.time() - starttime) logging.info("END: TEST CASE [%s] Execution Time [%s] seconds" % (testID, round(elapsed,2))) fileInit.close() reset()
class MyStream(object): def __iter__(self): # grab and return text from wherever return iter(["a\n", "b c d\n"]) from myutils import scanner def firstword(line): print line.split()[0] object = MyStream() scanner(object, firstword)