Commit cdde2d54 authored by Jérome Perrin's avatar Jérome Perrin Committed by Kazuhiko Shiozaki

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 d958e557
...@@ -77,12 +77,13 @@ from Products.ERP5Type.TransactionalVariable import getTransactionalVariable ...@@ -77,12 +77,13 @@ from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
from OFS.Traversable import NotFound from OFS.Traversable import NotFound
from OFS import SimpleItem from OFS import SimpleItem
from OFS.Image import Pdata from OFS.Image import Pdata
import coverage
from io import BytesIO from io import BytesIO
from copy import deepcopy from copy import deepcopy
from zExceptions import BadRequest from zExceptions import BadRequest
from Products.ERP5Type.XMLExportImport import exportXML, customImporters from Products.ERP5Type.XMLExportImport import exportXML, customImporters
from Products.ERP5Type.Workflow import WorkflowHistoryList from Products.ERP5Type.Workflow import WorkflowHistoryList
from zLOG import LOG, WARNING, INFO from zLOG import LOG, WARNING, INFO, PROBLEM
from warnings import warn from warnings import warn
from lxml.etree import parse from lxml.etree import parse
from xml.sax.saxutils import escape from xml.sax.saxutils import escape
...@@ -97,6 +98,7 @@ import threading ...@@ -97,6 +98,7 @@ import threading
from ZODB.broken import Broken, BrokenModified from ZODB.broken import Broken, BrokenModified
from Products.ERP5.genbt5list import BusinessTemplateRevision, \ from Products.ERP5.genbt5list import BusinessTemplateRevision, \
item_name_list, item_set item_name_list, item_set
from Products.ERP5Type.mixin.component import ComponentMixin
CACHE_DATABASE_PATH = None CACHE_DATABASE_PATH = None
try: try:
...@@ -1165,7 +1167,16 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -1165,7 +1167,16 @@ class ObjectTemplateItem(BaseTemplateItem):
`context` is the business template instance, in its acquisition context. `context` is the business template instance, in its acquisition context.
Can be overridden by subclasses. 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): def onReplaceObject(self, obj, context):
""" """
......
...@@ -36,6 +36,7 @@ import imp ...@@ -36,6 +36,7 @@ import imp
import collections import collections
from six import reraise from six import reraise
import coverage
from Products.ERP5Type.Utils import ensure_list from Products.ERP5Type.Utils import ensure_list
from Products.ERP5.ERP5Site import getSite from Products.ERP5.ERP5Site import getSite
from Products.ERP5Type import product_path as ERP5Type_product_path from Products.ERP5Type import product_path as ERP5Type_product_path
...@@ -333,6 +334,14 @@ class ComponentDynamicPackage(ModuleType): ...@@ -333,6 +334,14 @@ class ComponentDynamicPackage(ModuleType):
# This must be set for imports at least (see PEP 302) # This must be set for imports at least (see PEP 302)
module.__file__ = '<' + relative_url + '>' 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 # 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 # 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