[Checkins] SVN: zope.location/trunk/src/zope/location/ moving tests
to .txt file
Christian Zagrodnick
cz at gocept.com
Fri Aug 17 07:48:00 EDT 2007
Log message for revision 78900:
moving tests to .txt file
Changed:
U zope.location/trunk/src/zope/location/location.py
U zope.location/trunk/src/zope/location/tests.py
-=-
Modified: zope.location/trunk/src/zope/location/location.py
===================================================================
--- zope.location/trunk/src/zope/location/location.py 2007-08-17 10:04:02 UTC (rev 78899)
+++ zope.location/trunk/src/zope/location/location.py 2007-08-17 11:48:00 UTC (rev 78900)
@@ -17,50 +17,22 @@
"""
__docformat__ = 'restructuredtext'
+
import zope.interface
from zope.location.interfaces import ILocation
from zope.proxy import ProxyBase, getProxiedObject, non_overridable
from zope.proxy.decorator import DecoratorSpecificationDescriptor
from zope.security.decorator import DecoratedSecurityCheckerDescriptor
+
class Location(object):
- """Stupid mix-in that defines `__parent__` and `__name__` attributes
+ """Stupid mix-in that defines `__parent__` and `__name__` attributes."""
- Usage within an Object field:
-
- >>> from zope.interface import implements, Interface
- >>> from zope.schema import Object
- >>> from zope.schema.fieldproperty import FieldProperty
- >>> from zope.location.interfaces import ILocation
- >>> from zope.location.location import Location
-
- >>> class IA(Interface):
- ... location = Object(schema=ILocation, required=False, default=None)
- >>> class A(object):
- ... implements(IA)
- ... location = FieldProperty(IA['location'])
-
- >>> a = A()
- >>> a.location = Location()
-
- >>> loc = Location(); loc.__name__ = u'foo'
- >>> a.location = loc
-
- >>> loc = Location(); loc.__name__ = None
- >>> a.location = loc
-
- >>> loc = Location(); loc.__name__ = 'foo'
- >>> a.location = loc
- Traceback (most recent call last):
- ...
- WrongContainedType: [foo <type 'unicode'>]
-
- """
-
zope.interface.implements(ILocation)
__parent__ = __name__ = None
+
def locate(object, parent, name=None):
"""Locate an object in another
@@ -71,38 +43,19 @@
object.__parent__ = parent
object.__name__ = name
+
def LocationIterator(object):
while object is not None:
yield object
object = getattr(object, '__parent__', None)
+
def inside(l1, l2):
"""Is l1 inside l2
L1 is inside l2 if l2 is an ancestor of l1.
- >>> o1 = Location()
- >>> o2 = Location(); o2.__parent__ = o1
- >>> o3 = Location(); o3.__parent__ = o2
- >>> o4 = Location(); o4.__parent__ = o3
-
- >>> inside(o1, o1)
- 1
- >>> inside(o2, o1)
- 1
- >>> inside(o3, o1)
- 1
- >>> inside(o4, o1)
- 1
-
- >>> inside(o1, o4)
- 0
-
- >>> inside(o1, None)
- 0
-
"""
-
while l1 is not None:
if l1 is l2:
return True
@@ -110,6 +63,7 @@
return False
+
class ClassAndInstanceDescr(object):
def __init__(self, *args):
@@ -120,32 +74,13 @@
return self.funcs[1](cls)
return self.funcs[0](inst)
+
class LocationProxy(ProxyBase):
- __doc__ = """Location-object proxy
+ """Location-object proxy
This is a non-picklable proxy that can be put around objects that
don't implement `ILocation`.
- >>> l = [1, 2, 3]
- >>> p = LocationProxy(l, "Dad", "p")
- >>> p
- [1, 2, 3]
- >>> p.__parent__
- 'Dad'
- >>> p.__name__
- 'p'
-
- >>> import pickle
- >>> p2 = pickle.dumps(p)
- Traceback (most recent call last):
- ...
- TypeError: Not picklable
-
- Proxies should get their doc strings from the object they proxy:
-
- >>> p.__doc__ == l.__doc__
- True
-
"""
zope.interface.implements(ILocation)
@@ -170,10 +105,9 @@
lambda inst: getProxiedObject(inst).__doc__,
lambda cls, __doc__ = __doc__: __doc__,
)
-
+
__reduce_ex__ = __reduce__
__providedBy__ = DecoratorSpecificationDescriptor()
__Security_checker__ = DecoratedSecurityCheckerDescriptor()
-
Modified: zope.location/trunk/src/zope/location/tests.py
===================================================================
--- zope.location/trunk/src/zope/location/tests.py 2007-08-17 10:04:02 UTC (rev 78899)
+++ zope.location/trunk/src/zope/location/tests.py 2007-08-17 11:48:00 UTC (rev 78900)
@@ -17,6 +17,7 @@
"""
import unittest
import zope.interface
+import zope.testing.doctest
from zope.traversing.interfaces import ITraverser
from zope.testing.doctestunit import DocTestSuite
from zope.location.location import Location
@@ -34,7 +35,7 @@
def test_suite():
return unittest.TestSuite((
- DocTestSuite('zope.location.location'),
+ zope.testing.doctest.DocFileSuite('location.txt'),
DocTestSuite('zope.location.traversing'),
DocTestSuite('zope.location.pickling'),
))
More information about the Checkins
mailing list