changes on quality module

bzr revid: mra@tinyerp.com-20081229093600-9lc1o16njgguthr2
This commit is contained in:
mra (Open ERP) 2008-12-29 15:06:00 +05:30
parent 58113254ba
commit 272ffb10b5
5 changed files with 72 additions and 38 deletions

View File

@ -20,6 +20,8 @@
#
##############################################################################
import pooler
import os
from tools import config
class abstract_quality_check(object):
'''
@ -64,9 +66,20 @@ class abstract_quality_check(object):
#False => the module can be uninstalled.
self.bool_installed_only = True
self.tests = []
self.list_folders = os.listdir(config['addons_path']+'/base_module_quality/')
for item in self.list_folders:
self.item = item
path = config['addons_path']+'/base_module_quality/'+item
if os.path.exists(path+'/'+item+'.py') and item not in ['report', 'wizard', 'security']:
item2 = 'base_module_quality.' + item +'.' + item
x = __import__(item2)
x2 = getattr(x, item)
x3 = getattr(x2, item)
self.tests.append(x3)
# raise 'Not Implemented'
def run_test(self, cr, uid, module_path=""):
def run_test(self, cr, uid, module_path="", module_state=""):
'''
this method should do the test and fill the score, result and result_details var
'''
@ -99,22 +112,26 @@ class abstract_quality_check(object):
if test=='method':
detail = ""
detail += "\n===Method Test===\n"
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
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]
res_format['detail'] = detail + '\n|}'
elif test=='pylint':
res_format['summary'] = data_list[0]
res_format['detail'] = data_list[1]
elif test=='speed':
detail = ""
detail += "\n===Speed Test===\n"
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
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]
res_format['detail'] = detail + '\n|}\n'
return res_format

View File

@ -40,13 +40,14 @@ class quality_test(base_module_quality.abstract_quality_check):
self.bool_installed_only = True
return None
def run_test(self, cr, uid, module_path):
def run_test(self, cr, uid, module_path, module_state):
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
error = False
for obj in obj_list:
temp = []
try:
@ -77,12 +78,20 @@ class quality_test(base_module_quality.abstract_quality_check):
# 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.score = (ok_count + ex_count) and float(ok_count)/float(ok_count + ex_count) or 0.0
summary = """\n ===Method Test===:
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"
self.result = self.format_table(test='method', header=header_list, data_list=[summary,result])
else:
summary =""" \n===Method Test===:
The module has to be installed before running this test.\n\n """
header_list = ""
error = True
self.result = self.format_table(test='method', header=header_list, data_list=[summary,result,error])
return None

View File

@ -40,7 +40,7 @@ class quality_test(base_module_quality.abstract_quality_check):
self.bool_installed_only = False
return None
def run_test(self, cr, uid, module_path):
def run_test(self, cr, uid, module_path, module_state):
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:
@ -53,6 +53,7 @@ class quality_test(base_module_quality.abstract_quality_check):
score = 0.0
detail = ""
detail = "\n===Pylint Test===\n"
error = False
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)
@ -75,13 +76,20 @@ class quality_test(base_module_quality.abstract_quality_check):
detail += file + ": Unable to parse the result. Check the details.\n"
self.result_details += res
self.score = n and score / n or score
summary ="""
if not self.bool_installed_only or module_state=="installed":
summary ="""
===Pylint Test===:
This test checks if the module satisfy the current coding standard used by OpenERP.
This test checks if the module satisfy the current coding standard used by OpenERP.
""" + "Score: " + str(self.score) + "/10\n"
self.result = self.format_table(test='pylint', data_list=[summary,detail])
else:
summary =""" \n===Pylint Test===:
The module has to be installed before running this test.\n\n """
header_list = ""
error = True
self.result = self.format_table(test='pylint', data_list=[summary,detail,error])
return None

View File

@ -43,7 +43,7 @@ class quality_test(base_module_quality.abstract_quality_check):
#"""
self.bool_installed_only = True
return None
def run_test(self, cr, uid, module_path):
def run_test(self, cr, uid, module_path, module_state):
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))
@ -54,6 +54,7 @@ class quality_test(base_module_quality.abstract_quality_check):
obj_ids = self.get_ids(cr, uid, obj_list)
detail = ""
list1 = []
error = False
for obj in obj_ids:
obj_counter += 1
ids = obj_ids[obj]
@ -96,13 +97,20 @@ class quality_test(base_module_quality.abstract_quality_check):
list1.append(list)
# self.result += '\n|}\n'
self.score = obj_counter and score/obj_counter or 0.0
summary = """
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"
self.result = self.format_table(test='speed', header=header_list, data_list=[summary,list1])
else:
summary =""" \n===Speed Test===:
The module has to be installed before running this test.\n\n """
header_list = ""
error = True
self.result = self.format_table(test='speed', header=header_list, data_list=[summary,list1, error])
return None
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -26,7 +26,7 @@ from osv import osv, fields
import tools
import os
from base_module_quality import base_module_quality
#TODO: (utiliser les nouveaux wizards pour heriter la vue et rajouter un onglet par test?)
#TODO: implement the speed test
#TODO: add cheks: do the class quality_check inherits the class abstract_quality_check?
@ -65,24 +65,16 @@ class wiz_quality_check(osv.osv_memory):
module_data = pool.get('ir.module.module').browse(cr, uid, [data['ids']])
list_folders = os.listdir(config['addons_path']+'/base_module_quality/')
module_name = module_data[0].name
for item in list_folders:
path = config['addons_path']+'/base_module_quality/'+item
if os.path.exists(path+'/'+item+'.py') and item not in ['report', 'wizard', 'security']:
ad = tools.config['addons_path']
if module_data[0].name == 'base':
ad = tools.config['root_path']+'/addons'
module_path = os.path.join(ad, module_data[0].name)
item2 = 'base_module_quality.' + item +'.' + item
x = __import__(item2)
x2 = getattr(x, item)
x3 = getattr(x2, item)
val = x3.quality_test()
if (not val.bool_installed_only or module_data[0].state == "installed"):
val.run_test(cr, uid, str(module_path))
else:
val.result += "The module has to be installed before running this test."
string_ret += val.result['summary']
string_detail += val.result['detail']
abstract_obj = base_module_quality.abstract_quality_check()
for test in abstract_obj.tests:
ad = tools.config['addons_path']
if module_data[0].name == 'base':
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']
string_detail += val.result['detail']
self.string_detail = string_detail
return string_ret