summaryrefslogtreecommitdiff
path: root/factory/declarations.py
diff options
context:
space:
mode:
Diffstat (limited to 'factory/declarations.py')
-rw-r--r--factory/declarations.py29
1 files changed, 15 insertions, 14 deletions
diff --git a/factory/declarations.py b/factory/declarations.py
index 969d780..974b4ac 100644
--- a/factory/declarations.py
+++ b/factory/declarations.py
@@ -231,13 +231,17 @@ class ContainerAttribute(OrderedDeclaration):
return self.function(obj, containers)
-class SubFactory(OrderedDeclaration):
- """Base class for attributes based upon a sub-factory.
+class ParameteredAttribute(OrderedDeclaration):
+ """Base class for attributes expecting parameters.
Attributes:
- defaults (dict): Overrides to the defaults defined in the wrapped
- factory
- factory (base.Factory): the wrapped factory
+ defaults (dict): Default values for the paramters.
+ May be overridden by call-time parameters.
+
+ Class attributes:
+ CONTAINERS_FIELD (str): name of the field, if any, where container
+ information (e.g for SubFactory) should be stored. If empty,
+ containers data isn't merged into generate() parameters.
"""
CONTAINERS_FIELD = '__containers'
@@ -248,7 +252,6 @@ class SubFactory(OrderedDeclaration):
def __init__(self, **kwargs):
super(ParameteredAttribute, self).__init__()
self.defaults = kwargs
- self.factory = factory
def _prepare_containers(self, obj, containers=()):
if self.EXTEND_CONTAINERS:
@@ -260,19 +263,17 @@ class SubFactory(OrderedDeclaration):
"""Evaluate the current definition and fill its attributes.
Uses attributes definition in the following order:
- - attributes defined in the wrapped factory class
- - values defined when defining the SubFactory
- - additional values defined in attributes
+ - values defined when defining the ParameteredAttribute
+ - additional values defined when instantiating the containing factory
Args:
- create (bool): whether the subfactory should call 'build' or
- 'create'
+ create (bool): whether the parent factory is being 'built' or
+ 'created'
extra (containers.DeclarationDict): extra values that should
- override the wrapped factory's defaults
+ override the defaults
containers (list of LazyStub): List of LazyStub for the chain of
factories being evaluated, the calling stub being first.
"""
-
defaults = dict(self.defaults)
if extra:
defaults.update(extra)
@@ -393,7 +394,7 @@ class PostGenerationDeclaration(object):
kwargs = utils.extract_dict(name, attrs)
return extracted, kwargs
- def call(self, obj, create, extracted=None, **kwargs):
+ def call(self, obj, create, extracted=None, **kwargs): # pragma: no cover
"""Call this hook; no return value is expected.
Args: