Commit 3622731e authored by Jérome Perrin's avatar Jérome Perrin

Make coding style tests easier to integrate in projects

Various improvements to `CodingStyleTestCase` so that it can be used in a project test suite.

/reviewed-on nexedi/erp5!455
parents 9c516160 4699e91c
...@@ -49,11 +49,7 @@ class TestXHTMLMixin(ERP5TypeTestCase): ...@@ -49,11 +49,7 @@ class TestXHTMLMixin(ERP5TypeTestCase):
# some forms have intentionally empty listbox selections like RSS generators # some forms have intentionally empty listbox selections like RSS generators
FORM_LISTBOX_EMPTY_SELECTION_PATH_LIST = ['erp5_web_widget_library/WebSection_viewContentListAsRSS'] FORM_LISTBOX_EMPTY_SELECTION_PATH_LIST = ['erp5_web_widget_library/WebSection_viewContentListAsRSS']
JSL_IGNORE_FILE_LIST = ('require.js','require.min.js','wz_dragdrop.js', JSL_IGNORE_FILE_LIST = (
'renderjs.js','jio.js','rsvp.js','handlebars.js',
'pdf_js/build/pdf.js', 'pdf_js/build/pdf.worker.js',
'pdf_js/compatibility.js', 'pdf_js/debugger.js',
'pdf_js/viewer.js', 'pdf_js/l10n.js',
'dream_graph_editor/lib/handlebars.min.js', 'dream_graph_editor/lib/handlebars.min.js',
'dream_graph_editor/lib/jquery-ui.js', 'dream_graph_editor/lib/jquery-ui.js',
'dream_graph_editor/lib/jquery.js', 'dream_graph_editor/lib/jquery.js',
...@@ -61,10 +57,33 @@ class TestXHTMLMixin(ERP5TypeTestCase): ...@@ -61,10 +57,33 @@ class TestXHTMLMixin(ERP5TypeTestCase):
'dream_graph_editor/lib/jquery.simulate.js', 'dream_graph_editor/lib/jquery.simulate.js',
'dream_graph_editor/lib/qunit.js', 'dream_graph_editor/lib/qunit.js',
'dream_graph_editor/lib/springy.js', 'dream_graph_editor/lib/springy.js',
'handlebars.js',
'jio.js',
'jslint.js',
'pdf_js/build/pdf.js',
'pdf_js/build/pdf.worker.js',
'pdf_js/compatibility.js',
'pdf_js/debugger.js',
'pdf_js/l10n.js',
'pdf_js/viewer.js',
'renderjs.js',
'require.js',
'require.min.js',
'rsvp.js',
'wz_dragdrop.js',
)
JSL_IGNORE_SKIN_LIST = (
'erp5_ace_editor',
'erp5_code_mirror',
'erp5_fckeditor',
'erp5_jquery',
'erp5_jquery_ui',
'erp5_pivot_table',
'erp5_sql_browser',
'erp5_dhtmlx_scheduler',
'erp5_svg_editor',
'erp5_xinha_editor',
) )
JSL_IGNORE_SKIN_LIST = ('erp5_ace_editor', 'erp5_code_mirror',
'erp5_fckeditor', 'erp5_jquery', 'erp5_jquery_ui',
'erp5_svg_editor', 'erp5_xinha_editor')
def changeSkin(self, skin_name): def changeSkin(self, skin_name):
""" """
...@@ -189,6 +208,7 @@ class TestXHTMLMixin(ERP5TypeTestCase): ...@@ -189,6 +208,7 @@ class TestXHTMLMixin(ERP5TypeTestCase):
portal_skins_path = self.portal.getId() + '/portal_skins/' portal_skins_path = self.portal.getId() + '/portal_skins/'
args = ('jsl', '-stdin', '-nologo', '-nosummary', '-conf', args = ('jsl', '-stdin', '-nologo', '-nosummary', '-conf',
os.path.join(os.path.dirname(__file__), 'jsl.conf')) os.path.join(os.path.dirname(__file__), 'jsl.conf'))
error_list = []
for path in path_list: for path in path_list:
check_path = portal_skins_path + path check_path = portal_skins_path + path
body = self.publish(check_path).getBody() body = self.publish(check_path).getBody()
...@@ -197,7 +217,11 @@ class TestXHTMLMixin(ERP5TypeTestCase): ...@@ -197,7 +217,11 @@ class TestXHTMLMixin(ERP5TypeTestCase):
close_fds=True).communicate(body) close_fds=True).communicate(body)
except OSError, e: except OSError, e:
raise OSError, '%r\n%r' % (os.environ, e) raise OSError, '%r\n%r' % (os.environ, e)
self.assertEqual(stdout, '', 'jsl result of %s : %s' % (check_path, stdout)) if stdout:
error_list.append((check_path, stdout))
if error_list:
message = '\n'.join(["%s\n%s\n" % error for error in error_list])
self.fail(message)
def test_html_file(self): def test_html_file(self):
path_list = os.environ.get('CGI_PATH', path_list = os.environ.get('CGI_PATH',
......
...@@ -38,10 +38,6 @@ class CodingStyleTestCase(ERP5TypeTestCase): ...@@ -38,10 +38,6 @@ class CodingStyleTestCase(ERP5TypeTestCase):
* getBusinessTemplateList to list business template to install. * getBusinessTemplateList to list business template to install.
* getTestedBusinessTemplateList to list business templates to test. * getTestedBusinessTemplateList to list business templates to test.
""" """
manager_username = 'zope'
manager_password = 'zope'
website_id = 'test'
def getBusinessTemplateList(self): def getBusinessTemplateList(self):
""" """
Return the list of required business templates. Return the list of required business templates.
...@@ -59,12 +55,7 @@ class CodingStyleTestCase(ERP5TypeTestCase): ...@@ -59,12 +55,7 @@ class CodingStyleTestCase(ERP5TypeTestCase):
return self.getBusinessTemplateList()[-1:] return self.getBusinessTemplateList()[-1:]
def afterSetUp(self): def afterSetUp(self):
portal = self.portal self.login()
uf = portal.acl_users
uf._doAddUser(self.manager_username, self.manager_password, ['Manager'], [])
self.loginByUserName(self.manager_username)
def test_SkinCodingStyle(self): def test_SkinCodingStyle(self):
""" """
...@@ -73,25 +64,25 @@ class CodingStyleTestCase(ERP5TypeTestCase): ...@@ -73,25 +64,25 @@ class CodingStyleTestCase(ERP5TypeTestCase):
""" """
# Find the list if skins to test - we only test the last business template # Find the list if skins to test - we only test the last business template
portal_templates = self.portal.portal_templates portal_templates = self.portal.portal_templates
skin_id_list = [] skin_id_set = set()
for business_template in portal_templates.contentValues(): for business_template in portal_templates.contentValues():
if business_template.getTitle() in self.getTestedBusinessTemplateList(): if business_template.getTitle() in self.getTestedBusinessTemplateList():
skin_id_list.extend(business_template.getTemplateSkinIdList()) skin_id_set.update(business_template.getTemplateSkinIdList())
# Init message list # Init message list
message_list = [] message_list = []
# Test skins # Test skins
portal_skins = self.portal.portal_skins portal_skins = self.portal.portal_skins
for skin_id in skin_id_list: for skin_id in skin_id_set:
skin = portal_skins[skin_id] skin = portal_skins[skin_id]
for document in skin.objectValues(): for _, document in skin.ZopeFind(
skin,
obj_metatypes=(),
search_sub=True):
if getattr(aq_base(document), 'checkConsistency', None) is not None: if getattr(aq_base(document), 'checkConsistency', None) is not None:
message_list.extend(document.checkConsistency()) message_list.extend(document.checkConsistency())
self.assertEqual([], message_list)
# Return results
if len(message_list):
raise self.failureException('\n'.join(map(lambda x: repr(x), message_list)))
def test_PythonSourceCode(self): def test_PythonSourceCode(self):
"""test python script from the tested business templates. """test python script from the tested business templates.
...@@ -105,4 +96,3 @@ class CodingStyleTestCase(ERP5TypeTestCase): ...@@ -105,4 +96,3 @@ class CodingStyleTestCase(ERP5TypeTestCase):
for business_template in self.portal.portal_templates.contentValues(): for business_template in self.portal.portal_templates.contentValues():
if business_template.getTitle() in self.getTestedBusinessTemplateList(): if business_template.getTitle() in self.getTestedBusinessTemplateList():
self.assertEqual([], business_template.BusinessTemplate_getPythonSourceCodeMessageList()) self.assertEqual([], business_template.BusinessTemplate_getPythonSourceCodeMessageList())
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment