summaryrefslogtreecommitdiff
path: root/factory/declarations.py
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polyconseil.fr>2011-09-06 17:18:00 +0200
committerRaphaël Barrois <raphael.barrois@polyconseil.fr>2011-09-06 17:18:00 +0200
commit41c68349cf3925818a6c05477790a2f67d431d39 (patch)
treeb3fe0111b500ec97b28f5c5badb9a4709ca9cc7e /factory/declarations.py
parentd17972e3e21c14ecca91e4238fa0726bd1a68a23 (diff)
downloadfactory-boy-41c68349cf3925818a6c05477790a2f67d431d39.tar
factory-boy-41c68349cf3925818a6c05477790a2f67d431d39.tar.gz
Rewrite all the 'OrderedDeclaration' part.
Signed-off-by: Raphaël Barrois <raphael.barrois@polyconseil.fr>
Diffstat (limited to 'factory/declarations.py')
-rw-r--r--factory/declarations.py41
1 files changed, 8 insertions, 33 deletions
diff --git a/factory/declarations.py b/factory/declarations.py
index a1e9102..f1112c5 100644
--- a/factory/declarations.py
+++ b/factory/declarations.py
@@ -18,37 +18,12 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
-import threading
-
-global_counter_lock = threading.Lock()
-
-class GlobalCounter(object):
- """A simple global counter.
-
- It is used to order the various OrderedDeclaration together.
- """
-
- _value = 0
-
- @classmethod
- def step(cls):
- with global_counter_lock:
- current = cls._value
- cls._value += 1
- return current
-
-
class OrderedDeclaration(object):
"""A factory declaration.
Ordered declarations keep track of the order in which they're defined so that later declarations
can refer to attributes created by earlier declarations when the declarations are evaluated."""
- _next_order = 0
-
- def __init__(self):
- self.order = GlobalCounter.step()
-
- def evaluate(self, factory, obj):
+ def evaluate(self, sequence, obj):
"""Evaluate this declaration.
Args:
@@ -64,7 +39,7 @@ class LazyAttribute(OrderedDeclaration):
super(LazyAttribute, self).__init__()
self.function = function
- def evaluate(self, factory, obj):
+ def evaluate(self, sequence, obj):
return self.function(obj)
@@ -73,7 +48,7 @@ class SelfAttribute(OrderedDeclaration):
super(SelfAttribute, self).__init__()
self.attribute_name = attribute_name
- def evaluate(self, factory, obj):
+ def evaluate(self, sequence, obj):
return getattr(obj, self.attribute_name)
@@ -83,13 +58,13 @@ class Sequence(OrderedDeclaration):
self.function = function
self.type = type
- def evaluate(self, factory, obj):
- return self.function(self.type(factory.sequence))
+ def evaluate(self, sequence, obj):
+ return self.function(self.type(sequence))
class LazyAttributeSequence(Sequence):
- def evaluate(self, factory, obj):
- return self.function(obj, self.type(factory.sequence))
+ def evaluate(self, sequence, obj):
+ return self.function(obj, self.type(sequence))
class SubFactory(OrderedDeclaration):
@@ -105,7 +80,7 @@ class SubFactory(OrderedDeclaration):
self.defaults = kwargs
self.factory = factory
- def evaluate(self, factory, create, extra):
+ def evaluate(self, create, extra):
"""Evaluate the current definition and fill its attributes.
Uses attributes definition in the following order: