-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
main files
- Loading branch information
Showing
5 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
"""Test case basic class. | ||
Note: | ||
Contents: | ||
- BaseTestCaseClass: test case base class | ||
XXX To do: | ||
""" | ||
|
||
__version__ = "0.1" | ||
__all__ = ["BaseTestCaseClass"] | ||
|
||
import os | ||
import sys | ||
import ConfigParser | ||
import re | ||
import util | ||
|
||
DEFAULT_ERROR_MESSAGE = """\ | ||
<head> | ||
<title>Error response</title> | ||
</head> | ||
<body> | ||
<h1>Error response</h1> | ||
<p>Error code %(code)d. | ||
<p>Message: %(message)s. | ||
<p>Error code explanation: %(code)s = %(explain)s. | ||
</body> | ||
""" | ||
|
||
DEFAULT_ERROR_CONTENT_TYPE = "text/html" | ||
|
||
class BaseTestCaseClass(): | ||
"""Test case basic class. | ||
""" | ||
conf_path = "./common_conf.conf" | ||
utp_name = "" | ||
|
||
def set_utp_name(self,utp_name_set): | ||
self.utp_name = utp_name_set | ||
return None | ||
|
||
def get_UTP_path(self): | ||
"""To get the common conf like path of UTP.""" | ||
UT_group = "utp" | ||
UT_path = util.get_conf(self.conf_path,UT_group,self.utp_name) | ||
return UT_path | ||
|
||
def get_data_info(self): | ||
"""To get the infomation of data set. """ | ||
c = sys._getframe(2) | ||
case_name = c.f_code.co_filename | ||
data_path = case_name.replace("case_","data_")[:-3] #This has to be fix to changing the first. | ||
print data_path | ||
if os.path.isdir(data_path): | ||
data_info = ["dir",data_path] | ||
elif os.path.isfile(data_path): | ||
data_info = ["file",data_path] | ||
else: | ||
data_info = None | ||
return data_info | ||
|
||
def data_runner(self,dc,UT_path): | ||
"""To run a single data using a test case.""" | ||
dc_info = dc.split(" ") | ||
dc_name = dc_info[0].strip() | ||
dc_input_UT = dc_info[1].strip() | ||
dc_input_expect = dc_info[2].strip() | ||
dc_output_UT = os.popen(dc_input_UT).read() | ||
dc_output_expect = os.popen(dc_input_expect).read() | ||
if dc_output_UT == dc_output_expect: | ||
dc_result = 1 | ||
else: | ||
dc_result = 0 | ||
return dc_result, dc_name | ||
|
||
def data_manager(self,data_info,UT_path): | ||
"""To run a single case.""" | ||
pass_num = 0 | ||
fail_num = 0 | ||
log = [] | ||
if data_info[0] == "file": | ||
data_file = open(data_info[1]) | ||
data_cases = data_file.readlines() | ||
for dc in data_cases: | ||
if re.match("data_",dc): | ||
data_result, dc_name = self.data_runner(dc,UT_path) | ||
if data_result == 1: | ||
pass_num += 1 | ||
elif data_result == 0: | ||
fail_num += 1 | ||
log.append(dc_name) | ||
else: | ||
pass | ||
elif data_info[0] == "dir": | ||
pass | ||
log = ";".join(log) | ||
return pass_num,fail_num,log | ||
|
||
def log_printer(self,pass_num,fail_num,log_str): | ||
"""logger""" | ||
log = {} | ||
log.update({"pass":pass_num}) | ||
log.update({"fail":fail_num}) | ||
log.update({"log":log_str}) | ||
return log | ||
|
||
def run_me(self): | ||
"""main function""" | ||
data_info = self.get_data_info() | ||
UT_path = self.get_UTP_path() | ||
pass_num,fail_num,log = self.data_manager(data_info,UT_path) | ||
print self.log_printer(pass_num,fail_num,log) | ||
return None | ||
|
||
if __name__ == "__main__": | ||
test = BaseTestCaseClass() | ||
test.set_utp_name("awk_ex") | ||
print test.get_UTP_path() | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[main] | ||
casePath = test_suite | ||
|
||
[utp] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#! /usr/bin/python | ||
import os,re,ConfigParser | ||
|
||
def case_list_collector(caseDir): | ||
try: | ||
dirList = os.listdir(caseDir) | ||
caseList = [] | ||
for item in dirList: | ||
if not os.path.isdir(item): | ||
if re.match('case_',item): | ||
caseList.append(item) | ||
return caseList | ||
except Exception,e: | ||
print "Get case list failed!" | ||
print e | ||
return None | ||
|
||
def case_runner(caseList): | ||
try: | ||
executeResults = {} | ||
for case in caseList: | ||
print str(case) + " is runing..." | ||
singleResult = os.popen('python ./test_suite/' + str(case)).readlines() | ||
singleResult = singleResult[1].strip() | ||
executeResults.update({str(case):singleResult}) | ||
return executeResults | ||
except Exception,e: | ||
print "Runner error!" | ||
print e | ||
return None | ||
|
||
def log_printer(executeResults): | ||
try: | ||
passNum = 0 | ||
failNum = 0 | ||
failCase = {} | ||
for resultCaseName in executeResults: | ||
singleResult = executeResults.get(resultCaseName) | ||
singleResult = eval(singleResult) | ||
singlePassNum = singleResult.get("pass") | ||
singleFailNum = singleResult.get("fail") | ||
singleLog = singleResult.get("log") | ||
passNum += int(singlePassNum) | ||
failNum += int(singleFailNum) | ||
if singleLog != "": | ||
failCase.update({resultCaseName:singleLog}) | ||
print "pass number is " + str(passNum) | ||
print "fail number is " + str(failNum) | ||
print "------------------------------" | ||
for resultCaseName in failCase: | ||
print resultCaseName | ||
failData = failCase.get(resultCaseName) | ||
for case in failData.split(";"): | ||
print " " + case | ||
print "------------------------------" | ||
except Exception,e: | ||
print "print log err!" | ||
print e | ||
|
||
if __name__ == "__main__" : | ||
cf = ConfigParser.ConfigParser() | ||
cf.read("common_conf.conf") | ||
caseDir = cf.get("main","casePath") | ||
caseList = case_list_collector(caseDir) | ||
if caseList != None and caseList != []: | ||
executeResults = case_runner(caseList) | ||
print executeResults | ||
if executeResults != None and executeResults != {}: | ||
log_printer(executeResults) | ||
print "Done!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"""Utils | ||
Note: | ||
Contents: | ||
-get_conf | ||
""" | ||
|
||
__version__ = "0.1" | ||
|
||
import os | ||
import sys | ||
import ConfigParser | ||
import re | ||
|
||
def get_conf(conf_path, info_group, info_key): | ||
"""conf handler""" | ||
cf = ConfigParser.ConfigParser() | ||
cf.read(conf_path) | ||
info_value = cf.get(info_group,info_key) | ||
return info_value |