Commit 6746229c authored by Arnaud Fontaine's avatar Arnaud Fontaine

ZODB Components: Components not actually loaded were never cleared of astroid AST module cache.

This fixes testDynamicClassGeneration failure since the migration of
IMovement (e8e5f273) which uncovered this issue.
parent 1d19758f
...@@ -147,11 +147,25 @@ class ComponentTool(BaseTool): ...@@ -147,11 +147,25 @@ class ComponentTool(BaseTool):
import erp5.component import erp5.component
from Products.ERP5Type.dynamic.component_package import ComponentDynamicPackage from Products.ERP5Type.dynamic.component_package import ComponentDynamicPackage
with aq_method_lock: with aq_method_lock:
component_package_list = []
for package in erp5.component.__dict__.itervalues(): for package in erp5.component.__dict__.itervalues():
if isinstance(package, ComponentDynamicPackage): if isinstance(package, ComponentDynamicPackage):
package.reset() package.reset()
component_package_list.append(package.__name__)
erp5.component.ref_manager.gc() erp5.component.ref_manager.gc()
# Clear pylint cache
try:
from astroid.builder import MANAGER
except ImportError:
pass
else:
astroid_cache = MANAGER.astroid_cache
for k in astroid_cache.keys():
if k.startswith('erp5.component.') and k not in component_package_list:
del astroid_cache[k]
if reset_portal_type_at_transaction_boundary: if reset_portal_type_at_transaction_boundary:
portal.portal_types.resetDynamicDocumentsOnceAtTransactionBoundary() portal.portal_types.resetDynamicDocumentsOnceAtTransactionBoundary()
else: else:
......
...@@ -429,14 +429,6 @@ class ComponentDynamicPackage(ModuleType): ...@@ -429,14 +429,6 @@ class ComponentDynamicPackage(ModuleType):
delattr(package, name) delattr(package, name)
# Clear pylint cache
try:
from astroid.builder import MANAGER
except ImportError:
pass
else:
MANAGER.astroid_cache.pop(module_name, None)
class ToolComponentDynamicPackage(ComponentDynamicPackage): class ToolComponentDynamicPackage(ComponentDynamicPackage):
def reset(self, *args, **kw): def reset(self, *args, **kw):
""" """
......
...@@ -2242,7 +2242,15 @@ from Shared.DC.ZRDB.Results import Results # pylint: disable=unused-import ...@@ -2242,7 +2242,15 @@ from Shared.DC.ZRDB.Results import Results # pylint: disable=unused-import
module2=imported_module2, module2=imported_module2,
module2_with_version=imported_module2_with_version)) + module2_with_version=imported_module2_with_version)) +
component.getTextContent()) component.getTextContent())
self.tic()
self._assertAstroidCacheContent(
must_be_in_cache_set={'%s' % namespace},
must_not_be_in_cache_set={'%s.erp5_version' % namespace,
imported_module1,
imported_module1_with_version,
imported_module2,
imported_module2_with_version})
component.checkSourceCode()
self._assertAstroidCacheContent( self._assertAstroidCacheContent(
must_be_in_cache_set={'%s' % namespace, must_be_in_cache_set={'%s' % namespace,
'%s.erp5_version' % namespace}, '%s.erp5_version' % namespace},
...@@ -2250,6 +2258,8 @@ from Shared.DC.ZRDB.Results import Results # pylint: disable=unused-import ...@@ -2250,6 +2258,8 @@ from Shared.DC.ZRDB.Results import Results # pylint: disable=unused-import
imported_module1_with_version, imported_module1_with_version,
imported_module2, imported_module2,
imported_module2_with_version}) imported_module2_with_version})
self.tic()
self.assertEqual(component.getValidationState(), 'modified') self.assertEqual(component.getValidationState(), 'modified')
self.assertEqual( self.assertEqual(
component.getTextContentErrorMessageList(), component.getTextContentErrorMessageList(),
...@@ -2288,9 +2298,8 @@ from Shared.DC.ZRDB.Results import Results # pylint: disable=unused-import ...@@ -2288,9 +2298,8 @@ from Shared.DC.ZRDB.Results import Results # pylint: disable=unused-import
self.assertEqual(imported_component1.getValidationState(), 'validated') self.assertEqual(imported_component1.getValidationState(), 'validated')
self.assertEqual(imported_component2.getValidationState(), 'validated') self.assertEqual(imported_component2.getValidationState(), 'validated')
# 2) Then modify the main one so that it automatically 'validate' message_list = component.checkSourceCode()
component.setTextContent(component.getTextContent() + '\n') self.assertEqual(message_list, [])
self.tic()
self._assertAstroidCacheContent( self._assertAstroidCacheContent(
must_be_in_cache_set={'%s' % namespace, must_be_in_cache_set={'%s' % namespace,
'%s.erp5_version' % namespace, '%s.erp5_version' % namespace,
...@@ -2299,6 +2308,17 @@ from Shared.DC.ZRDB.Results import Results # pylint: disable=unused-import ...@@ -2299,6 +2308,17 @@ from Shared.DC.ZRDB.Results import Results # pylint: disable=unused-import
imported_module2, imported_module2,
imported_module2_with_version}, imported_module2_with_version},
must_not_be_in_cache_set=set()) must_not_be_in_cache_set=set())
# 2) Then modify the main one so that it automatically 'validate'
component.setTextContent(component.getTextContent() + '\n')
self.tic()
self._assertAstroidCacheContent(
must_be_in_cache_set={'%s' % namespace},
must_not_be_in_cache_set={'%s.erp5_version' % namespace,
imported_module1,
imported_module1_with_version,
imported_module2,
imported_module2_with_version})
self.assertEqual(component.getValidationState(), 'validated') self.assertEqual(component.getValidationState(), 'validated')
self.assertEqual(component.getTextContentErrorMessageList(), []) self.assertEqual(component.getTextContentErrorMessageList(), [])
self.assertEqual(component.getTextContentWarningMessageList(), []) self.assertEqual(component.getTextContentWarningMessageList(), [])
...@@ -2363,12 +2383,8 @@ from %(namespace)s.erp5_version import %(reference)s ...@@ -2363,12 +2383,8 @@ from %(namespace)s.erp5_version import %(reference)s
%(reference)s.hoge() %(reference)s.hoge()
""" % dict(namespace=self._document_class._getDynamicModuleNamespace(), """ % dict(namespace=self._document_class._getDynamicModuleNamespace(),
reference=imported_reference)) reference=imported_reference))
self.portal.portal_workflow.doActionFor(component, 'validate_action')
self.tic()
self.assertEqual(component.getValidationState(), 'validated')
self.assertEqual(component.getTextContentErrorMessageList(), [])
self.assertEqual(component.getTextContentWarningMessageList(), [])
component.checkSourceCode()
from astroid.builder import MANAGER from astroid.builder import MANAGER
imported_module = self._getComponentFullModuleName(imported_reference) imported_module = self._getComponentFullModuleName(imported_reference)
self.assertEqual( self.assertEqual(
...@@ -2378,6 +2394,12 @@ from %(namespace)s.erp5_version import %(reference)s ...@@ -2378,6 +2394,12 @@ from %(namespace)s.erp5_version import %(reference)s
MANAGER.astroid_cache[self._getComponentFullModuleName(imported_reference, version='erp5')], MANAGER.astroid_cache[self._getComponentFullModuleName(imported_reference, version='erp5')],
MANAGER.astroid_cache[imported_module]) MANAGER.astroid_cache[imported_module])
self.portal.portal_workflow.doActionFor(component, 'validate_action')
self.tic()
self.assertEqual(component.getValidationState(), 'validated')
self.assertEqual(component.getTextContentErrorMessageList(), [])
self.assertEqual(component.getTextContentWarningMessageList(), [])
finally: finally:
self.portal.setVersionPriorityList(priority_tuple) self.portal.setVersionPriorityList(priority_tuple)
self.tic() self.tic()
......
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