*base_module_quality:

* added a configuration file
	* added possiblity to define tests on installed module only or no
	* cleaned
	* improved

bzr revid: qdp@tinyerp.com-20081217171244-x8rnbx32yd2bj3v3
This commit is contained in:
qdp 2008-12-17 18:12:44 +01:00
parent 6232b371fe
commit 503a081c9d
5 changed files with 80 additions and 49 deletions

View File

@ -20,21 +20,38 @@
#
##############################################################################
import netsvc
from osv import fields, osv
class abstract_quality_check(object):
'''
This Class provide...
'''
_score = 0.0
_result = ""
_result_details = ""
#This float have to store the rating of the module.
#Used to compute the final score (average of all scores).
score = 0.0
def __init__(self, module_path=""):
#This char have to store the result.
#Used to display the result of the test.
result = ""
#This char have to store the result with more details.
#Used to provide more details if necessary.
result_details = ""
#This bool defines if the test can be run only if the module is installed.
#True => the module have to be installed.
#False => the module can be uninstalled.
bool_installed_only = True
def __init__(self):
'''
this method should do the test and fill the _score, _result and _result_details var
this method should initialize the var
'''
raise 'Not Implemented'
def run_test(self, module_path=""):
'''
this method should do the test and fill the score, result and result_details var
'''
raise 'Not Implemented'

View File

@ -20,8 +20,7 @@
#
##############################################################################
import netsvc
from osv import fields, osv
import os
from tools import config
@ -30,8 +29,8 @@ from base_module_quality import base_module_quality
class quality_test(base_module_quality.abstract_quality_check):
def __init__(self, module_path):
self._result = """
def __init__(self):
self.result = """
Pylint Test:
------------
@ -39,36 +38,41 @@ Pylint Test:
"""
self.bool_installed_only = False
return None
def run_test(self, module_path):
config_file_path = config['addons_path']+'/base_module_quality/pylint_test/pylint_test_config.txt'
list_files = os.listdir(module_path)
new_list = []
subfolder = {}
for i in list_files:
path = os.path.join(module_path, i)
if os.path.isdir(path):
for j in os.listdir(path):
list_files.append(os.path.join(i, j))
dict_files = {}
n =0
n = 0
score = 0.0
print list_files
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)
res = os.popen('pylint --rcfile='+config_file_path+' '+file_path).read()
res = os.popen('pylint --rcfile=' + config_file_path + ' ' + file_path).read()
n += 1
leftchar = -1
while res[leftchar:leftchar+1] != ' ' and leftchar-1 <= 0:
leftchar -=1
leftchar -= 1
rightchar = -10
while res[rightchar:rightchar+1] != '/' and rightchar+1 <= 0:
rightchar +=1
rightchar += 1
score += float(res[leftchar+1:rightchar])
self._result_details += res
self._result += file+": "+ res[leftchar+1:rightchar]+"/10\n"
self._score = score / n
try:
score += float(res[leftchar+1:rightchar])
self.result += file + ": " + res[leftchar+1:rightchar] + "/10\n"
except:
score += 0
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

View File

@ -56,8 +56,7 @@ load-plugins=
#enable-msg=
# Disable the message(s) with the given id(s).
#disable-msg=
disable-msg=C0103,F0401,E0611,R0903,W0232,W0102,E1002,R0913,R0904
[REPORTS]
@ -66,7 +65,7 @@ load-plugins=
output-format=text
# Include message's id in output
include-ids=no
include-ids=yes
# Put messages in a separate file for each module / package specified on the
# command line instead of printing them on stdout. Reports (if any) will be

View File

@ -30,8 +30,8 @@ from base_module_quality import base_module_quality
class quality_test(base_module_quality.abstract_quality_check):
def __init__(self, module_path):
self._result = """
def __init__(self):
self.result = """
Speed Test:
------------
@ -41,8 +41,11 @@ Speed Test:
to be continued...
"""
self.bool_installed_only = True
return None
def run_test(self, module_path):
return None
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -21,14 +21,20 @@
##############################################################################
import wizard
import pooler
import osv
import netsvc
import sys
import tools
import os
#TODO: (utiliser les nouveaux wizards pour heriter la vue et rajouter un onglet par test?)
#TODO: configure pylint
#TODO: implement the speed test
#TODO: implement the simple test
#TODO: add cheks: do the class quality_check inherits the class abstract_quality_check?
#TODO: improve translability
#To keep or not? to be discussed...
#~ form_check = '''<?xml version="1.0"?>
#~ <form string="Quality check">
#~ <field name="test" />
@ -50,47 +56,49 @@ view_form = """<?xml version="1.0"?>
</page>
</notebook>
</form>"""
#TODO: utiliser les nouveaux wizards pour heriter la vue et rajouter un onglet par test?
#TODO: remove the first screen which is unused
view_field = {
"general_info": {'type': 'text', 'string': 'General Info', 'readonly':True},
}
class wiz_quality_check(wizard.interface):
def _check(self, cr, uid, data, context):
def _check(self, cr, uid, data, context={}):
string_ret = ""
from tools import config
list_folders=os.listdir(config['addons_path']+'/base_module_quality/')
pool = pooler.get_pool(cr.dbname)
module_data = pool.get('ir.module.module').browse(cr, uid, data['ids'])
list_folders = os.listdir(config['addons_path']+'/base_module_quality/')
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']:
pool=pooler.get_pool(cr.dbname)
module_data = pool.get('ir.module.module').browse(cr, uid, data['ids'])
if os.path.exists(path+'/'+item+'.py') and item not in ['report', 'wizard', 'security']:
ad = tools.config['addons_path']
module_path = os.path.join(ad, module_data[0].name)
from base_module_quality import base_module_quality
item2='base_module_quality.'+item+'.'+item
item2 = 'base_module_quality.'+item+'.'+item
x = __import__(item2)
x2 = getattr(x,item)
x3 = getattr(x2,item)
val = x3.quality_test(str(module_path))
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(str(module_path))
else:
val.result += "The module has to be installed before running this test."
string_ret += val._result
string_ret += val.result
print val.result_details
return {'general_info':string_ret}
states = {
#To keep or not? to be discussed...
#~ 'init': {
#~ 'actions': [],
#~ 'result': {'type':'form', 'arch':form_check, 'fields':fields_check, 'state':[('end','Cancel'),('do','Do Test')]}