Added additional helper methods to TestData to eliminate overuse of make_path

This commit is contained in:
Jeff Wallace 2013-07-11 10:22:41 -04:00
parent 7952b7368c
commit 7c87217bf4

View File

@ -904,7 +904,7 @@ class TestResultsDiffer(object):
Args: Args:
test_data: the TestData of the test being performed test_data: the TestData of the test being performed
""" """
gold_dir = Emailer.make_path(test_config.img_gold, test_data.image_name, test_data.image_name + "SortedErrors.txt") gold_dir = test_data.get_sorted_errors_path(DBType.GOLD)
common_log = codecs.open(test_data.sorted_log, "r", "utf_8") common_log = codecs.open(test_data.sorted_log, "r", "utf_8")
gold_log = codecs.open(gold_dir, "r", "utf_8") gold_log = codecs.open(gold_dir, "r", "utf_8")
gold_dat = gold_log.read() gold_dat = gold_log.read()
@ -1039,6 +1039,8 @@ class TestData(object):
common_log_path: a pathto_File, the IMAGE_NAMECOMMON_LOG file common_log_path: a pathto_File, the IMAGE_NAMECOMMON_LOG file
sorted_log: a pathto_File, the IMAGENAMESortedErrors.txt file sorted_log: a pathto_File, the IMAGENAMESortedErrors.txt file
reports_dir: a pathto_Dir, the AutopsyTestCase/Reports folder reports_dir: a pathto_Dir, the AutopsyTestCase/Reports folder
gold_data_dir: a pathto_Dir, the gold standard directory
logs_dir: a pathto_Dir, the location where autopsy logs are stored
total_test_time: a String representation of the test duration total_test_time: a String representation of the test duration
start_date: a String representation of this TestData's start date start_date: a String representation of this TestData's start date
end_date: a String representation of the TestData's end date end_date: a String representation of the TestData's end date
@ -1068,11 +1070,13 @@ class TestData(object):
self.autopsy_data_file = Emailer.make_path(self.output_path, self.image_name + "Autopsy_data.txt") self.autopsy_data_file = Emailer.make_path(self.output_path, self.image_name + "Autopsy_data.txt")
self.warning_log = Emailer.make_local_path(self.output_path, "AutopsyLogs.txt") self.warning_log = Emailer.make_local_path(self.output_path, "AutopsyLogs.txt")
self.antlog_dir = Emailer.make_local_path(self.output_path, "antlog.txt") self.antlog_dir = Emailer.make_local_path(self.output_path, "antlog.txt")
self.test_dbdump = Emailer.make_path(self.output_path, self.image_name + "Dump.txt") self.test_dbdump = Emailer.make_path(self.output_path, self.image_name +
"DBDump.txt")
self.common_log_path = Emailer.make_local_path(self.output_path, self.image_name + COMMON_LOG) self.common_log_path = Emailer.make_local_path(self.output_path, self.image_name + COMMON_LOG)
self.sorted_log = Emailer.make_local_path(self.output_path, self.image_name + "SortedErrors.txt") self.sorted_log = Emailer.make_local_path(self.output_path, self.image_name + "SortedErrors.txt")
self.reports_dir = Emailer.make_path(self.output_path, AUTOPSY_TEST_CASE, "Reports") self.reports_dir = Emailer.make_path(self.output_path, AUTOPSY_TEST_CASE, "Reports")
self.gold_data_dir = Emailer.make_path(self.main_config.img_gold, self.image_name) self.gold_data_dir = Emailer.make_path(self.main_config.img_gold, self.image_name)
self.logs_dir = Emailer.make_path(self.output_path, "logs")
self.total_test_time = "" self.total_test_time = ""
self.start_date = "" self.start_date = ""
self.end_date = "" self.end_date = ""
@ -1145,13 +1149,39 @@ class TestData(object):
"""Get the path to the SortedData file that corresponds to the given DBType. """Get the path to the SortedData file that corresponds to the given DBType.
Args: Args:
DBType: the DBType of the path to be generated file_type: the DBType of the path to be generated
""" """
filename = self.image_name + "SortedData.txt" return self._get_path_to_file(file_type, "SortedData.txt")
def get_sorted_errors_path(self, file_type):
"""Get the path to the SortedErrors file that correspodns to the given
DBType.
Args:
file_type: the DBType of the path to be generated
"""
return self._get_path_to_file(file_type, "SortedErrors.txt")
def get_db_dump_path(self, file_type):
"""Get the path to the DBDump file that corresponds to the given DBType.
Args:
file_type: the DBType of the path to be generated
"""
return self._get_path_to_file(file_type, "DBDump.txt")
def _get_path_to_file(self, file_type, file_name):
"""Get the path to the specified file with the specified type.
Args:
file_type: the DBType of the path to be generated
file_name: a String, the filename of the path to be generated
"""
full_filename = self.image_name + file_name
if(file_type == DBType.GOLD): if(file_type == DBType.GOLD):
return Emailer.make_path(self.gold_data_dir, filename) return Emailer.make_path(self.gold_data_dir, full_filename)
else: else:
return Emailer.make_path(self.output_path, filename) return Emailer.make_path(self.output_path, full_filename)
class Reports(object): class Reports(object):
def generate_reports(csv_path, database, test_data): def generate_reports(csv_path, database, test_data):
@ -1201,7 +1231,7 @@ class Reports(object):
logs = "<div id='logs'>\ logs = "<div id='logs'>\
<h2><a name='" + test_data.image_name + "-logs'>Logs</a></h2>\ <h2><a name='" + test_data.image_name + "-logs'>Logs</a></h2>\
<hr color='#282828'>" <hr color='#282828'>"
logs_path = Emailer.make_local_path(test_config.output_dir, test_data.image_name, "logs") logs_path = test_data.logs_dir
for file in os.listdir(logs_path): for file in os.listdir(logs_path):
logs += "<p><a href='file:\\" + Emailer.make_path(logs_path, file) + "' target='_blank'>" + file + "</a></p>" logs += "<p><a href='file:\\" + Emailer.make_path(logs_path, file) + "' target='_blank'>" + file + "</a></p>"
logs += "</div>" logs += "</div>"
@ -1335,6 +1365,7 @@ class Reports(object):
name = get_image_name(full_name) name = get_image_name(full_name)
links.append("<a href='#" + name + "(0)'>" + name + "</a>") links.append("<a href='#" + name + "(0)'>" + name + "</a>")
html.write("<p align='center'>" + (" | ".join(links)) + "</p>") html.write("<p align='center'>" + (" | ".join(links)) + "</p>")
html.close()
def _generate_csv(csv_path, database, test_data): def _generate_csv(csv_path, database, test_data):
"""Generate the CSV log file""" """Generate the CSV log file"""
@ -1494,7 +1525,7 @@ class Logs(object):
"""Fill the global test config's variables that require the log files.""" """Fill the global test config's variables that require the log files."""
try: try:
# Open autopsy.log.0 # Open autopsy.log.0
log_path = Emailer.make_path(test_config.output_dir, test_data.image_name, "logs", "autopsy.log.0") log_path = Emailer.make_path(test_data.logs_dir, "autopsy.log.0")
log = open(log_path) log = open(log_path)
# Set the test_config starting time based off the first line of autopsy.log.0 # Set the test_config starting time based off the first line of autopsy.log.0
@ -1618,7 +1649,7 @@ def search_logs(string, test_data):
Returns: Returns:
a listof_String, the lines that contained the given String. a listof_String, the lines that contained the given String.
""" """
logs_path = Emailer.make_local_path(test_config.output_dir, test_data.image_name, "logs") logs_path = test_data.logs_dir
results = [] results = []
for file in os.listdir(logs_path): for file in os.listdir(logs_path):
log = codecs.open(Emailer.make_path(logs_path, file), "r", "utf_8") log = codecs.open(Emailer.make_path(logs_path, file), "r", "utf_8")
@ -1639,7 +1670,7 @@ def search_log(log, string, test_data):
Returns: Returns:
a listof_String, all the lines that the string is found on a listof_String, all the lines that the string is found on
""" """
logs_path = Emailer.make_local_path(test_config.output_dir, test_data.image_name, "logs", log) logs_path = Emailer.make_path(test_data.logs_dir, log)
try: try:
results = [] results = []
log = codecs.open(logs_path, "r", "utf_8") log = codecs.open(logs_path, "r", "utf_8")
@ -1665,7 +1696,7 @@ def search_log_set(type, string, test_data):
Returns: Returns:
a listof_String, the lines on which the String was found. a listof_String, the lines on which the String was found.
""" """
logs_path = Emailer.make_local_path(test_config.output_dir, test_data.image_name, "logs") logs_path = test_data.logs_dir
results = [] results = []
for file in os.listdir(logs_path): for file in os.listdir(logs_path):
if type in file: if type in file:
@ -1734,7 +1765,7 @@ def get_exceptions(test_data):
a listof_String, the exceptions found in the logs. a listof_String, the exceptions found in the logs.
""" """
exceptions = [] exceptions = []
logs_path = Emailer.make_path(test_config.output_dir, test_data.image_name, "logs") logs_path = test_data.logs_dir
results = [] results = []
for file in os.listdir(logs_path): for file in os.listdir(logs_path):
if "autopsy.log" in file: if "autopsy.log" in file:
@ -1764,7 +1795,7 @@ def get_warnings(test_data):
def copy_logs(test_data): def copy_logs(test_data):
try: try:
log_dir = os.path.join("..", "..", "Testing","build","test","qa-functional","work","userdir0","var","log") log_dir = os.path.join("..", "..", "Testing","build","test","qa-functional","work","userdir0","var","log")
shutil.copytree(log_dir, Emailer.make_local_path(test_config.output_dir, test_data.image_name, "logs")) shutil.copytree(log_dir, test_data.logs_dir)
except Exception as e: except Exception as e:
printerror(test_data,"Error: Failed to copy the logs.") printerror(test_data,"Error: Failed to copy the logs.")
printerror(test_data,str(e) + "\n") printerror(test_data,str(e) + "\n")
@ -1941,7 +1972,6 @@ class TestRunner(object):
logres.append(TestRunner._run_test(test_data)) logres.append(TestRunner._run_test(test_data))
Reports.write_html_foot() Reports.write_html_foot()
html.close()
if (len(logres)>0): if (len(logres)>0):
failedbool = True failedbool = True
imgfail = True imgfail = True
@ -1949,12 +1979,13 @@ class TestRunner(object):
for lm in logres: for lm in logres:
for ln in lm: for ln in lm:
errorem += ln errorem += ln
html.close()
if failedbool: if failedbool:
passFail = False passFail = False
errorem += "The test output didn't match the gold standard.\n" errorem += "The test output didn't match the gold standard.\n"
errorem += "Autopsy test failed.\n" errorem += "Autopsy test failed.\n"
html = open(test_config.html_log)
attachl.insert(0, html.name) attachl.insert(0, html.name)
html.close()
else: else:
errorem += "Autopsy test passed.\n" errorem += "Autopsy test passed.\n"
passFail = True passFail = True
@ -2082,21 +2113,19 @@ class TestRunner(object):
gold_dir = test_config.img_gold gold_dir = test_config.img_gold
clear_dir(test_config.img_gold) clear_dir(test_config.img_gold)
tmpdir = Emailer.make_path(gold_dir, test_data.image_name) tmpdir = Emailer.make_path(gold_dir, test_data.image_name)
dbinpth = Emailer.make_path(test_config.output_dir, test_data.image_name, AUTOPSY_TEST_CASE, DB_FILENAME) dbinpth = test_data.get_db_path(DBType.OUTPUT)
dboutpth = Emailer.make_path(tmpdir, DB_FILENAME) dboutpth = Emailer.make_path(tmpdir, DB_FILENAME)
dataoutpth = Emailer.make_path(tmpdir, test_data.image_name + "SortedData.txt") dataoutpth = Emailer.make_path(tmpdir, test_data.image_name + "SortedData.txt")
dbdumpinpth = test_data.test_dbdump dbdumpinpth = test_data.get_db_dump_path(DBType.OUTPUT)
dbdumpoutpth = Emailer.make_path(tmpdir, test_data.image_name + "DBDump.txt") dbdumpoutpth = Emailer.make_path(tmpdir, test_data.image_name + "DBDump.txt")
if not os.path.exists(test_config.img_gold): if not os.path.exists(test_config.img_gold):
os.makedirs(test_config.img_gold) os.makedirs(test_config.img_gold)
if not os.path.exists(gold_dir):
os.makedirs(gold_dir)
if not os.path.exists(tmpdir): if not os.path.exists(tmpdir):
os.makedirs(tmpdir) os.makedirs(tmpdir)
try: try:
copy_file(dbinpth, dboutpth) copy_file(dbinpth, dboutpth)
if Emailer.file_exists(test_data.get_sorted_data_path(DBType.OUTPUT)): if Emailer.file_exists(test_data.get_sorted_data_path(DBType.OUTPUT)):
copy_file(test_data.get_sorted_data_path(DBType.OUTPUT, dataoutpth)) copy_file(test_data.get_sorted_data_path(DBType.OUTPUT), dataoutpth)
copy_file(dbdumpinpth, dbdumpoutpth) copy_file(dbdumpinpth, dbdumpoutpth)
error_pth = Emailer.make_path(tmpdir, test_data.image_name+"SortedErrors.txt") error_pth = Emailer.make_path(tmpdir, test_data.image_name+"SortedErrors.txt")
copy_file(test_data.sorted_log, error_pth) copy_file(test_data.sorted_log, error_pth)
@ -2105,22 +2134,13 @@ class TestRunner(object):
print(str(e)) print(str(e))
print(traceback.format_exc()) print(traceback.format_exc())
# Rebuild the HTML report # Rebuild the HTML report
htmlfolder = "" output_html_report_dir = test_data.get_html_report_path(DBType.OUTPUT)
for fs in os.listdir(os.path.join(os.getcwd(),test_config.output_dir, test_data.image_name, AUTOPSY_TEST_CASE, "Reports")): gold_html_report_dir = Emailer.make_path(tmpdir, "Report")
if os.path.isdir(os.path.join(os.getcwd(), test_config.output_dir, test_data.image_name, AUTOPSY_TEST_CASE, "Reports", fs)):
htmlfolder = fs
autopsy_html_path = Emailer.make_local_path(test_config.output_dir, test_data.image_name, AUTOPSY_TEST_CASE, "Reports", htmlfolder)
html_path = Emailer.make_path(test_config.output_dir, test_data.image_name,
IMG_TEST_FOLDER, "Reports")
try: try:
if not os.path.exists(Emailer.make_path(tmpdir, htmlfolder)): copy_dir(output_html_report_dir, gold_html_report_dir)
os.makedirs(Emailer.make_path(tmpdir, htmlfolder))
for file in os.listdir(autopsy_html_path):
html_to = Emailer.make_path(tmpdir, file.replace("HTML Report", "Report"))
copy_dir(get_file_in_dir(autopsy_html_path, file), html_to)
except FileNotFoundException as e: except FileNotFoundException as e:
errors.append(e.error) errors.append(e.error())
except Exception as e: except Exception as e:
errors.append("Error: Unknown fatal error when rebuilding the gold html report.") errors.append("Error: Unknown fatal error when rebuilding the gold html report.")
errors.append(str(e) + "\n") errors.append(str(e) + "\n")