Commit e7b009a7 authored by Jérome Perrin's avatar Jérome Perrin

[TMP] Coding style check

temp changes in ERP5, backporting  changes for https://lab.nexedi.com/nexedi/capago/merge_requests/235

/reviewed-on https://lab.nexedi.com/nexedi/erp5-capago/merge_requests/1
parents e14b1ba0 28893194
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ActionInformation" module="Products.CMFCore.ActionInformation"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/object_report</string>
</tuple>
</value>
</item>
<item>
<key> <string>category</string> </key>
<value> <string>object_report</string> </value>
</item>
<item>
<key> <string>condition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>icon</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>check_python_code</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
<value>
<tuple>
<string>Manage portal</string>
</tuple>
</value>
</item>
<item>
<key> <string>priority</string> </key>
<value> <float>12.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Check Python Code</string> </value>
</item>
<item>
<key> <string>visible</string> </key>
<value> <int>1</int> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Expression" module="Products.CMFCore.Expression"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:${object_url}/BusinessTemplate_viewCheckPythonCodeDialog</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -171,7 +171,7 @@ def checkConversionToolAvailability(self): ...@@ -171,7 +171,7 @@ def checkConversionToolAvailability(self):
from Products.ERP5Type.Utils import checkPythonSourceCode from Products.ERP5Type.Utils import checkPythonSourceCode
def checkPythonSourceCodeAsJSON(self, data): def checkPythonSourceCodeAsJSON(self, data, REQUEST=None):
""" """
Check Python source suitable for Ace Editor and return a JSON object Check Python source suitable for Ace Editor and return a JSON object
""" """
...@@ -212,7 +212,8 @@ def checkPythonSourceCodeAsJSON(self, data): ...@@ -212,7 +212,8 @@ def checkPythonSourceCodeAsJSON(self, data):
else: else:
message_dict['type'] = 'warning' message_dict['type'] = 'warning'
self.REQUEST.RESPONSE.setHeader('content-type', 'application/json') if REQUEST is not None:
REQUEST.RESPONSE.setHeader('content-type', 'application/json')
return json.dumps(dict(annotations=message_list)) return json.dumps(dict(annotations=message_list))
def filterSecurityUidDict(security_uid_dict, referenced_security_uid_set): def filterSecurityUidDict(security_uid_dict, referenced_security_uid_set):
......
"""Return python source code in business template
"""
import json
class Message:
"""A python code linter message, with a link to edit the source code.
Supports both being displayed in a listbox and being printed.
"""
def __init__(self, location, message, edit_url):
self.location = location
self.message = message
self.edit_url = edit_url
def getListItemUrl(self, *args, **kw):
return self.edit_url
def __repr__(self):
return "{}:{}".format(self.location, self.message)
portal = context.getPortalObject()
line_list = []
def checkPythonScript(script_instance, script_path):
"""Check a python script, adding messages to global `line_list`
"""
# printed is from RestrictedPython.RestrictionMutator the rest comes from
# RestrictedPython.Utilities.utility_builtins
extra_builtins = ['printed', 'same_type', 'string', 'sequence', 'random',
'DateTime', 'whrandom', 'reorder', 'sets', 'test', 'math']
for annotation in json.loads(portal.ERP5Site_checkPythonSourceCodeAsJSON(
{'bound_names': extra_builtins +
script_instance.getBindingAssignments().getAssignedNamesInOrder(),
'params': script_instance.params(),
'code': unicode(script_instance.read(), 'utf8')
}))['annotations']:
annotation["script_path"] = script_path
line_list.append(
Message(
location="{script_path}:{row}:{column}".format(**annotation),
message=annotation['text'],
edit_url="{script_path}/manage_main?line={row}".format(**annotation),))
def checkComponent(component_instance):
"""Check a component, adding messages to global `line_list`
"""
for annotation in json.loads(portal.ERP5Site_checkPythonSourceCodeAsJSON(
{'code': unicode(component_instance.getTextContent(), 'utf8')}))['annotations']:
annotation['component_path'] = component_instance.getRelativeUrl()
line_list.append(
Message(
location="{component_path}:{row}:{column}".format(**annotation),
message=annotation["text"],
edit_url="{component_path}?line={row}".format(**annotation),))
# Check scripts
script_container_list = []
for skin_id in context.getTemplateSkinIdList():
script_container_list.append(portal.portal_skins[skin_id])
for workflow_id in context.getTemplateWorkflowIdList():
script_container_list.append(portal.portal_workflow[workflow_id])
for script_container in script_container_list:
for script_path, script_instance in portal.ZopeFind(
script_container,
obj_metatypes=['Script (Python)'],
search_sub=1):
checkPythonScript(script_instance, "%s/%s" % (
portal.portal_url.getRelativeUrl(script_container), script_path))
# Check components
for component_id in (
context.getTemplateExtensionIdList() +
context.getTemplateDocumentIdList() +
context.getTemplateTestIdList()):
checkComponent(portal.portal_components[component_id])
return line_list
...@@ -50,11 +50,11 @@ ...@@ -50,11 +50,11 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string>*args, **kw</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>ERP5Site_checkPythonScriptsWithPyflakes</string> </value> <value> <string>BusinessTemplate_getPythonSourceCodeMessageList</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ERP5 Form" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>action</string> </key>
<value> <string>BusinessTemplate_viewCheckPythonCodeDialog</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>edit_order</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>enctype</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>group_list</string> </key>
<value>
<list>
<string>left</string>
<string>right</string>
<string>center</string>
<string>bottom</string>
<string>hidden</string>
</list>
</value>
</item>
<item>
<key> <string>groups</string> </key>
<value>
<dictionary>
<item>
<key> <string>bottom</string> </key>
<value>
<list>
<string>listbox</string>
</list>
</value>
</item>
<item>
<key> <string>center</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>hidden</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>left</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>right</string> </key>
<value>
<list/>
</value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>BusinessTemplate_viewCheckPythonCodeDialog</string> </value>
</item>
<item>
<key> <string>method</string> </key>
<value> <string>POST</string> </value>
</item>
<item>
<key> <string>name</string> </key>
<value> <string>BusinessTemplate_viewCheckPythonCodeDialog</string> </value>
</item>
<item>
<key> <string>pt</string> </key>
<value> <string>form_dialog</string> </value>
</item>
<item>
<key> <string>row_length</string> </key>
<value> <int>4</int> </value>
</item>
<item>
<key> <string>stored_encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Check Python Code</string> </value>
</item>
<item>
<key> <string>unicode_mode</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>update_action</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>update_action_title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
"""Runs pyflakes on all python scripts.
TODO / BUGS:
* there is an offset in the line numbers in the reports
* script containing only a comment cannot be parsed
* integrate this directly in python script ZMI
* wouldn't it be better to use this on a business template to check scripts
from the business template ?
"""
pyflakes = context.ERP5Site_runPyflakes
def indent(text):
return ''.join((" " + line) for line in text.splitlines(True))
def make_body(script):
"""rewrite a python script as if it was a python function with all
bound names in the signature.
"""
bound_names = script.getBindingAssignments().getAssignedNamesInOrder()
# printed is from RestrictedPython.RestrictionMutator the rest comes from
# RestrictedPython.Utilities.utility_builtins
extra_builtins= ['printed', 'same_type', 'string', 'sequence', 'random',
'DateTime', 'whrandom', 'reorder', 'sets', 'test', 'math']
params = script.params()
signature_parts = bound_names + extra_builtins
if params:
signature_parts += [params]
signature = ", ".join(signature_parts)
function_name = script.getId().replace(".", "__dot__").replace(" ", "__space__")
body = "def %s(%s):\n%s" % (function_name, signature, indent(script.body()) or " pass")
return body
for script_container in (context.portal_skins, context.portal_workflow):
for script_path, script in context.ZopeFind(script_container, obj_metatypes=['Script (Python)'], search_sub=1):
err = pyflakes(make_body(script), '%s/%s' % (script_container.getId(), script_path))
if err:
print err,
return printed
Business Template | check_python_code
Missing Category Document Constraint | predicate Missing Category Document Constraint | predicate
Missing Category Document Constraint | view Missing Category Document Constraint | view
portal_actions | consistency portal_actions | consistency
......
...@@ -9,13 +9,17 @@ ...@@ -9,13 +9,17 @@
<script src="renderjs.js" type="text/javascript"></script> <script src="renderjs.js" type="text/javascript"></script>
<script src="rsvp.js" type="text/javascript"></script> <script src="rsvp.js" type="text/javascript"></script>
--> -->
<!--
FIXME: Including jQuery twice cause the jsplumb to be loaded twice.
For now we assume that it has already been loaded at this point.
<script src="../lib/jquery.js" type="text/javascript"></script> <script src="../lib/jquery.js" type="text/javascript"></script>
-->
<script src="../lib/jquery-ui.js" type="text/javascript"></script> <script src="../lib/jquery-ui.js" type="text/javascript"></script>
<script src="../lib/jquery.jsplumb.js" type="text/javascript"></script> <script src="../lib/jquery.jsplumb.js" type="text/javascript"></script>
<script src="../lib/handlebars.min.js" type="text/javascript"></script> <script src="../lib/handlebars.min.js" type="text/javascript"></script>
<script src="../lib/springy.js" type="text/javascript"></script>
<script src="../dream/mixin_promise.js" type="text/javascript"></script> <script src="../dream/mixin_promise.js" type="text/javascript"></script>
<script src="springy.js" type="text/javascript"></script>
<script src="jsplumb.js" type="text/javascript"></script> <script src="jsplumb.js" type="text/javascript"></script>
<script id="node-template" type="text/x-handlebars-template"> <script id="node-template" type="text/x-handlebars-template">
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
<body> <body>
<div id="qunit"></div> <div id="qunit"></div>
<div id="qunit-fixture"></div> <div id="qunit-fixture">
<div id="test-element"/>
</div>
</body> </body>
</html> </html>
...@@ -14,16 +14,16 @@ ...@@ -14,16 +14,16 @@
}).declareMethod("render", function(options) { }).declareMethod("render", function(options) {
var select = this.element.getElementsByTagName("select")[0], i, template, tmp = ""; var select = this.element.getElementsByTagName("select")[0], i, template, tmp = "";
select.setAttribute("name", options.key); select.setAttribute("name", options.key);
for (i = 0; i < options.property_definition.enum.length; i += 1) { for (i = 0; i < options.property_definition['enum'].length; i += 1) {
if (options.property_definition.enum[i] === options.value) { if (options.property_definition['enum'][i] === options.value) {
template = selected_option_template; template = selected_option_template;
} else { } else {
template = option_template; template = option_template;
} }
// XXX value and text are always same in json schema // XXX value and text are always same in json schema
tmp += template({ tmp += template({
value: options.property_definition.enum[i], value: options.property_definition['enum'][i],
text: options.property_definition.enum[i] text: options.property_definition['enum'][i]
}); });
} }
select.innerHTML += tmp; select.innerHTML += tmp;
......
erp5_trade
\ No newline at end of file
...@@ -2,21 +2,19 @@ ...@@ -2,21 +2,19 @@
<ZopeData> <ZopeData>
<record id="1" aka="AAAAAAAAAAE="> <record id="1" aka="AAAAAAAAAAE=">
<pickle> <pickle>
<global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/> <global name="Zuite" module="Products.Zelenium.zuite"/>
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
<item> <item>
<key> <string>_function</string> </key> <key> <string>_objects</string> </key>
<value> <string>runPyflakes</string> </value> <value>
</item> <tuple/>
<item> </value>
<key> <string>_module</string> </key>
<value> <string>ERP5Administration</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>ERP5Site_runPyflakes</string> </value> <value> <string>graph_editor_zuite</string> </value>
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>expand</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>testQunit</string> </value>
</item>
<item>
<key> <string>output_encoding</string> </key>
<value> <string>utf-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <unicode>Graph Editor Qunit Test</unicode> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<html>
<head><title>Graph Editor Qunit Test</title></head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="4">
Run existing qunit test in zelenium framework, to easily integrate it in current test suite.
</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td tal:content="string:${context/portal_url}/dream_graph_editor/jsplumb/test.html"></td>
<td></td>
</tr>
<tr>
<td>waitForTextPresent</td>
<td>Tests completed in </td>
<td>30000</td>
</tr>
<tr>
<td>assertText</td>
<td>css=#qunit-testresult span.failed</td>
<td>0</td>
</tr>
</tbody></table>
</body>
</html>
\ No newline at end of file
##############################################################################
#
# Copyright (c) 2017 Nexedi SA and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import unittest
from Products.ERP5Type.tests.ERP5TypeFunctionalTestCase import ERP5TypeFunctionalTestCase
class TestGraphEditor(ERP5TypeFunctionalTestCase):
run_only = "graph_editor_zuite"
def getBusinessTemplateList(self):
return (
'erp5_graph_editor',
'erp5_graph_editor_ui_test',
'erp5_ui_test_core',
)
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestGraphEditor))
return suite
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Test Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testFunctionalGraphEditor</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testFunctionalGraphEditor</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Test Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
</ZopeData>
erp5_graph_editor
erp5_ui_test_core
\ No newline at end of file
portal_tests/graph_editor_zuite
portal_tests/graph_editor_zuite/**
\ No newline at end of file
test.erp5.testFunctionalGraphEditor
\ No newline at end of file
erp5_full_text_mroonga_catalog
\ No newline at end of file
erp5_graph_editor_ui_test
\ No newline at end of file
...@@ -49,14 +49,41 @@ class TestXHTMLMixin(ERP5TypeTestCase): ...@@ -49,14 +49,41 @@ 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', 'dream_graph_editor/lib/handlebars.min.js',
'pdf_js/build/pdf.js', 'pdf_js/build/pdf.worker.js', 'dream_graph_editor/lib/jquery-ui.js',
'pdf_js/compatibility.js', 'pdf_js/debugger.js', 'dream_graph_editor/lib/jquery.js',
'pdf_js/viewer.js', 'pdf_js/l10n.js') 'dream_graph_editor/lib/jquery.jsplumb.js',
JSL_IGNORE_SKIN_LIST = ('erp5_ace_editor', 'erp5_code_mirror', 'dream_graph_editor/lib/jquery.simulate.js',
'erp5_fckeditor', 'erp5_jquery', 'erp5_jquery_ui', 'dream_graph_editor/lib/qunit.js',
'erp5_svg_editor', 'erp5_xinha_editor') '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',
)
def changeSkin(self, skin_name): def changeSkin(self, skin_name):
""" """
...@@ -181,6 +208,7 @@ class TestXHTMLMixin(ERP5TypeTestCase): ...@@ -181,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()
...@@ -189,7 +217,11 @@ class TestXHTMLMixin(ERP5TypeTestCase): ...@@ -189,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',
...@@ -429,6 +461,7 @@ class TestXHTML(TestXHTMLMixin): ...@@ -429,6 +461,7 @@ class TestXHTML(TestXHTMLMixin):
'erp5_xinha_editor', 'erp5_xinha_editor',
'erp5_svg_editor', 'erp5_svg_editor',
'erp5_jquery_sheet_editor', 'erp5_jquery_sheet_editor',
'erp5_graph_editor',
'erp5_web_ung_core', 'erp5_web_ung_core',
'erp5_web_ung_theme', 'erp5_web_ung_theme',
'erp5_web_ung_role', 'erp5_web_ung_role',
......
...@@ -79,6 +79,7 @@ def getSkinPrefixList(self): ...@@ -79,6 +79,7 @@ def getSkinPrefixList(self):
'NotificationTool', 'NotificationTool',
'ERP5Site', 'ERP5Site',
'ERP5Type', 'ERP5Type',
'Zuite',
'Form', # Acceptable for ERP5 Forms which will soon become portal types too 'Form', # Acceptable for ERP5 Forms which will soon become portal types too
)) ))
......
...@@ -434,40 +434,6 @@ def checkPythonSourceCode(source_code_str): ...@@ -434,40 +434,6 @@ def checkPythonSourceCode(source_code_str):
if not source_code_str: if not source_code_str:
return [] return []
try:
compile(source_code_str, '<string>', 'exec')
except Exception, error:
if isinstance(error, SyntaxError):
message = {'type': 'F',
'row': error.lineno,
'column': error.offset,
'text': error.message}
else:
message = {'type': 'F',
'row': -1,
'column': -1,
'text': str(error)}
return [message]
import pyflakes.reporter
import pyflakes.api
message_list = []
class ERP5FlakesReporter(pyflakes.reporter.Reporter):
__init__ = unexpectedError = syntaxError = lambda *args, **kw: None # errors are handled by compile
def flake(self, message):
message_list.append(
{'type': 'W',
'row': message.lineno,
'column': message.col,
'text': message.message % message.message_args })
pyflakes.api.check(source_code_str, '<string>', ERP5FlakesReporter())
return message_list
# XXX pylint disabled because it is slow
try: try:
from pylint.lint import Run from pylint.lint import Run
from pylint.reporters.text import TextReporter from pylint.reporters.text import TextReporter
......
...@@ -32,18 +32,12 @@ from Testing import ZopeTestCase ...@@ -32,18 +32,12 @@ from Testing import ZopeTestCase
from Acquisition import aq_base from Acquisition import aq_base
class CodingStyleTestCase(ERP5TypeTestCase): class CodingStyleTestCase(ERP5TypeTestCase):
"""XXX """Test case to test coding style in business templates.
"""
manager_username = 'zope'
manager_password = 'zope'
website_id = 'test'
def getTitle(self): Subclasses must override:
""" * getBusinessTemplateList to list business template to install.
Override this method in implementation class. * getTestedBusinessTemplateList to list business templates to test.
""" """
raise NotImplementedError
def getBusinessTemplateList(self): def getBusinessTemplateList(self):
""" """
Return the list of required business templates. Return the list of required business templates.
...@@ -61,12 +55,7 @@ class CodingStyleTestCase(ERP5TypeTestCase): ...@@ -61,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):
""" """
...@@ -75,22 +64,36 @@ class CodingStyleTestCase(ERP5TypeTestCase): ...@@ -75,22 +64,36 @@ 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())
# Return results self.assertEqual([], message_list)
if len(message_list):
raise self.failureException('\n'.join(map(lambda x: repr(x), message_list))) def test_PythonSourceCode(self):
"""test python script from the tested business templates.
reuses BusinessTemplate_getPythonSourceCodeMessageList from erp5_administration
"""
if 'erp5_administration' not in self.getBusinessTemplateList():
self.skipTest('erp5_administration needs be installed to check python source code')
self.maxDiff = None
for business_template in self.portal.portal_templates.contentValues():
if business_template.getTitle() in self.getTestedBusinessTemplateList():
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