summaryrefslogtreecommitdiff
path: root/tests/test_containers.py
diff options
context:
space:
mode:
authorHervé Cauwelier <herve.cauwelier@polyconseil.fr>2016-02-12 17:31:04 +0100
committerHervé Cauwelier <herve.cauwelier@polyconseil.fr>2016-02-12 17:31:04 +0100
commitf2c075c40fd331b7d26a9db72aad249b2165eac4 (patch)
tree9a9de1a7c1a608b40b2ec18610edad361be28602 /tests/test_containers.py
parent38f4a69db8f71cb52b9e7fd8d6e20e7d052a5b8d (diff)
downloadfactory-boy-f2c075c40fd331b7d26a9db72aad249b2165eac4.tar
factory-boy-f2c075c40fd331b7d26a9db72aad249b2165eac4.tar.gz
factory: LazyFunction to just call a function in the simplest case
No need to wrap it in a lambda to strip the object argument from LazyAttribute or the sequence argument from Sequence.
Diffstat (limited to 'tests/test_containers.py')
-rw-r--r--tests/test_containers.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/test_containers.py b/tests/test_containers.py
index 083b306..825e897 100644
--- a/tests/test_containers.py
+++ b/tests/test_containers.py
@@ -215,6 +215,29 @@ class AttributeBuilderTestCase(unittest.TestCase):
ab = containers.AttributeBuilder(FakeFactory, extra={'one': seq2})
self.assertEqual({'one': 'yy1'}, ab.build(create=False))
+ def test_lazy_function(self):
+ lf = declarations.LazyFunction(int)
+
+ class FakeFactory(object):
+ @classmethod
+ def declarations(cls, extra):
+ d = {'one': 1, 'two': lf}
+ d.update(extra)
+ return d
+
+ @classmethod
+ def _generate_next_sequence(cls):
+ return 1
+
+ ab = containers.AttributeBuilder(FakeFactory)
+ self.assertEqual({'one': 1, 'two': 0}, ab.build(create=False))
+
+ ab = containers.AttributeBuilder(FakeFactory, {'one': 4})
+ self.assertEqual({'one': 4, 'two': 0}, ab.build(create=False))
+
+ ab = containers.AttributeBuilder(FakeFactory, {'one': 4, 'three': lf})
+ self.assertEqual({'one': 4, 'two': 0, 'three': 0}, ab.build(create=False))
+
def test_lazy_attribute(self):
la = declarations.LazyAttribute(lambda a: a.one * 2)