From 4ffb26661eae4df640cc6f502b9090960283b860 Mon Sep 17 00:00:00 2001 From: Nick Johnson Date: Mon, 14 Sep 2009 21:43:00 +0100 Subject: [PATCH] Added doctests --- __init__.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/__init__.py b/__init__.py index a03ef60..84a212a 100644 --- a/__init__.py +++ b/__init__.py @@ -135,6 +135,19 @@ def __init__(self, property, *args, **kwargs): class KeyProperty(db.Property): """A property that stores a key, without automatically dereferencing it. + + Example usage: + + >>> class SampleModel(db.Model): + ... sample_key = KeyProperty() + + >>> model = SampleModel() + >>> model.sample_key = db.Key.from_path("Foo", "bar") + >>> model.put() # doctest: +ELLIPSIS + datastore_types.Key.from_path(u'SampleModel', ...) + + >>> model.sample_key # doctest: +ELLIPSIS + datastore_types.Key.from_path(u'Foo', u'bar', ...) """ def validate(self, value): """Validate the value. @@ -146,6 +159,8 @@ def validate(self, value): """ if isinstance(value, basestring): value = db.Key(value) - if value is not None and not isinstance(value, db.Key): - raise TypeError("Property %s must be an instance of db.Key" % self.name) + if value is not None: + if not isinstance(value, db.Key): + raise TypeError("Property %s must be an instance of db.Key" + % (self.name,)) return super(KeyProperty, self).validate(value)