summaryrefslogtreecommitdiff
path: root/addons/base_module_quality
diff options
context:
space:
mode:
authormra (Open ERP) <mra@tinyerp.com>2009-01-05 18:14:34 +0530
committermra (Open ERP) <mra@tinyerp.com>2009-01-05 18:14:34 +0530
commitb9e8786ef86b4ef89af84aab1a2a2c44d09826b9 (patch)
treee7ac6be766516f3a1ecd50514fff9469554efc15 /addons/base_module_quality
parent21f104a506545f869453c7aa9416ce40c49a1c00 (diff)
changes on quality module
bzr revid: mra@tinyerp.com-20090105124434-oll8rix427lv524l
Diffstat (limited to 'addons/base_module_quality')
-rw-r--r--addons/base_module_quality/base_module_quality.py46
-rw-r--r--addons/base_module_quality/method_test/method_test.py32
-rw-r--r--addons/base_module_quality/pylint_test/pylint_test.py28
-rw-r--r--addons/base_module_quality/speed_test/speed_test.py40
-rw-r--r--addons/base_module_quality/terp_test/terp_test.py47
-rw-r--r--addons/base_module_quality/wizard/module_quality_check.py9
6 files changed, 84 insertions, 118 deletions
diff --git a/addons/base_module_quality/base_module_quality.py b/addons/base_module_quality/base_module_quality.py
index 0564d7c9066..f8cf125cbc2 100644
--- a/addons/base_module_quality/base_module_quality.py
+++ b/addons/base_module_quality/base_module_quality.py
@@ -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:
diff --git a/addons/base_module_quality/method_test/method_test.py b/addons/base_module_quality/method_test/method_test.py
index 38a07c9428b..b07e7f349e1 100644
--- a/addons/base_module_quality/method_test/method_test.py
+++ b/addons/base_module_quality/method_test/method_test.py
@@ -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:
diff --git a/addons/base_module_quality/pylint_test/pylint_test.py b/addons/base_module_quality/pylint_test/pylint_test.py
index 5877dc6ff39..d81b70b2aa9 100644
--- a/addons/base_module_quality/pylint_test/pylint_test.py
+++ b/addons/base_module_quality/pylint_test/pylint_test.py
@@ -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:
diff --git a/addons/base_module_quality/speed_test/speed_test.py b/addons/base_module_quality/speed_test/speed_test.py
index d2ab88cbd14..45800e06356 100644
--- a/addons/base_module_quality/speed_test/speed_test.py
+++ b/addons/base_module_quality/speed_test/speed_test.py
@@ -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:
diff --git a/addons/base_module_quality/terp_test/terp_test.py b/addons/base_module_quality/terp_test/terp_test.py
index e3bbaa356ea..6f76656eae6 100644
--- a/addons/base_module_quality/terp_test/terp_test.py
+++ b/addons/base_module_quality/terp_test/terp_test.py
@@ -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.
+ 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
-"""
-# else:
-# summary += """
-#The module has to be installed before running this test.\n\n """
-# header_list = ""
-# error = True
+ def get_result_detail(self):
+ detail = "\n===TERP Test===\n" + self.result
+ return detail
- detail += "__terp__.py : "+ str(self.score) + "/10\n"
- self.result = self.format_table(test='terp', data_list=[summary, detail, self.error])
- return None
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file
diff --git a/addons/base_module_quality/wizard/module_quality_check.py b/addons/base_module_quality/wizard/module_quality_check.py
index 1da35f9f68a..155ad87061a 100644
--- a/addons/base_module_quality/wizard/module_quality_check.py
+++ b/addons/base_module_quality/wizard/module_quality_check.py
@@ -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) + "%"