[Checkins] SVN: zope.location/trunk/src/zope/location/location.txt moving tests to .txt file

Christian Zagrodnick cz at gocept.com
Fri Aug 17 07:48:11 EDT 2007


Log message for revision 78901:
  moving tests to .txt file

Changed:
  A   zope.location/trunk/src/zope/location/location.txt

-=-
Added: zope.location/trunk/src/zope/location/location.txt
===================================================================
--- zope.location/trunk/src/zope/location/location.txt	                        (rev 0)
+++ zope.location/trunk/src/zope/location/location.txt	2007-08-17 11:48:10 UTC (rev 78901)
@@ -0,0 +1,96 @@
+========
+Location
+========
+
+Location Base Class
+===================
+
+
+The `Location` base class is a 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'>]
+
+
+The `insde` Function
+====================
+
+The `inside` function tells if l1 is 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
+
+>>> from zope.location.location import inside
+>>> inside(o1, o1)
+1
+>>> inside(o2, o1)
+1
+>>> inside(o3, o1)
+1
+>>> inside(o4, o1)
+1
+
+>>> inside(o1, o4)
+0
+
+>>> inside(o1, None)
+0
+
+
+LocationProxy
+=============
+    
+The LocationProxy is a non-picklable proxy that can be put around objects that
+don't implement `ILocation`.
+
+>>> from zope.location.location import LocationProxy
+>>> 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
+


Property changes on: zope.location/trunk/src/zope/location/location.txt
___________________________________________________________________
Name: svn:keywords
   + Id Rev Date
Name: svn:eol-style
   + native



More information about the Checkins mailing list