changes on quality module
bzr revid: mra@tinyerp.com-20090105124434-oll8rix427lv524l
This commit is contained in:
@@ -86,7 +86,7 @@ class abstract_quality_check(object):
|
||||
self.tests.append(x3)
|
||||
# raise 'Not Implemented'
|
||||
|
||||
def run_test(self, cr, uid, module_path="", module_state=""):
|
||||
def run_test(self, cr, uid, module_path=""):
|
||||
'''
|
||||
this method should do the test and fill the score, result and result_details var
|
||||
'''
|
||||
@@ -114,40 +114,22 @@ class abstract_quality_check(object):
|
||||
result_ids[obj] = ids
|
||||
return result_ids
|
||||
|
||||
def format_table(self, test='', header=[], data_list=[]):
|
||||
res_format = {}
|
||||
if test=='method':
|
||||
detail = ""
|
||||
detail += "\n===Method Test===\n"
|
||||
res_format['detail'] = detail
|
||||
if not data_list[2]:
|
||||
detail += ('{| border="1" cellspacing="0" cellpadding="5" align="left" \n! %-40s \n! %-16s \n! %-20s \n! %-16s ') % (header[0].ljust(40), header[1].ljust(16), header[2].ljust(20), header[3].ljust(16))
|
||||
for res in data_list[1]:
|
||||
detail += ('\n|-\n| %s \n| %s \n| %s \n| %s ') % (res, data_list[1][res][0], data_list[1][res][1], data_list[1][res][2])
|
||||
res_format['detail'] = detail + '\n|}'
|
||||
res_format['summary'] = data_list[0]
|
||||
elif test=='pylint':
|
||||
res_format['summary'] = data_list[0]
|
||||
res_format['detail'] = data_list[1]
|
||||
elif test=='speed':
|
||||
detail = ""
|
||||
detail += "\n===Speed Test===\n"
|
||||
res_format['detail'] = detail
|
||||
if not data_list[2]:
|
||||
detail += ('{| border="1" cellspacing="0" cellpadding="5" align="left" \n! %-40s \n! %-10s \n! %-10s \n! %-10s \n! %-10s \n! %-20s') % (header[0].ljust(40), header[1].ljust(10), header[2].ljust(10), header[3].ljust(10), header[4].ljust(10), header[5].ljust(20))
|
||||
for data in data_list[1]:
|
||||
detail += ('\n|-\n| %s \n| %s \n| %s \n| %s \n| %s \n| %s ') % (data[0], data[1], data[2], data[3], data[4], data[5])
|
||||
res_format['detail'] = detail + '\n|}\n'
|
||||
res_format['summary'] = data_list[0]
|
||||
elif test=='terp':
|
||||
res_format['summary'] = data_list[0]
|
||||
res_format['detail'] = data_list[1]
|
||||
return res_format
|
||||
def format_table(self, header=[], data_list=[]):
|
||||
detail = ""
|
||||
if header[0]=='method':
|
||||
detail += ('{| border="1" cellspacing="0" cellpadding="5" align="left" \n! %-40s \n! %-16s \n! %-20s \n! %-16s ') % (header[1].ljust(40), header[2].ljust(16), header[3].ljust(20), header[4].ljust(16))
|
||||
for res in data_list[0]:
|
||||
detail += ('\n|-\n| %s \n| %s \n| %s \n| %s ') % (res, data_list[0][res][0], data_list[0][res][1], data_list[0][res][2])
|
||||
detail = detail + '\n|}'
|
||||
elif header[0]=='speed':
|
||||
detail += ('{| border="1" cellspacing="0" cellpadding="5" align="left" \n! %-40s \n! %-10s \n! %-10s \n! %-10s \n! %-10s \n! %-20s') % (header[1].ljust(40), header[2].ljust(10), header[3].ljust(10), header[4].ljust(10), header[5].ljust(10), header[6].ljust(20))
|
||||
for data in data_list[0]:
|
||||
detail += ('\n|-\n| %s \n| %s \n| %s \n| %s \n| %s \n| %s ') % (data[0], data[1], data[2], data[3], data[4], data[5])
|
||||
detail = detail + '\n|}\n'
|
||||
return detail
|
||||
|
||||
def add_quatation(self, x, y):
|
||||
return x/y
|
||||
|
||||
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
||||
@@ -31,21 +31,15 @@ class quality_test(base_module_quality.abstract_quality_check):
|
||||
|
||||
def __init__(self):
|
||||
super(quality_test, self).__init__()
|
||||
# self.result = """
|
||||
#===Method Test===:
|
||||
#
|
||||
#This test checks if the module classes are raising exception when calling basic methods or no.
|
||||
#
|
||||
#"""
|
||||
self.bool_installed_only = True
|
||||
self.ponderation = 1.0
|
||||
self.result_det = {}
|
||||
return None
|
||||
|
||||
def run_test(self, cr, uid, module_path, module_state):
|
||||
def run_test(self, cr, uid, module_path):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
module_name = module_path.split('/')[-1]
|
||||
obj_list = self.get_objects(cr, uid, module_name)
|
||||
result = {}
|
||||
ok_count = 0
|
||||
ex_count = 0
|
||||
for obj in obj_list:
|
||||
@@ -71,29 +65,33 @@ class quality_test(base_module_quality.abstract_quality_check):
|
||||
except:
|
||||
temp.append('Exception')
|
||||
ex_count += 1
|
||||
result[obj] = temp
|
||||
# self.result += ('{| border="1" cellspacing="0" cellpadding="5" align="left" \n! %-40s \n! %-16s \n! %-20s \n! %-16s ') % ('Object Name'.ljust(40), 'search()'.ljust(16), 'fields_view_get()'.ljust(20), 'read()'.ljust(16))
|
||||
header_list = ['Object Name', 'search()', 'fields_view_get', 'read']
|
||||
# for res in result:
|
||||
# self.result += ('\n|-\n| %s \n| %s \n| %s \n| %s ') % (res, result[res][0],result[res][1], result[res][2])
|
||||
# self.result += '\n|}'
|
||||
self.result_det[obj] = temp
|
||||
self.score = (ok_count + ex_count) and float(ok_count)/float(ok_count + ex_count) or 0.0
|
||||
return None
|
||||
|
||||
def get_result(self, cr, uid, module_path, module_state):
|
||||
self.run_test(cr, uid, module_path)
|
||||
if not self.bool_installed_only or module_state=="installed":
|
||||
summary = """
|
||||
===Method Test===:
|
||||
|
||||
This test checks if the module classes are raising exception when calling basic methods or no.
|
||||
|
||||
""" #+ "Score: " + str(self.score) + "/10\n"
|
||||
""" + "Score: " + str(self.score) + "/10\n"
|
||||
else:
|
||||
summary =""" \n===Method Test===:
|
||||
|
||||
The module has to be installed before running this test.\n\n """
|
||||
header_list = ""
|
||||
self.error = True
|
||||
self.result = self.format_table(test='method', header=header_list, data_list=[summary,result,self.error])
|
||||
return None
|
||||
return summary
|
||||
|
||||
def get_result_detail(self):
|
||||
header_list = ['method', 'Object Name', 'search()', 'fields_view_get', 'read']
|
||||
detail = "\n===Method Test===\n"
|
||||
if not self.error:
|
||||
detail += self.format_table(header=header_list, data_list=[self.result_det])
|
||||
return detail
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
||||
@@ -31,17 +31,11 @@ class quality_test(base_module_quality.abstract_quality_check):
|
||||
|
||||
def __init__(self):
|
||||
super(quality_test, self).__init__()
|
||||
# self.result = """
|
||||
#===Pylint Test===:
|
||||
#
|
||||
# This test checks if the module satisfy the current coding standard used by OpenERP.
|
||||
#
|
||||
#"""
|
||||
self.bool_installed_only = False
|
||||
self.ponderation = 1.0
|
||||
return None
|
||||
|
||||
def run_test(self, cr, uid, module_path, module_state):
|
||||
def run_test(self, cr, uid, module_path):
|
||||
config_file_path = config['addons_path']+'/base_module_quality/pylint_test/pylint_test_config.txt'
|
||||
list_files = os.listdir(module_path)
|
||||
for i in list_files:
|
||||
@@ -52,8 +46,6 @@ class quality_test(base_module_quality.abstract_quality_check):
|
||||
|
||||
n = 0
|
||||
score = 0.0
|
||||
detail = ""
|
||||
detail = "\n===Pylint Test===\n"
|
||||
for file in list_files:
|
||||
if file.split('.')[-1] == 'py' and not file.endswith('__init__.py') and not file.endswith('__terp__.py'):
|
||||
file_path = os.path.join(module_path, file)
|
||||
@@ -68,30 +60,34 @@ class quality_test(base_module_quality.abstract_quality_check):
|
||||
|
||||
try:
|
||||
score += float(res[leftchar+1:rightchar])
|
||||
# self.result += file + ": " + res[leftchar+1:rightchar] + "/10\n"
|
||||
detail += file + ": " + res[leftchar+1:rightchar] + "/10\n"
|
||||
self.result += file + ": " + res[leftchar+1:rightchar] + "/10\n"
|
||||
except:
|
||||
score += 0
|
||||
# self.result += file + ": Unable to parse the result. Check the details.\n"
|
||||
detail += file + ": Unable to parse the result. Check the details.\n"
|
||||
self.result += file + ": Unable to parse the result. Check the details.\n"
|
||||
self.result_details += res
|
||||
self.score = n and score / n or score
|
||||
return None
|
||||
|
||||
def get_result(self, cr, uid, module_path, module_state):
|
||||
self.run_test(cr, uid, module_path)
|
||||
if not self.bool_installed_only or module_state=="installed":
|
||||
summary ="""
|
||||
===Pylint Test===:
|
||||
|
||||
This test checks if the module satisfies the current coding standard used by OpenERP.
|
||||
|
||||
""" #+ "Score: " + str(self.score) + "/10\n"
|
||||
""" + "Score: " + str(self.score) + "/10\n"
|
||||
else:
|
||||
summary =""" \n===Pylint Test===:
|
||||
|
||||
The module has to be installed before running this test.\n\n """
|
||||
header_list = ""
|
||||
self.error = True
|
||||
self.result = self.format_table(test='pylint', data_list=[summary,detail,self.error])
|
||||
return None
|
||||
return summary
|
||||
|
||||
def get_result_detail(self):
|
||||
detail = "\n===Pylint Test===\n" + self.result
|
||||
return detail
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
||||
@@ -35,26 +35,17 @@ class quality_test(base_module_quality.abstract_quality_check):
|
||||
|
||||
def __init__(self):
|
||||
super(quality_test, self).__init__()
|
||||
# self.result = """
|
||||
#===Speed Test===:
|
||||
#
|
||||
#This test checks the speed of the module.
|
||||
#
|
||||
#"""
|
||||
self.bool_installed_only = True
|
||||
self.ponderation = 1.0
|
||||
self.listdata = []
|
||||
return None
|
||||
def run_test(self, cr, uid, module_path, module_state):
|
||||
def run_test(self, cr, uid, module_path):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
module_name = module_path.split('/')[-1]
|
||||
# self.result+=('{| border="1" cellspacing="0" cellpadding="5" align="left" \n! %-40s \n! %-10s \n! %-10s \n! %-10s \n! %-10s \n! %-20s') % ('Object Name'.ljust(40), 'Size-Number of Records (S)'.ljust(10), '1'.ljust(10), 'S/2'.ljust(10), 'S'.ljust(10), 'Complexity using query'.ljust(20))
|
||||
header_list = ['Object Name', 'Size-Number of Records (S)', '1', 'S/2', 'S', 'Complexity using query']
|
||||
obj_list = self.get_objects(cr, uid, module_name)
|
||||
obj_counter = 0
|
||||
score = 0
|
||||
obj_ids = self.get_ids(cr, uid, obj_list)
|
||||
detail = ""
|
||||
list1 = []
|
||||
for obj in obj_ids:
|
||||
obj_counter += 1
|
||||
ids = obj_ids[obj]
|
||||
@@ -77,9 +68,8 @@ class quality_test(base_module_quality.abstract_quality_check):
|
||||
|
||||
if size < 5:
|
||||
self.score += -2
|
||||
# self.result += ('\n|-\n| %s \n| %s \n| %s \n| %s \n| %s \n| %s ') % (obj, size, code_base_complexity, code_half_complexity, code_size_complexity, "Warning! Not enough demo data")
|
||||
list = [obj, size, code_base_complexity, code_half_complexity, code_size_complexity, "Warning! Not enough demo data"]
|
||||
list1.append(list)
|
||||
self.listdata.append(list)
|
||||
else:
|
||||
if code_size_complexity <= (code_base_complexity + size):
|
||||
complexity = "O(1)"
|
||||
@@ -87,31 +77,39 @@ class quality_test(base_module_quality.abstract_quality_check):
|
||||
else:
|
||||
complexity = "O(n) or worst"
|
||||
score = 0
|
||||
# self.result += ('\n|-\n| %s \n| %s \n| %s \n| %s \n| %s \n| %s ') % (obj, size, code_base_complexity, code_half_complexity, code_size_complexity, complexity)
|
||||
list = [obj, size, code_base_complexity, code_half_complexity, code_size_complexity, complexity]
|
||||
list1.append(list)
|
||||
self.listdata.append(list)
|
||||
else:
|
||||
score += -5
|
||||
# self.result += ('\n|-\n| %s \n| %s \n| %s \n| %s \n| %s \n| %s ') % (obj, size, "", "", "", "Warning! Object has no demo data")
|
||||
list = [obj, size, "", "", "", "Warning! Object has no demo data"]
|
||||
list1.append(list)
|
||||
# self.result += '\n|}\n'
|
||||
self.listdata.append(list)
|
||||
self.score = obj_counter and score/obj_counter or 0.0
|
||||
return None
|
||||
|
||||
def get_result(self, cr, uid, module_path, module_state):
|
||||
self.run_test(cr, uid, module_path)
|
||||
if not self.bool_installed_only or module_state=="installed":
|
||||
summary = """
|
||||
===Speed Test===:
|
||||
|
||||
This test checks the speed of the module.
|
||||
|
||||
"""#+ "Score: " + str(self.score) + "/10\n"
|
||||
""" + "Score: " + str(self.score) + "/10\n"
|
||||
else:
|
||||
summary =""" \n===Speed Test===:
|
||||
|
||||
The module has to be installed before running this test.\n\n """
|
||||
header_list = ""
|
||||
self.error = True
|
||||
self.result = self.format_table(test='speed', header=header_list, data_list=[summary,list1,self.error])
|
||||
return None
|
||||
return summary
|
||||
|
||||
def get_result_detail(self):
|
||||
header_list = ['speed', 'Object Name', 'Size-Number of Records (S)', '1', 'S/2', 'S', 'Complexity using query']
|
||||
detail = ""
|
||||
detail += "\n===Speed Test===\n"
|
||||
if not self.error:
|
||||
detail += self.format_table(header=header_list, data_list=[self.listdata])
|
||||
return detail
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
||||
@@ -35,10 +35,10 @@ class quality_test(base_module_quality.abstract_quality_check):
|
||||
'''
|
||||
super(quality_test, self).__init__()
|
||||
self.bool_installed_only = True
|
||||
self.no_terp = False
|
||||
return None
|
||||
|
||||
def run_test(self, cr, uid, module_path, module_state):
|
||||
no_terp = False
|
||||
def run_test(self, cr, uid, module_path):
|
||||
list_files = os.listdir(module_path)
|
||||
for i in list_files:
|
||||
path = os.path.join(module_path, i)
|
||||
@@ -50,20 +50,8 @@ class quality_test(base_module_quality.abstract_quality_check):
|
||||
score = 0.0
|
||||
feel_good_factor = 0
|
||||
feel_bad_factor = 0
|
||||
detail = "\n===TERP Test===\n"
|
||||
summary = "\n===TERP Test===:\n"
|
||||
|
||||
if '__terp__.py' not in list_files:
|
||||
no_terp = True
|
||||
|
||||
if no_terp:
|
||||
summary += """
|
||||
The module does not contain the __terp__.py file.\n\n """
|
||||
header_list = ""
|
||||
self.error = True
|
||||
self.result = self.format_table(test='terp', data_list=[summary, detail, self.error])
|
||||
return None
|
||||
|
||||
self.no_terp = True
|
||||
terp_file = os.path.join(module_path,'__terp__.py')
|
||||
res = eval(tools.file_open(terp_file).read())
|
||||
|
||||
@@ -89,20 +77,25 @@ The module does not contain the __terp__.py file.\n\n """
|
||||
feel_bad_factor += 1
|
||||
|
||||
self.score = round((feel_good_factor * 10) / float(feel_good_factor + feel_bad_factor),2)
|
||||
# if not self.bool_installed_only or module_state=="installed":
|
||||
summary += """
|
||||
This test checks if the module satisfies the current coding standard for __terp__.py file used by OpenERP.
|
||||
|
||||
"""
|
||||
# else:
|
||||
# summary += """
|
||||
#The module has to be installed before running this test.\n\n """
|
||||
# header_list = ""
|
||||
# error = True
|
||||
|
||||
detail += "__terp__.py : "+ str(self.score) + "/10\n"
|
||||
self.result = self.format_table(test='terp', data_list=[summary, detail, self.error])
|
||||
self.result += "__terp__.py : "+ str(self.score) + "/10\n"
|
||||
return None
|
||||
|
||||
def get_result(self, cr, uid, module_path, module_state):
|
||||
self.run_test(cr, uid, module_path)
|
||||
summary = "\n===TERP Test===:\n"
|
||||
if self.no_terp:
|
||||
summary += """
|
||||
The module does not contain the __terp__.py file.\n\n """
|
||||
else:
|
||||
summary += """
|
||||
This test checks if the module satisfies the current coding standard for __terp__.py file used by OpenERP.
|
||||
""" + "Score: " + str(self.score) + "/10\n"
|
||||
return summary
|
||||
|
||||
def get_result_detail(self):
|
||||
detail = "\n===TERP Test===\n" + self.result
|
||||
return detail
|
||||
|
||||
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -75,11 +75,10 @@ class wiz_quality_check(osv.osv_memory):
|
||||
ad = tools.config['root_path']+'/addons'
|
||||
module_path = os.path.join(ad, module_data[0].name)
|
||||
val = test.quality_test()
|
||||
val.run_test(cr, uid, str(module_path), str(module_data[0].state))
|
||||
string_ret += val.result['summary'] #summary tab
|
||||
if not val.error:
|
||||
string_ret += "Score: " + str(val.score) + "/10\n" #val.score = val.score * val.ponderation ???
|
||||
string_detail += val.result['detail'] # detail tab
|
||||
string_ret += val.get_result(cr, uid, str(module_path), str(module_data[0].state)) #result['summary'] #summary tab
|
||||
string_detail += val.get_result_detail()#result['detail'] # detail tab
|
||||
# if not val.error:
|
||||
# string_ret += "Score: " + str(val.score) + "/10\n" #val.score = val.score * val.ponderation ???
|
||||
score_sum += (val.add_quatation(val.score, 10) * val.ponderation)
|
||||
ponderation_sum += val.ponderation
|
||||
final_score = str(score_sum / ponderation_sum * 100) + "%"
|
||||
|
||||
Reference in New Issue
Block a user