Skip to content

Commit

Permalink
Merge pull request #110 from plone/109-improved-warnings
Browse files Browse the repository at this point in the history
Improve debugging
  • Loading branch information
jensens authored Sep 3, 2019
2 parents 903795b + 91407dd commit 04f9f70
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions news/109.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The debug messages issued when a non existent behavior is recorded in an FTI have been improved [ale-rt]
9 changes: 5 additions & 4 deletions plone/dexterity/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,20 @@ def behavior_registrations(self, fti):
if registration is None:
# BBB - this case should be deprecated in v 3.0
warnings.warn(
'No behavior registration found for behavior named: "{0}"'
'No behavior registration found for behavior named "{0}"'
' for factory "{1}"'
' - trying deprecated fallback lookup (will be removed '
'in 3.0)..."'.format(
behavior_name
behavior_name, fti.getId()
),
DeprecationWarning,
)
try:
schema_interface = resolve(behavior_name)
except (ValueError, ImportError):
log.error(
"Error resolving behavior {0}".format(
behavior_name
"Error resolving behavior {0} for factory {1}".format(
behavior_name, fti.getId()
)
)
continue
Expand Down
21 changes: 21 additions & 0 deletions plone/dexterity/tests/test_schema_cache.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# -*- coding: utf-8 -*-
from .case import MockTestCase
from mock import Mock
from mock import patch
from plone.dexterity.fti import DexterityFTI
from plone.dexterity.interfaces import IDexterityFTI
from plone.dexterity.schema import SCHEMA_CACHE
from zope.interface import Interface

import unittest
import warnings


class TestSchemaCache(MockTestCase):
Expand Down Expand Up @@ -57,6 +59,25 @@ class ITestBehavior(Interface):

self.assertTrue(r1[0] is r2[0] is registration)

def test_unexistent_behaviors_lookup(self):
fti = DexterityFTI(u"testtype")
self.mock_utility(fti, IDexterityFTI, name=u"testtype")
# Set an unregistered behavior
fti.behaviors = ["foo.bar"]

with patch("warnings.warn") as mock_warnings:
warning_list = [call[1][0] for call in mock_warnings.mock_calls]
SCHEMA_CACHE.behavior_registrations(u'testtype')
# Verify the warning has been issued
self.assertEqual(
mock_warnings.mock_calls[-1].args[0],
(
'No behavior registration found for behavior named '
'"foo.bar" for factory "testtype" - trying deprecated '
'fallback lookup (will be removed in 3.0)..."'
)
)

def test_repeated_subtypes_lookup(self):

fti = DexterityFTI(u"testtype")
Expand Down

0 comments on commit 04f9f70

Please sign in to comment.