Commit 1f897452 authored by Jérome Perrin's avatar Jérome Perrin

BusinessTemplate: support coverage with erp5_coverage_plugin

When installing scripts or components from a business template, set
the _erp5_coverage_filename property so that the plugin is able to find
the corresponding code from the business template filesystem
representation.
parent 89f7285d
......@@ -77,12 +77,13 @@ from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
from OFS.Traversable import NotFound
from OFS import SimpleItem
from OFS.Image import Pdata
import coverage
from io import BytesIO
from copy import deepcopy
from zExceptions import BadRequest
from Products.ERP5Type.XMLExportImport import exportXML, customImporters
from Products.ERP5Type.Workflow import WorkflowHistoryList
from zLOG import LOG, WARNING, INFO
from zLOG import LOG, WARNING, INFO, PROBLEM
from warnings import warn
from lxml.etree import parse
from xml.sax.saxutils import escape
......@@ -97,6 +98,7 @@ import threading
from ZODB.broken import Broken, BrokenModified
from Products.ERP5.genbt5list import BusinessTemplateRevision, \
item_name_list, item_set
from Products.ERP5Type.mixin.component import ComponentMixin
CACHE_DATABASE_PATH = None
try:
......@@ -1165,7 +1167,16 @@ class ObjectTemplateItem(BaseTemplateItem):
`context` is the business template instance, in its acquisition context.
Can be overridden by subclasses.
"""
pass
if isinstance(obj, (PythonScript, ComponentMixin)) and coverage.Coverage.current():
relative_path = '/'.join(obj.getPhysicalPath()[len(context.getPortalObject().getPhysicalPath()):])
filename = os.path.join(
context.getPublicationUrl(),
self.__class__.__name__,
relative_path + '.py')
if os.path.exists(filename):
obj._erp5_coverage_filename = filename
else:
LOG('BusinessTemplate', PROBLEM, 'Could not find file for %s' % filename)
def onReplaceObject(self, obj, context):
"""
......
......@@ -36,6 +36,7 @@ import imp
import collections
from six import reraise
import coverage
from Products.ERP5Type.Utils import ensure_list
from Products.ERP5.ERP5Site import getSite
from Products.ERP5Type import product_path as ERP5Type_product_path
......@@ -333,6 +334,14 @@ class ComponentDynamicPackage(ModuleType):
# This must be set for imports at least (see PEP 302)
module.__file__ = '<' + relative_url + '>'
if coverage.Coverage.current():
if hasattr(component, '_erp5_coverage_filename'):
module.__file__ = component._erp5_coverage_filename
else:
LOG(
"ERP5Type.Tool.ComponentTool",
WARNING,
"No coverage filesystem mapping for %s" % (module_fullname_alias or module_fullname))
# Only useful for get_source(), do it before exec'ing the source code
# so that the source code is properly display in case of error
......
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