1
2 '''
3 Created on 26-Dec-2012
4
5 @author: Anil Kumar (anilkumar.s@paxterrasolutions.com)
6 '''
7 import re
8 import sys
11 try :
12 testFileHandler = open(testFile, 'r')
13 except IOError:
14 print "No such file "+testFile
15 sys.exit(0)
16
17 testFileList = testFileHandler.readlines()
18 self.testscript = testFileList
19 self.caseCode = {}
20 self.caseBlock = ''
21 self.statementsList = []
22 index = 0
23 self.statementsList = []
24
25 while index < len(testFileList):
26 testFileList[index] = re.sub("^\s{8}|^\s{4}", "", testFileList[index])
27
28 if re.match('^(\'\'\')|^(\"\"\")',testFileList[index],0) :
29 index = index + 1
30 try :
31 while not re.match('^\s*(\'\'\')|^\s*(\"\"\")',testFileList[index],0) :
32 index = index + 1
33 except IndexError,e:
34 print ''
35
36
37
38 elif not re.match('#|^\s*$',testFileList[index],0):
39 self.statementsList.append(testFileList[index])
40 index = index + 1
41
43 index = 0
44 statementsList = self.statementsList
45 while index < len(statementsList):
46
47 m= re.match('def\s+CASE(\d+)',statementsList[index],0)
48 self.caseBlock = []
49 if m:
50
51 index = index + 1
52 try :
53 while not re.match('\s*def\s+CASE(\d+)',statementsList[index],0) :
54 self.caseBlock.append(statementsList[index])
55 if index < len(statementsList)-1:
56 index = index + 1
57 else :
58 break
59 index = index - 1
60 except IndexError,e:
61
62 print ''
63
64 self.caseCode [str(m.group(1))] = self.caseBlock
65
66 index = index + 1
67
68 return self.caseCode
69
71 index = 0
72 step = 0
73 stepCode = {}
74 step_flag = False
75 while index < len(caseStatements):
76 m= re.match('main\.step',caseStatements[index],0)
77 stepBlock = ''
78 if m:
79 step_flag = True
80 if step == 0 :
81 i = 0
82 block = ''
83 while i <= index :
84 block += caseStatements[i]
85 i = i + 1
86 stepCode[step] = block
87 step = step + 1
88 stepBlock= stepBlock + caseStatements[index]
89 index = index + 1
90 try :
91 while not re.match('main\.step',caseStatements[index],0) :
92 stepBlock= stepBlock + caseStatements[index]
93 if index < len(caseStatements)-1:
94 index = index + 1
95 else :
96 break
97 index = index - 1
98 except IndexError,e:
99
100 print ''
101 stepCode[step] = stepBlock
102 step = step + 1
103 index = index + 1
104
105 if not step_flag :
106 stepCode[step] = "".join(caseStatements)
107 return stepCode
108
110 case_step_code = {}
111 case_block = self.case_code()
112
113 for case in case_block :
114 case_step_code[case] = {}
115 step_block = self.step_code(case_block[case])
116 for step in step_block :
117 case_step_code[case][step] = step_block[step]
118 return case_step_code
119