代碼如下:
#!/usr/bin/python
# -*- coding: cp936 -*-
#filename : SimpleAutoTest.py
import os,io
import sys
import re
#import lib.MyException.myExecpt
#--------------------------------------
# Class Name :SimpleAutoTest
#--------------------------------------
class SimpleAutoTest:
#--------------------------------------------------
# Function :
# method__ : 主函數 Main_() => private
#
# 設定運行參數SetFormat_() => private
# 寫日誌 _WriteLog() => public
# 讀取日誌 _ReadLog() => public
# 分析資料 _AnaylzData()=> public
# 結果估值 EvalData_() => private
#
# 修改:
# @date : 2009-4-20
# @writer: 天淵小劍
# 設定運行參數& _SetFormat() => public
# 主函數 _Main() => public
#
# 添加:
# @date : 2009-4-20
# @writer: 天淵小劍
# 預設設定 DefauleSetting_() => private
# @package : lib/__init__.py
# @Exception handling : lib/MyException/myExcept.py
#--------------------------------------------------
def __init__ (self,exeFile,logFile,url):
'''
__init__
'''
self.SysPath = os.getcwd()
self.ToolPath = self.SysPath+'\\tool\\'
self.LogPaht = self.SysPath+'\\Log\\'
self.ToolName = exeFile
self.LogName = logFile
self.Url = url
self.CMD_ = ''
def _Main(self):
self.DefauleSetting_()
self.SysCmd()
def DefauleSetting_ (self):
self.CMD_ = ' -n 3 -c 4 '
def SysCmd (self):
try:
self.Results = os.popen(self.ToolPath+self.ToolName+self.CMD_+self.Url).readlines()
self._AnaylzData()
except OSError:
print('運行有問題')
os.close()
def _WriteLog(self):
try:
f = open(self.LogPaht+self.LogName,'w')
for line in self.Results:
f.write(line)
except EOFError:
print("沒找到檔案")
sys.exit(1)
def _AnaylzData (self):
if len(self.Results)>1:
Static = self.Results[4]
Res_chk=Static.find('done')
if Res_chk:
print('分析結果:這是正確的運行過程')
else:
print('分析結果:這是有問題運行過程')
else:
print('運行有問題無法進行分析結果!')
'''
def _SetFormat(self,reqNum=3,ccyNum=4,timernu=''):
self.REQ_NUM = ' -n '+reqNum
self.CCY_NUM = ' -c '+ccyNum
self.CMD = self.REQ_NUM + self.CCY_NUM + self.TIMER
def EvalData__ (self):
'''
#--------------------------------------
# Test Name :
#--------------------------------------
exeFile = 'ab'
logFile = 'log.log'
url = 'http://51hongka.com/a/index.html';
bf = SimpleAutoTest(exeFile,logFile,url)
bf._Main()
bf._WriteLog()