This article mainly introduces python parsing text file examples. For more information, see python. recently, the main task is to test component compatibility. The original framework has many functions that are not complete yet and need to be supplemented! For example, you need to write the execution result of the AutoIt script to Excel. The final solution is to use the local log to parse the result!
Added the following class to complete the above functions:
The code is as follows:
Class AutoItResultParser ():
Def ParseResult (self, vm_result, log_file ):
For case_result in vm_result.cases_results:
Self. _ ModifyAutoItResult (case_result, log_file)
Def _ ModifyAutoItResult (self, result, log_file ):
Items = []
Myfile = open (log_file, 'RB ')
Line = myfile. readline ()
Count = 0
While (''! = Line ):
Items. append (line. split (':') [0])
Count + = 1
If (count % 2 = 0 ):
Items. append (line. split (':') [1])
Line = myfile. readline ()
Myfile. close ()
Fail_scripts = []
Length = len (items)
Arr = list (range (2, length, 3 ))
For I in arr:
Test = items [I]. lower ()
If test. rfind ('success') =-1:
Fail_scripts.append (items [I-2], items [I-1])
For script in fail_scripts:
If script [0] = result. case_name:
If script [1] = 'installation ':
Result. install_script_success = False
Elif script [1] = 'launch ':
Result. launch_script_success = False
Elif script [1] = 'function ':
Result. function_script_success = False
Else:
Result. uninstall_script_success = False
The content of the log_file file is similar to the following:
The code is as follows:
VisualStudio2010_StandaloneProfiler:
Installation: Success
VisualStudio2010_StandaloneProfiler:
Launch: Success
VisualStudio2010_StandaloneProfiler:
Function: Fail
TaobaoBrowser_2.0.0:
CitrixOfflinePlugin_6.5:
Installation: Success
CitrixOfflinePlugin_6.5:
Function: Success
TrusteerRapport:
TNTShippingTools:
Installation: Success
TNTShippingTools:
Launch: Success
WGET_1.11.4:
Installation: Success
VisualStudio2010_StandaloneProfiler:
Uninstallation: Success
TNTShippingTools:
Uninstallation: Fail