Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport from grokcore.component 1.0.1:
* The grokkers for adapters and global utilities did not use the correct value for the *provided* interface in the configuration action discriminator. Because of this, uninformative and potentially wrong conflict errors would occur, as well as no conflict where a conflict should have occurred. * The grokker for the ``global_utility()`` directive did immediate registrations instead of generating configuration actions. Therefore it did not provoke ``ConflictErrors`` for conflicting registrations.
- Loading branch information
Showing
9 changed files
with
258 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
""" | ||
Registering two adapters for the same target interface should provoke | ||
a conflict, even if the interface is guessed (instead of being | ||
explicitly declared with grok.provides): | ||
>>> grok.testing.grok(__name__) | ||
Traceback (most recent call last): | ||
... | ||
ConfigurationConflictError: Conflicting configuration actions | ||
For: ('adapter', <InterfaceClass grok.tests.adapter.conflict.ICave>, <InterfaceClass grok.tests.adapter.conflict.IDecoration>, '') | ||
""" | ||
import grok | ||
from zope.interface import Interface | ||
|
||
class ICave(Interface): | ||
pass | ||
|
||
class IDecoration(Interface): | ||
pass | ||
|
||
class ICaveCleaning(Interface): | ||
pass | ||
|
||
class Cave(object): | ||
grok.implements(ICave) | ||
|
||
|
||
class ImplicitProvides(grok.Adapter): | ||
"""Here the provided interface is guessed because the class only | ||
implements one interface.""" | ||
grok.context(ICave) | ||
grok.implements(IDecoration) | ||
|
||
class ExplicitProvides(grok.Adapter): | ||
"""Here the provided interface is specific explicitly.""" | ||
grok.context(ICave) | ||
grok.implements(IDecoration, ICaveCleaning) | ||
grok.provides(IDecoration) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
""" | ||
Trying to register two utilities for the same interface (and | ||
potentially under the same name) will generate a configuration | ||
conflict: | ||
>>> grok.testing.grok(__name__) | ||
Traceback (most recent call last): | ||
... | ||
ConfigurationConflictError: Conflicting configuration actions | ||
For: ('utility', <InterfaceClass grok.tests.utility.conflict.IUtilityInterface>, 'class and module') | ||
<BLANKLINE> | ||
<BLANKLINE> | ||
For: ('utility', <InterfaceClass grok.tests.utility.conflict.IUtilityInterface>, 'direct class') | ||
<BLANKLINE> | ||
<BLANKLINE> | ||
For: ('utility', <InterfaceClass grok.tests.utility.conflict.IUtilityInterface>, 'explicit class') | ||
<BLANKLINE> | ||
<BLANKLINE> | ||
For: ('utility', <InterfaceClass grok.tests.utility.conflict.IUtilityInterface>, 'implicit class') | ||
<BLANKLINE> | ||
<BLANKLINE> | ||
For: ('utility', <InterfaceClass grok.tests.utility.conflict.IUtilityInterface>, 'mixed class') | ||
<BLANKLINE> | ||
<BLANKLINE> | ||
""" | ||
import grok | ||
from zope.interface import Interface, classProvides | ||
|
||
class IUtilityInterface(Interface): | ||
pass | ||
|
||
class IAnotherInterface(Interface): | ||
pass | ||
|
||
|
||
class Implicit1(grok.GlobalUtility): | ||
grok.implements(IUtilityInterface) | ||
grok.name('implicit class') | ||
|
||
class Implicit2(grok.GlobalUtility): | ||
grok.implements(IUtilityInterface) | ||
grok.name('implicit class') | ||
|
||
|
||
class Explicit1(grok.GlobalUtility): | ||
grok.implements(IUtilityInterface, IAnotherInterface) | ||
grok.provides(IUtilityInterface) | ||
grok.name('explicit class') | ||
|
||
class Explicit2(grok.GlobalUtility): | ||
grok.implements(IUtilityInterface, IAnotherInterface) | ||
grok.provides(IUtilityInterface) | ||
grok.name('explicit class') | ||
|
||
|
||
class Mixed1(grok.GlobalUtility): | ||
grok.implements(IUtilityInterface, IAnotherInterface) | ||
grok.provides(IUtilityInterface) | ||
grok.name('mixed class') | ||
|
||
class Mixed2(grok.GlobalUtility): | ||
grok.implements(IUtilityInterface) | ||
grok.name('mixed class') | ||
|
||
|
||
class Direct1(grok.GlobalUtility): | ||
classProvides(IUtilityInterface) | ||
grok.name('direct class') | ||
grok.direct() | ||
|
||
class Direct2(grok.GlobalUtility): | ||
classProvides(IUtilityInterface) | ||
grok.name('direct class') | ||
grok.direct() | ||
|
||
|
||
class ClassLevel(grok.GlobalUtility): | ||
"""This utility inherits from Grok's base class and is registered | ||
this way.""" | ||
grok.implements(IUtilityInterface) | ||
grok.name('class and module') | ||
|
||
class ModuleLevel(object): | ||
"""This utility doesn't inherit from Grok's base class and is | ||
registered explicitly using the module-level directive below.""" | ||
grok.implements(IUtilityInterface) | ||
|
||
grok.global_utility(ModuleLevel, name='class and module') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
""" | ||
Subclasses of grok.GlobalUtility that are supposed to be registered | ||
directly as utilities and which provide more than one interface must | ||
specify which interface to use for the registration: | ||
>>> grok.testing.grok(__name__) | ||
Traceback (most recent call last): | ||
... | ||
GrokError: <class 'grok.tests.utility.providesmany.Club'> | ||
provides more than one interface (use grok.provides to specify which one | ||
to use). | ||
""" | ||
import grok | ||
from zope import interface | ||
|
||
class IClub(interface.Interface): | ||
pass | ||
|
||
class ISpikyClub(interface.Interface): | ||
pass | ||
|
||
class Club(grok.GlobalUtility): | ||
interface.classProvides(IClub, ISpikyClub) | ||
grok.direct() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
""" | ||
Subclasses of grok.GlobalUtility that are supposed to be registered | ||
directly as utilities and which provide more than one interface must | ||
specify which interface to use for the registration: | ||
>>> grok.testing.grok(__name__) | ||
Traceback (most recent call last): | ||
... | ||
GrokError: <class 'grok.tests.utility.providesmany2.Club'> | ||
provides more than one interface (use grok.provides to specify which one | ||
to use). | ||
""" | ||
import grok | ||
from zope import interface | ||
|
||
class IClub(interface.Interface): | ||
pass | ||
|
||
class ISpikyClub(interface.Interface): | ||
pass | ||
|
||
class Club(object): | ||
interface.classProvides(IClub, ISpikyClub) | ||
|
||
grok.global_utility(Club, direct=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
""" | ||
Subclasses of grok.GlobalUtility must implement exactly one interface: | ||
>>> grok.testing.grok(__name__) | ||
Traceback (most recent call last): | ||
... | ||
GrokError: <class 'grok.tests.utility.providesnone.Club'> | ||
must provide at least one interface (use zope.interface.classProvides | ||
to specify). | ||
""" | ||
import grok | ||
|
||
class Club(grok.GlobalUtility): | ||
grok.direct() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
Subclasses of grok.GlobalUtility must implement exactly one interface: | ||
>>> grok.testing.grok(__name__) | ||
Traceback (most recent call last): | ||
... | ||
GrokError: <class 'grok.tests.utility.providesnone2.Club'> | ||
must provide at least one interface (use zope.interface.classProvides | ||
to specify). | ||
""" | ||
import grok | ||
|
||
class Club(object): | ||
pass | ||
|
||
grok.global_utility(Club, direct=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters