|
| 1 | +__author__ = 'k22li' |
| 2 | + |
| 3 | +import re |
| 4 | +import os |
| 5 | +import os.path as Path |
| 6 | + |
| 7 | +PATH_TO_TEST=r'C:\Users\k22li\workspace\bsta\bsta\cases\test' |
| 8 | +TARGET_PATH=r'/home/k22li/N/NST_Home/NSTRunner/cases/test' |
| 9 | + |
| 10 | + |
| 11 | +def listAllFiles(path): |
| 12 | + |
| 13 | + if os.path.isdir(path): |
| 14 | + return os.listdir(path) |
| 15 | + else: |
| 16 | + return '' |
| 17 | + |
| 18 | +def removeNonPythonScripts(fileList): |
| 19 | + |
| 20 | + if '__init__.py' in fileList: |
| 21 | + fileList.remove('__init__.py') |
| 22 | + return fileList |
| 23 | + |
| 24 | +def caseFilter(fileName): |
| 25 | + |
| 26 | + patten_gourNo = re.compile('self._grouNO = \'(\d*)\'') |
| 27 | + patten_caseNo = re.compile('self._caseNO = \'(\d*)\'') |
| 28 | + |
| 29 | + file = Path.join(PATH_TO_TEST, fileName) |
| 30 | + if not Path.isfile(file): |
| 31 | + raise BaseException, 'Invalid file path provided!' |
| 32 | + else: |
| 33 | + with open(file, 'r+') as filer: |
| 34 | + for line in filer.readlines(): |
| 35 | + if re.search(patten_gourNo, line): |
| 36 | + groupNo = re.search(patten_gourNo, line).group(1) |
| 37 | + elif re.search(patten_caseNo, line): |
| 38 | + caseNo = re.search(patten_caseNo, line).group(1) |
| 39 | + realPath=os.path.join(TARGET_PATH, fileName) |
| 40 | + return groupNo, caseNo, realPath |
| 41 | + |
| 42 | +def composeTestPlan(caseDict, whiteList): |
| 43 | + |
| 44 | + template='<testcase no="%s" name="" location="%s" refPhone = ""/>' |
| 45 | + |
| 46 | + prefix =""" |
| 47 | +<?xml version="1.0" encoding="utf-8"?> |
| 48 | +<testplan assignTo="a030623e,b3b9521d,1a2215a" resultPath="/home/k22li/N/NST_Home/TestResult" syncQRDLog="true"> |
| 49 | + <target-device hwversion="" osversion="" deviceid=""/> |
| 50 | + <testtask id="2" type="monkeyrunner" timeout="120">""" |
| 51 | + |
| 52 | + postfix = """ </testtask> |
| 53 | +</testplan>""" |
| 54 | + print prefix |
| 55 | + for case in cases.items(): |
| 56 | + if whiteList: |
| 57 | + if case[0] in whiteList: |
| 58 | + print '\t\t'+template %(case[0], case[1]) |
| 59 | + else: |
| 60 | + print '\t\t'+template %(case[0], case[1]) |
| 61 | + print postfix |
| 62 | + |
| 63 | +if __name__ == '__main__': |
| 64 | + cases = {} |
| 65 | + whiteList = ['5900.315', '5104.895', '5104.894', '5104.818', '5104.817', '5104.851', '5900.210', '5104.851', \ |
| 66 | + '5104.116', '5104.944', '5104.945', '5104.946', '5104.947', '5104.951', '5104.826'] |
| 67 | + |
| 68 | + files = listAllFiles(PATH_TO_TEST) |
| 69 | + |
| 70 | + scriptFiles = removeNonPythonScripts(files) |
| 71 | + for file in scriptFiles: |
| 72 | +# print file |
| 73 | + groupNo, caseNo, filePath = caseFilter(file) |
| 74 | + cases.update({groupNo+'.'+caseNo : filePath}) |
| 75 | + |
| 76 | + composeTestPlan(cases, whiteList) |
0 commit comments