[Checkins] SVN: grok/trunk/src/grok/ Refactored tests to put tests
closer to their fixtures.
Philipp von Weitershausen
philikon at philikon.de
Sun Oct 15 08:07:28 EDT 2006
Log message for revision 70638:
Refactored tests to put tests closer to their fixtures.
Changed:
D grok/trunk/src/grok/adapter.txt
A grok/trunk/src/grok/tests/adapter/
A grok/trunk/src/grok/tests/adapter/__init__.py
A grok/trunk/src/grok/tests/adapter/adapter.py
A grok/trunk/src/grok/tests/adapter/alphabetical.py
A grok/trunk/src/grok/tests/adapter/classcontext.py
A grok/trunk/src/grok/tests/adapter/classcontextimported.py
A grok/trunk/src/grok/tests/adapter/classcontextmultiple.py
A grok/trunk/src/grok/tests/adapter/classcontextmultiple_fixture.py
A grok/trunk/src/grok/tests/adapter/classorinterface.py
A grok/trunk/src/grok/tests/adapter/functioncontext.py
A grok/trunk/src/grok/tests/adapter/importedmodel.py
A grok/trunk/src/grok/tests/adapter/importedmodel2.py
A grok/trunk/src/grok/tests/adapter/interface.py
A grok/trunk/src/grok/tests/adapter/interfacemodule.py
A grok/trunk/src/grok/tests/adapter/modulecontext.py
A grok/trunk/src/grok/tests/adapter/modulecontextimported.py
A grok/trunk/src/grok/tests/adapter/modulecontextmultiple.py
A grok/trunk/src/grok/tests/adapter/modulecontextmultiple_fixture.py
A grok/trunk/src/grok/tests/adapter/multiple.py
A grok/trunk/src/grok/tests/adapter/nomodel.py
A grok/trunk/src/grok/tests/adapter/oldstyleclass.py
A grok/trunk/src/grok/tests/adapter/order.py
D grok/trunk/src/grok/tests/adapter.py
D grok/trunk/src/grok/tests/alphabetical.py
D grok/trunk/src/grok/tests/classcontext.py
D grok/trunk/src/grok/tests/classcontextimported.py
D grok/trunk/src/grok/tests/classcontextmultiple.py
D grok/trunk/src/grok/tests/classorinterface.py
D grok/trunk/src/grok/tests/functioncontext.py
D grok/trunk/src/grok/tests/importedmodel.py
D grok/trunk/src/grok/tests/importedmodel2.py
D grok/trunk/src/grok/tests/interface.py
D grok/trunk/src/grok/tests/interfacemodule.py
D grok/trunk/src/grok/tests/modulecontext.py
D grok/trunk/src/grok/tests/modulecontextimported.py
D grok/trunk/src/grok/tests/modulecontextmultiple.py
D grok/trunk/src/grok/tests/multiple.py
D grok/trunk/src/grok/tests/nomodel.py
D grok/trunk/src/grok/tests/oldstyleclass.py
D grok/trunk/src/grok/tests/order.py
U grok/trunk/src/grok/tests/test_adapter.py
-=-
Deleted: grok/trunk/src/grok/adapter.txt
===================================================================
--- grok/trunk/src/grok/adapter.txt 2006-10-15 11:48:51 UTC (rev 70637)
+++ grok/trunk/src/grok/adapter.txt 2006-10-15 12:07:27 UTC (rev 70638)
@@ -1,302 +0,0 @@
-Adapter
-=======
-
- >>> import grok
- >>> grok.grok('grok.tests.adapter')
-
- >>> from grok.tests.adapter import IHome, Home, Cave
- >>> cave = Cave()
- >>> home = IHome(cave)
-
- >>> IHome.providedBy(home)
- True
- >>> isinstance(home, Home)
- True
-
-If no model can be found in the module, we get an error:
-
- >>> grok.grok('grok.tests.nomodel')
- Traceback (most recent call last):
- ...
- GrokError: Adapter without context
-
-Clean up component registry:
-
- >>> from zope.testing.cleanup import cleanUp
- >>> cleanUp()
-
-Imported model and adapter won't be grokked:
-
- >>> grok.grok('grok.tests.importedmodel')
- >>> home = IHome(cave)
- Traceback (most recent call last):
- ...
- TypeError: ('Could not adapt', <grok.tests.adapter.Cave object at ...>, <InterfaceClass grok.tests.adapter.IHome>)
-
-Clean up:
-
- >>> cleanUp()
-
-Grok error because import model doesn't count as context:
-
- >>> grok.grok('grok.tests.importedmodel2')
- Traceback (most recent call last):
- ...
- GrokError: Adapter without context
-
-Clean up:
-
- >>> cleanUp()
-
-Grok does not depend on the alphabetical order:
-
- >>> grok.grok('grok.tests.alphabetical')
-
- >>> from grok.tests.alphabetical import IHome, Home, ZCave
- >>> cave = ZCave()
- >>> home = IHome(cave)
-
- >>> IHome.providedBy(home)
- True
- >>> isinstance(home, Home)
- True
-
-Clean up:
-
- >>> cleanUp()
-
-If the model is defined after the adapter, it should still be grokked
-properly:
-
- >>> grok.grok('grok.tests.order')
-
- >>> from grok.tests.order import IHome, Home, Cave
- >>> cave = Cave()
- >>> home = IHome(cave)
-
- >>> IHome.providedBy(home)
- True
- >>> isinstance(home, Home)
- True
-
-Clean up:
-
- >>> cleanUp()
-
-Multiple models lead to ambiguity:
-
- >>> grok.grok('grok.tests.multiple')
- Traceback (most recent call last):
- ...
- GrokError: Ambiguous contexts, please use grok.context.
-
-Clean up:
-
- >>> cleanUp()
-
-Explicit module-level context in case of multiple models:
-
- >>> grok.grok('grok.tests.modulecontext')
-
- >>> from grok.tests.modulecontext import IHome, Home, Cave
- >>> cave = Cave()
- >>> home = IHome(cave)
-
- >>> IHome.providedBy(home)
- True
- >>> isinstance(home, Home)
- True
-
-Clean up:
-
- >>> cleanUp()
-
-Explicit module-level context for an imported model:
-
- >>> grok.grok('grok.tests.modulecontextimported')
-
- >>> from grok.tests.modulecontextimported import IPainting, Painting, Cave
- >>> cave = Cave()
- >>> painting = IPainting(cave)
-
- >>> IPainting.providedBy(painting)
- True
- >>> isinstance(painting, Painting)
- True
-
-Clean up:
-
- >>> cleanUp()
-
-You can't call grok.context multiple times on module level:
-
- >>> import grok.tests.modulecontextmultiple
- Traceback (most recent call last):
- ...
- GrokError: grok.context can only be called once per class or module.
-
-Clean up:
-
- >>> cleanUp()
-
-Explicit class-level context in case of multiple models:
-
- >>> grok.grok('grok.tests.classcontext')
-
- >>> from grok.tests.classcontext import IHome, Home, Cave
- >>> cave = Cave()
- >>> home = IHome(cave)
-
- >>> IHome.providedBy(home)
- True
- >>> isinstance(home, Home)
- True
-
-Clean up:
-
- >>> cleanUp()
-
-Explicit class-level context for an imported model:
-
- >>> grok.grok('grok.tests.classcontextimported')
-
- >>> from grok.tests.classcontextimported import IPainting, Painting, Cave
- >>> cave = Cave()
- >>> painting = IPainting(cave)
-
- >>> IPainting.providedBy(painting)
- True
- >>> isinstance(painting, Painting)
- True
-
-Clean up:
-
- >>> cleanUp()
-
-You can't call grok.context multiple times on class level:
-
- >>> import grok.tests.classcontextmultiple
- Traceback (most recent call last):
- ...
- GrokError: grok.context can only be called once per class or module.
-
-Clean up:
-
- >>> cleanUp()
-
-You can't call grok.context from a function:
-
- >>> from grok.tests.functioncontext import func, SomeClass
- >>> func()
- Traceback (most recent call last):
- ...
- GrokError: grok.context can only be used on class or module level.
-
-You can't call grok.context from a method either:
-
- >>> SomeClass().meth()
- Traceback (most recent call last):
- ...
- GrokError: grok.context can only be used on class or module level.
-
-Clean up:
-
- >>> cleanUp()
-
-You can also specify interfaces instead of classes with
-`grok.context` (class-level):
-
- >>> grok.grok('grok.tests.interface')
-
- >>> from grok.tests.interface import IHome, Home, Cave, Hole
- >>> cave = Cave()
- >>> home = IHome(cave)
-
- >>> IHome.providedBy(home)
- True
- >>> isinstance(home, Home)
- True
-
- >>> hole = Hole()
- >>> home = IHome(hole)
-
- >>> IHome.providedBy(home)
- True
- >>> isinstance(home, Home)
- True
-
-Clean up:
-
- >>> cleanUp()
-
-You can also specify interfaces instead of classes with
-`grok.context` (module-level):
-
- >>> grok.grok('grok.tests.interfacemodule')
-
- >>> from grok.tests.interfacemodule import IHome, Home, Cave, Hole
- >>> cave = Cave()
- >>> home = IHome(cave)
-
- >>> IHome.providedBy(home)
- True
- >>> isinstance(home, Home)
- True
-
- >>> hole = Hole()
- >>> home = IHome(hole)
-
- >>> IHome.providedBy(home)
- True
- >>> isinstance(home, Home)
- True
-
-Clean up:
-
- >>> cleanUp()
-
-You can only use `grok.context` with interfaces or classes and not
-with anything else:
-
- >>> from grok.tests import classorinterface
- >>> classorinterface.function_context()
- Traceback (most recent call last):
- ...
- GrokError: You can only pass classes or interfaces to grok.context.
-
- >>> classorinterface.string_context()
- Traceback (most recent call last):
- ...
- GrokError: You can only pass classes or interfaces to grok.context.
-
- >>> classorinterface.module_context()
- Traceback (most recent call last):
- ...
- GrokError: You can only pass classes or interfaces to grok.context.
-
- >>> classorinterface.instance_context()
- Traceback (most recent call last):
- ...
- GrokError: You can only pass classes or interfaces to grok.context.
-
-
-Clean up:
-
- >>> cleanUp()
-
-Old-style classes are also supported:
-
- >>> grok.grok('grok.tests.oldstyleclass')
-
- >>> from grok.tests.oldstyleclass import IHome, Home, Cave
- >>> cave = Cave()
- >>> home = IHome(cave)
-
- >>> IHome.providedBy(home)
- True
- >>> isinstance(home, Home)
- True
-
-Clean up:
-
- >>> cleanUp()
Copied: grok/trunk/src/grok/tests/adapter/__init__.py (from rev 70615, grok/trunk/src/grok/tests/__init__.py)
Copied: grok/trunk/src/grok/tests/adapter/adapter.py (from rev 70615, grok/trunk/src/grok/tests/adapter.py)
===================================================================
--- grok/trunk/src/grok/tests/adapter.py 2006-10-14 17:18:12 UTC (rev 70615)
+++ grok/trunk/src/grok/tests/adapter/adapter.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -0,0 +1,23 @@
+"""
+ >>> grok.grok(__name__)
+
+ >>> cave = Cave()
+ >>> home = IHome(cave)
+
+ >>> IHome.providedBy(home)
+ True
+ >>> isinstance(home, Home)
+ True
+"""
+
+import grok
+from zope import interface
+
+class Cave(grok.Model):
+ pass
+
+class IHome(interface.Interface):
+ pass
+
+class Home(grok.Adapter):
+ grok.implements(IHome)
Copied: grok/trunk/src/grok/tests/adapter/alphabetical.py (from rev 70618, grok/trunk/src/grok/tests/alphabetical.py)
===================================================================
--- grok/trunk/src/grok/tests/alphabetical.py 2006-10-14 17:56:59 UTC (rev 70618)
+++ grok/trunk/src/grok/tests/adapter/alphabetical.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -0,0 +1,26 @@
+"""
+Grok does not depend on the alphabetical order:
+
+ >>> grok.grok(__name__)
+
+ >>> cave = ZCave()
+ >>> home = IHome(cave)
+
+ >>> IHome.providedBy(home)
+ True
+ >>> isinstance(home, Home)
+ True
+
+"""
+import grok
+from zope import interface
+
+class ZCave(grok.Model):
+ """we call this `ZCave` because we want to test that we do not
+ depend on alphabetical order"""
+
+class IHome(interface.Interface):
+ pass
+
+class Home(grok.Adapter):
+ grok.implements(IHome)
Copied: grok/trunk/src/grok/tests/adapter/classcontext.py (from rev 70626, grok/trunk/src/grok/tests/classcontext.py)
===================================================================
--- grok/trunk/src/grok/tests/classcontext.py 2006-10-14 18:39:54 UTC (rev 70626)
+++ grok/trunk/src/grok/tests/adapter/classcontext.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -0,0 +1,29 @@
+"""
+Explicit class-level context in case of multiple models:
+
+ >>> grok.grok(__name__)
+
+ >>> cave = Cave()
+ >>> home = IHome(cave)
+
+ >>> IHome.providedBy(home)
+ True
+ >>> isinstance(home, Home)
+ True
+
+"""
+import grok
+from zope import interface
+
+class Cave(grok.Model):
+ pass
+
+class Club(grok.Model):
+ pass
+
+class IHome(interface.Interface):
+ pass
+
+class Home(grok.Adapter):
+ grok.implements(IHome)
+ grok.context(Cave)
Copied: grok/trunk/src/grok/tests/adapter/classcontextimported.py (from rev 70627, grok/trunk/src/grok/tests/classcontextimported.py)
===================================================================
--- grok/trunk/src/grok/tests/classcontextimported.py 2006-10-14 18:45:16 UTC (rev 70627)
+++ grok/trunk/src/grok/tests/adapter/classcontextimported.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -0,0 +1,24 @@
+"""
+Explicit class-level context for an imported model:
+
+ >>> grok.grok(__name__)
+
+ >>> cave = Cave()
+ >>> painting = IPainting(cave)
+
+ >>> IPainting.providedBy(painting)
+ True
+ >>> isinstance(painting, Painting)
+ True
+
+"""
+import grok
+from grok.tests.adapter.adapter import Cave
+from zope import interface
+
+class IPainting(interface.Interface):
+ pass
+
+class Painting(grok.Adapter):
+ grok.implements(IPainting)
+ grok.context(Cave)
Copied: grok/trunk/src/grok/tests/adapter/classcontextmultiple.py (from rev 70628, grok/trunk/src/grok/tests/classcontextmultiple.py)
===================================================================
--- grok/trunk/src/grok/tests/classcontextmultiple.py 2006-10-14 18:47:41 UTC (rev 70628)
+++ grok/trunk/src/grok/tests/adapter/classcontextmultiple.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -0,0 +1,10 @@
+"""
+You can't call grok.context multiple times on class level:
+
+ >>> import grok.tests.adapter.classcontextmultiple_fixture
+ Traceback (most recent call last):
+ ...
+ GrokError: grok.context can only be called once per class or module.
+
+"""
+
Added: grok/trunk/src/grok/tests/adapter/classcontextmultiple_fixture.py
===================================================================
--- grok/trunk/src/grok/tests/adapter/classcontextmultiple_fixture.py 2006-10-15 11:48:51 UTC (rev 70637)
+++ grok/trunk/src/grok/tests/adapter/classcontextmultiple_fixture.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -0,0 +1,11 @@
+import grok
+
+class Cave(grok.Model):
+ pass
+
+class Club(grok.Model):
+ pass
+
+class Anything(object):
+ grok.context(Cave)
+ grok.context(Club)
Property changes on: grok/trunk/src/grok/tests/adapter/classcontextmultiple_fixture.py
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: grok/trunk/src/grok/tests/adapter/classorinterface.py (from rev 70635, grok/trunk/src/grok/tests/classorinterface.py)
===================================================================
--- grok/trunk/src/grok/tests/classorinterface.py 2006-10-15 10:49:16 UTC (rev 70635)
+++ grok/trunk/src/grok/tests/adapter/classorinterface.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -0,0 +1,46 @@
+"""
+You can only use `grok.context` with interfaces or classes and not
+with anything else:
+
+ >>> function_context()
+ Traceback (most recent call last):
+ ...
+ GrokError: You can only pass classes or interfaces to grok.context.
+
+ >>> string_context()
+ Traceback (most recent call last):
+ ...
+ GrokError: You can only pass classes or interfaces to grok.context.
+
+ >>> module_context()
+ Traceback (most recent call last):
+ ...
+ GrokError: You can only pass classes or interfaces to grok.context.
+
+ >>> instance_context()
+ Traceback (most recent call last):
+ ...
+ GrokError: You can only pass classes or interfaces to grok.context.
+
+"""
+import grok
+
+def function_context():
+ def a():
+ pass
+
+ class FunctionContext(object):
+ grok.context(a)
+
+def string_context():
+ class StringContext(object):
+ grok.context('string')
+
+def module_context():
+ class ModuleContext(object):
+ grok.context(grok)
+
+def instance_context():
+ obj = object()
+ class InstanceContext(object):
+ grok.context(obj)
Copied: grok/trunk/src/grok/tests/adapter/functioncontext.py (from rev 70629, grok/trunk/src/grok/tests/functioncontext.py)
===================================================================
--- grok/trunk/src/grok/tests/functioncontext.py 2006-10-14 19:14:37 UTC (rev 70629)
+++ grok/trunk/src/grok/tests/adapter/functioncontext.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -0,0 +1,30 @@
+"""
+You can't call grok.context from a function:
+
+ >>> func()
+ Traceback (most recent call last):
+ ...
+ GrokError: grok.context can only be used on class or module level.
+
+You can't call grok.context from a method either:
+
+ >>> SomeClass().meth()
+ Traceback (most recent call last):
+ ...
+ GrokError: grok.context can only be used on class or module level.
+
+"""
+import grok
+from grok.tests.adapter.adapter import Cave
+
+def func():
+ """We don't allow calling `grok.context` from anything else than a
+ module or a class"""
+ grok.context(Cave)
+
+class SomeClass(object):
+
+ def meth(self):
+ """We don't allow calling `grok.context` from anything else
+ than a module or a class"""
+ grok.context(Cave)
Copied: grok/trunk/src/grok/tests/adapter/importedmodel.py (from rev 70617, grok/trunk/src/grok/tests/importedmodel.py)
===================================================================
--- grok/trunk/src/grok/tests/importedmodel.py 2006-10-14 17:43:28 UTC (rev 70617)
+++ grok/trunk/src/grok/tests/adapter/importedmodel.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -0,0 +1,14 @@
+"""
+Imported model and adapter won't be grokked:
+
+ >>> import grok
+ >>> grok.grok(__name__)
+ >>> from grok.tests.adapter.adapter import IHome
+ >>> cave = Cave()
+ >>> home = IHome(cave)
+ Traceback (most recent call last):
+ ...
+ TypeError: ('Could not adapt', <grok.tests.adapter.adapter.Cave object at ...>, <InterfaceClass grok.tests.adapter.adapter.IHome>)
+
+"""
+from grok.tests.adapter.adapter import Cave, Home
Copied: grok/trunk/src/grok/tests/adapter/importedmodel2.py (from rev 70617, grok/trunk/src/grok/tests/importedmodel2.py)
===================================================================
--- grok/trunk/src/grok/tests/importedmodel2.py 2006-10-14 17:43:28 UTC (rev 70617)
+++ grok/trunk/src/grok/tests/adapter/importedmodel2.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -0,0 +1,22 @@
+"""
+Grok error because import model doesn't count as context:
+
+ >>> grok.grok(__name__)
+ Traceback (most recent call last):
+ ...
+ GrokError: Adapter without context
+
+"""
+import grok
+from grok.tests.adapter.adapter import Cave
+from zope import interface
+
+class IPainting(interface.Interface):
+ pass
+
+class Painting(grok.Adapter):
+ """
+ Grokking of this should fail because there's no model (only an
+ imported one which doesn't count).
+ """
+ grok.implements(IPainting)
Copied: grok/trunk/src/grok/tests/adapter/interface.py (from rev 70632, grok/trunk/src/grok/tests/interface.py)
===================================================================
--- grok/trunk/src/grok/tests/interface.py 2006-10-15 10:31:19 UTC (rev 70632)
+++ grok/trunk/src/grok/tests/adapter/interface.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -0,0 +1,41 @@
+"""
+You can also specify interfaces instead of classes with
+`grok.context` (class-level):
+
+ >>> grok.grok(__name__)
+
+ >>> cave = Cave()
+ >>> home = IHome(cave)
+
+ >>> IHome.providedBy(home)
+ True
+ >>> isinstance(home, Home)
+ True
+
+ >>> hole = Hole()
+ >>> home = IHome(hole)
+
+ >>> IHome.providedBy(home)
+ True
+ >>> isinstance(home, Home)
+ True
+
+"""
+import grok
+from zope import interface
+
+class ICave(interface.Interface):
+ pass
+
+class Cave(grok.Model):
+ grok.implements(ICave)
+
+class Hole(grok.Model):
+ grok.implements(ICave)
+
+class IHome(interface.Interface):
+ pass
+
+class Home(grok.Adapter):
+ grok.implements(IHome)
+ grok.context(ICave)
Copied: grok/trunk/src/grok/tests/adapter/interfacemodule.py (from rev 70634, grok/trunk/src/grok/tests/interfacemodule.py)
===================================================================
--- grok/trunk/src/grok/tests/interfacemodule.py 2006-10-15 10:35:26 UTC (rev 70634)
+++ grok/trunk/src/grok/tests/adapter/interfacemodule.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -0,0 +1,42 @@
+"""
+You can also specify interfaces instead of classes with
+`grok.context` (module-level):
+
+ >>> grok.grok(__name__)
+
+ >>> cave = Cave()
+ >>> home = IHome(cave)
+
+ >>> IHome.providedBy(home)
+ True
+ >>> isinstance(home, Home)
+ True
+
+ >>> hole = Hole()
+ >>> home = IHome(hole)
+
+ >>> IHome.providedBy(home)
+ True
+ >>> isinstance(home, Home)
+ True
+
+"""
+import grok
+from zope import interface
+
+class ICave(interface.Interface):
+ pass
+
+class Cave(grok.Model):
+ grok.implements(ICave)
+
+class Hole(grok.Model):
+ grok.implements(ICave)
+
+grok.context(ICave)
+
+class IHome(interface.Interface):
+ pass
+
+class Home(grok.Adapter):
+ grok.implements(IHome)
Copied: grok/trunk/src/grok/tests/adapter/modulecontext.py (from rev 70623, grok/trunk/src/grok/tests/modulecontext.py)
===================================================================
--- grok/trunk/src/grok/tests/modulecontext.py 2006-10-14 18:26:35 UTC (rev 70623)
+++ grok/trunk/src/grok/tests/adapter/modulecontext.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -0,0 +1,30 @@
+"""
+Explicit module-level context in case of multiple models:
+
+ >>> grok.grok(__name__)
+
+ >>> cave = Cave()
+ >>> home = IHome(cave)
+
+ >>> IHome.providedBy(home)
+ True
+ >>> isinstance(home, Home)
+ True
+
+"""
+import grok
+from zope import interface
+
+class Cave(grok.Model):
+ pass
+
+class Club(grok.Model):
+ pass
+
+grok.context(Cave)
+
+class IHome(interface.Interface):
+ pass
+
+class Home(grok.Adapter):
+ grok.implements(IHome)
Copied: grok/trunk/src/grok/tests/adapter/modulecontextimported.py (from rev 70624, grok/trunk/src/grok/tests/modulecontextimported.py)
===================================================================
--- grok/trunk/src/grok/tests/modulecontextimported.py 2006-10-14 18:30:13 UTC (rev 70624)
+++ grok/trunk/src/grok/tests/adapter/modulecontextimported.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -0,0 +1,25 @@
+"""
+Explicit module-level context for an imported model:
+
+ >>> grok.grok(__name__)
+
+ >>> cave = Cave()
+ >>> painting = IPainting(cave)
+
+ >>> IPainting.providedBy(painting)
+ True
+ >>> isinstance(painting, Painting)
+ True
+
+"""
+import grok
+from grok.tests.adapter.adapter import Cave
+from zope import interface
+
+grok.context(Cave)
+
+class IPainting(interface.Interface):
+ pass
+
+class Painting(grok.Adapter):
+ grok.implements(IPainting)
Copied: grok/trunk/src/grok/tests/adapter/modulecontextmultiple.py (from rev 70625, grok/trunk/src/grok/tests/modulecontextmultiple.py)
===================================================================
--- grok/trunk/src/grok/tests/modulecontextmultiple.py 2006-10-14 18:34:42 UTC (rev 70625)
+++ grok/trunk/src/grok/tests/adapter/modulecontextmultiple.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -0,0 +1,9 @@
+"""
+You can't call grok.context multiple times on module level:
+
+ >>> import grok.tests.adapter.modulecontextmultiple_fixture
+ Traceback (most recent call last):
+ ...
+ GrokError: grok.context can only be called once per class or module.
+
+"""
Added: grok/trunk/src/grok/tests/adapter/modulecontextmultiple_fixture.py
===================================================================
--- grok/trunk/src/grok/tests/adapter/modulecontextmultiple_fixture.py 2006-10-15 11:48:51 UTC (rev 70637)
+++ grok/trunk/src/grok/tests/adapter/modulecontextmultiple_fixture.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -0,0 +1,11 @@
+import grok
+from zope import interface
+
+class Cave(grok.Model):
+ pass
+
+class Club(grok.Model):
+ pass
+
+grok.context(Cave)
+grok.context(Club)
Property changes on: grok/trunk/src/grok/tests/adapter/modulecontextmultiple_fixture.py
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: grok/trunk/src/grok/tests/adapter/multiple.py (from rev 70620, grok/trunk/src/grok/tests/multiple.py)
===================================================================
--- grok/trunk/src/grok/tests/multiple.py 2006-10-14 18:11:07 UTC (rev 70620)
+++ grok/trunk/src/grok/tests/adapter/multiple.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -0,0 +1,23 @@
+"""
+Multiple models lead to ambiguity:
+
+ >>> grok.grok(__name__)
+ Traceback (most recent call last):
+ ...
+ GrokError: Ambiguous contexts, please use grok.context.
+
+"""
+import grok
+from zope import interface
+
+class Cave(grok.Model):
+ pass
+
+class Club(grok.Model):
+ pass
+
+class IHome(interface.Interface):
+ pass
+
+class Home(grok.Adapter):
+ grok.implements(IHome)
Copied: grok/trunk/src/grok/tests/adapter/nomodel.py (from rev 70616, grok/trunk/src/grok/tests/nomodel.py)
===================================================================
--- grok/trunk/src/grok/tests/nomodel.py 2006-10-14 17:23:00 UTC (rev 70616)
+++ grok/trunk/src/grok/tests/adapter/nomodel.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -0,0 +1,17 @@
+"""
+If no model can be found in the module, we get an error:
+
+ >>> grok.grok(__name__)
+ Traceback (most recent call last):
+ ...
+ GrokError: Adapter without context
+
+"""
+import grok
+from zope import interface
+
+class IHome(interface.Interface):
+ pass
+
+class Home(grok.Adapter):
+ grok.implements(IHome)
Copied: grok/trunk/src/grok/tests/adapter/oldstyleclass.py (from rev 70636, grok/trunk/src/grok/tests/oldstyleclass.py)
===================================================================
--- grok/trunk/src/grok/tests/oldstyleclass.py 2006-10-15 11:20:48 UTC (rev 70636)
+++ grok/trunk/src/grok/tests/adapter/oldstyleclass.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -0,0 +1,25 @@
+"""
+Old-style classes are also supported:
+
+ >>> grok.grok(__name__)
+
+ >>> cave = Cave()
+ >>> home = IHome(cave)
+
+ >>> IHome.providedBy(home)
+ True
+ >>> isinstance(home, Home)
+ True
+"""
+import grok
+from zope import interface
+
+class Cave:
+ pass
+
+class IHome(interface.Interface):
+ pass
+
+class Home(grok.Adapter):
+ grok.implements(IHome)
+ grok.context(Cave)
Copied: grok/trunk/src/grok/tests/adapter/order.py (from rev 70619, grok/trunk/src/grok/tests/order.py)
===================================================================
--- grok/trunk/src/grok/tests/order.py 2006-10-14 18:00:02 UTC (rev 70619)
+++ grok/trunk/src/grok/tests/adapter/order.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -0,0 +1,26 @@
+"""
+If the model is defined after the adapter, it should still be grokked
+properly:
+
+ >>> grok.grok(__name__)
+
+ >>> cave = Cave()
+ >>> home = IHome(cave)
+
+ >>> IHome.providedBy(home)
+ True
+ >>> isinstance(home, Home)
+ True
+
+"""
+import grok
+from zope import interface
+
+class IHome(interface.Interface):
+ pass
+
+class Home(grok.Adapter):
+ grok.implements(IHome)
+
+class Cave(grok.Model):
+ pass
Deleted: grok/trunk/src/grok/tests/adapter.py
===================================================================
--- grok/trunk/src/grok/tests/adapter.py 2006-10-15 11:48:51 UTC (rev 70637)
+++ grok/trunk/src/grok/tests/adapter.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -1,11 +0,0 @@
-import grok
-from zope import interface
-
-class Cave(grok.Model):
- pass
-
-class IHome(interface.Interface):
- pass
-
-class Home(grok.Adapter):
- grok.implements(IHome)
Deleted: grok/trunk/src/grok/tests/alphabetical.py
===================================================================
--- grok/trunk/src/grok/tests/alphabetical.py 2006-10-15 11:48:51 UTC (rev 70637)
+++ grok/trunk/src/grok/tests/alphabetical.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -1,12 +0,0 @@
-import grok
-from zope import interface
-
-class ZCave(grok.Model):
- """we call this `ZCave` because we want to test that we do not
- depend on alphabetical order"""
-
-class IHome(interface.Interface):
- pass
-
-class Home(grok.Adapter):
- grok.implements(IHome)
Deleted: grok/trunk/src/grok/tests/classcontext.py
===================================================================
--- grok/trunk/src/grok/tests/classcontext.py 2006-10-15 11:48:51 UTC (rev 70637)
+++ grok/trunk/src/grok/tests/classcontext.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -1,15 +0,0 @@
-import grok
-from zope import interface
-
-class Cave(grok.Model):
- pass
-
-class Club(grok.Model):
- pass
-
-class IHome(interface.Interface):
- pass
-
-class Home(grok.Adapter):
- grok.implements(IHome)
- grok.context(Cave)
Deleted: grok/trunk/src/grok/tests/classcontextimported.py
===================================================================
--- grok/trunk/src/grok/tests/classcontextimported.py 2006-10-15 11:48:51 UTC (rev 70637)
+++ grok/trunk/src/grok/tests/classcontextimported.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -1,10 +0,0 @@
-import grok
-from grok.tests.adapter import Cave
-from zope import interface
-
-class IPainting(interface.Interface):
- pass
-
-class Painting(grok.Adapter):
- grok.implements(IPainting)
- grok.context(Cave)
Deleted: grok/trunk/src/grok/tests/classcontextmultiple.py
===================================================================
--- grok/trunk/src/grok/tests/classcontextmultiple.py 2006-10-15 11:48:51 UTC (rev 70637)
+++ grok/trunk/src/grok/tests/classcontextmultiple.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -1,11 +0,0 @@
-import grok
-
-class Cave(grok.Model):
- pass
-
-class Club(grok.Model):
- pass
-
-class Anything(object):
- grok.context(Cave)
- grok.context(Club)
Deleted: grok/trunk/src/grok/tests/classorinterface.py
===================================================================
--- grok/trunk/src/grok/tests/classorinterface.py 2006-10-15 11:48:51 UTC (rev 70637)
+++ grok/trunk/src/grok/tests/classorinterface.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -1,24 +0,0 @@
-"""
-All of the below examples should fail
-"""
-import grok
-
-def function_context():
- def a():
- pass
-
- class FunctionContext(object):
- grok.context(a)
-
-def string_context():
- class StringContext(object):
- grok.context('string')
-
-def module_context():
- class ModuleContext(object):
- grok.context(grok)
-
-def instance_context():
- obj = object()
- class InstanceContext(object):
- grok.context(obj)
Deleted: grok/trunk/src/grok/tests/functioncontext.py
===================================================================
--- grok/trunk/src/grok/tests/functioncontext.py 2006-10-15 11:48:51 UTC (rev 70637)
+++ grok/trunk/src/grok/tests/functioncontext.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -1,14 +0,0 @@
-import grok
-from grok.tests.adapter import Cave
-
-def func():
- """We don't allow calling `grok.context` from anything else than a
- module or a class"""
- grok.context(Cave)
-
-class SomeClass(object):
-
- def meth(self):
- """We don't allow calling `grok.context` from anything else
- than a module or a class"""
- grok.context(Cave)
Deleted: grok/trunk/src/grok/tests/importedmodel.py
===================================================================
--- grok/trunk/src/grok/tests/importedmodel.py 2006-10-15 11:48:51 UTC (rev 70637)
+++ grok/trunk/src/grok/tests/importedmodel.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -1 +0,0 @@
-from grok.tests.adapter import Cave, Home
Deleted: grok/trunk/src/grok/tests/importedmodel2.py
===================================================================
--- grok/trunk/src/grok/tests/importedmodel2.py 2006-10-15 11:48:51 UTC (rev 70637)
+++ grok/trunk/src/grok/tests/importedmodel2.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -1,13 +0,0 @@
-import grok
-from grok.tests.adapter import Cave
-from zope import interface
-
-class IPainting(interface.Interface):
- pass
-
-class Painting(grok.Adapter):
- """
- Grokking of this should fail because there's no model (only an
- imported one which doesn't count).
- """
- grok.implements(IPainting)
Deleted: grok/trunk/src/grok/tests/interface.py
===================================================================
--- grok/trunk/src/grok/tests/interface.py 2006-10-15 11:48:51 UTC (rev 70637)
+++ grok/trunk/src/grok/tests/interface.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -1,18 +0,0 @@
-import grok
-from zope import interface
-
-class ICave(interface.Interface):
- pass
-
-class Cave(grok.Model):
- grok.implements(ICave)
-
-class Hole(grok.Model):
- grok.implements(ICave)
-
-class IHome(interface.Interface):
- pass
-
-class Home(grok.Adapter):
- grok.implements(IHome)
- grok.context(ICave)
Deleted: grok/trunk/src/grok/tests/interfacemodule.py
===================================================================
--- grok/trunk/src/grok/tests/interfacemodule.py 2006-10-15 11:48:51 UTC (rev 70637)
+++ grok/trunk/src/grok/tests/interfacemodule.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -1,19 +0,0 @@
-import grok
-from zope import interface
-
-class ICave(interface.Interface):
- pass
-
-class Cave(grok.Model):
- grok.implements(ICave)
-
-class Hole(grok.Model):
- grok.implements(ICave)
-
-grok.context(ICave)
-
-class IHome(interface.Interface):
- pass
-
-class Home(grok.Adapter):
- grok.implements(IHome)
Deleted: grok/trunk/src/grok/tests/modulecontext.py
===================================================================
--- grok/trunk/src/grok/tests/modulecontext.py 2006-10-15 11:48:51 UTC (rev 70637)
+++ grok/trunk/src/grok/tests/modulecontext.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -1,16 +0,0 @@
-import grok
-from zope import interface
-
-class Cave(grok.Model):
- pass
-
-class Club(grok.Model):
- pass
-
-grok.context(Cave)
-
-class IHome(interface.Interface):
- pass
-
-class Home(grok.Adapter):
- grok.implements(IHome)
Deleted: grok/trunk/src/grok/tests/modulecontextimported.py
===================================================================
--- grok/trunk/src/grok/tests/modulecontextimported.py 2006-10-15 11:48:51 UTC (rev 70637)
+++ grok/trunk/src/grok/tests/modulecontextimported.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -1,11 +0,0 @@
-import grok
-from grok.tests.adapter import Cave
-from zope import interface
-
-grok.context(Cave)
-
-class IPainting(interface.Interface):
- pass
-
-class Painting(grok.Adapter):
- grok.implements(IPainting)
Deleted: grok/trunk/src/grok/tests/modulecontextmultiple.py
===================================================================
--- grok/trunk/src/grok/tests/modulecontextmultiple.py 2006-10-15 11:48:51 UTC (rev 70637)
+++ grok/trunk/src/grok/tests/modulecontextmultiple.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -1,11 +0,0 @@
-import grok
-from zope import interface
-
-class Cave(grok.Model):
- pass
-
-class Club(grok.Model):
- pass
-
-grok.context(Cave)
-grok.context(Club)
Deleted: grok/trunk/src/grok/tests/multiple.py
===================================================================
--- grok/trunk/src/grok/tests/multiple.py 2006-10-15 11:48:51 UTC (rev 70637)
+++ grok/trunk/src/grok/tests/multiple.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -1,14 +0,0 @@
-import grok
-from zope import interface
-
-class Cave(grok.Model):
- pass
-
-class Club(grok.Model):
- pass
-
-class IHome(interface.Interface):
- pass
-
-class Home(grok.Adapter):
- grok.implements(IHome)
Deleted: grok/trunk/src/grok/tests/nomodel.py
===================================================================
--- grok/trunk/src/grok/tests/nomodel.py 2006-10-15 11:48:51 UTC (rev 70637)
+++ grok/trunk/src/grok/tests/nomodel.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -1,8 +0,0 @@
-import grok
-from zope import interface
-
-class IHome(interface.Interface):
- pass
-
-class Home(grok.Adapter):
- grok.implements(IHome)
Deleted: grok/trunk/src/grok/tests/oldstyleclass.py
===================================================================
--- grok/trunk/src/grok/tests/oldstyleclass.py 2006-10-15 11:48:51 UTC (rev 70637)
+++ grok/trunk/src/grok/tests/oldstyleclass.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -1,12 +0,0 @@
-import grok
-from zope import interface
-
-class Cave:
- pass
-
-class IHome(interface.Interface):
- pass
-
-class Home(grok.Adapter):
- grok.implements(IHome)
- grok.context(Cave)
Deleted: grok/trunk/src/grok/tests/order.py
===================================================================
--- grok/trunk/src/grok/tests/order.py 2006-10-15 11:48:51 UTC (rev 70637)
+++ grok/trunk/src/grok/tests/order.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -1,11 +0,0 @@
-import grok
-from zope import interface
-
-class IHome(interface.Interface):
- pass
-
-class Home(grok.Adapter):
- grok.implements(IHome)
-
-class Cave(grok.Model):
- pass
Modified: grok/trunk/src/grok/tests/test_adapter.py
===================================================================
--- grok/trunk/src/grok/tests/test_adapter.py 2006-10-15 11:48:51 UTC (rev 70637)
+++ grok/trunk/src/grok/tests/test_adapter.py 2006-10-15 12:07:27 UTC (rev 70638)
@@ -1,12 +1,27 @@
import unittest
-from zope.testing import doctest
+from pkg_resources import resource_listdir
+from zope.testing import doctest, cleanup
+def tearDown(test):
+ cleanup.cleanUp()
+
+def grokTestSuite(pkg):
+ return doctest.DocTestSuite(pkg, tearDown=tearDown,
+ optionflags=doctest.ELLIPSIS)
+
def test_suite():
- return unittest.TestSuite((
- doctest.DocFileSuite('adapter.txt',
- package='grok',
- optionflags=doctest.ELLIPSIS),
- ))
+ adapterfiles = resource_listdir(__name__, 'adapter')
+ suite = unittest.TestSuite()
+ for filename in adapterfiles:
+ if not filename.endswith('.py'):
+ continue
+ if filename.endswith('_fixture.py'):
+ continue
+ if filename == '__init__.py':
+ continue
+ dottedname = 'grok.tests.adapter.' + filename[:-3]
+ suite.addTest(grokTestSuite(dottedname))
+ return suite
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
More information about the Checkins
mailing list