From b832744b70ed811029edb045afc42ea307073c8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Barrois?= Date: Mon, 13 Jun 2011 11:33:37 +0200 Subject: Add a new type of attribute, SelfAttribute. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Should be used as a shortcut for 'lambda o: o.some_attr' ; most useful in SubFactories. Signed-off-by: Raphaƫl Barrois --- factory/declarations.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'factory/declarations.py') diff --git a/factory/declarations.py b/factory/declarations.py index 238e592..d827f30 100644 --- a/factory/declarations.py +++ b/factory/declarations.py @@ -62,6 +62,16 @@ class LazyAttribute(OrderedDeclaration): def evaluate(self, factory, attributes): return self.function(attributes) + +class SelfAttribute(OrderedDeclaration): + def __init__(self, attribute_name): + super(SelfAttribute, self).__init__() + self.attribute_name = attribute_name + + def evaluate(self, factory, attributes): + return getattr(attributes, self.attribute_name) + + class Sequence(OrderedDeclaration): def __init__(self, function, type=str): super(Sequence, self).__init__() -- cgit v1.2.3