From c1b42fd54b7670b829866d14221b4ab6cfcb1fba Mon Sep 17 00:00:00 2001 From: hut Date: Fri, 7 Oct 2011 21:32:16 +0200 Subject: ext.lazy_property: added doctest --- ranger/ext/lazy_property.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/ranger/ext/lazy_property.py b/ranger/ext/lazy_property.py index 320a1993..734d9616 100644 --- a/ranger/ext/lazy_property.py +++ b/ranger/ext/lazy_property.py @@ -4,12 +4,17 @@ class lazy_property(object): """ A @property-like decorator with lazy evaluation - Example: - class Foo: - @lazy_property - def bar(self): - result = [...] - return result + >>> class Foo: + ... @lazy_property + ... def answer(self): + ... print("calculating answer...") + ... return 2*3*7 + >>> foo = Foo() + >>> foo.answer + calculating answer... + 42 + >>> foo.answer + 42 """ def __init__(self, method): @@ -23,3 +28,7 @@ class lazy_property(object): result = self._method(obj) obj.__dict__[self.__name__] = result return result + +if __name__ == '__main__': + import doctest + doctest.testmod() -- cgit 1.4.1-2-gfad0