diff options
author | Carl Meyer <carl@oddbird.net> | 2012-01-11 14:11:45 -0700 |
---|---|---|
committer | Carl Meyer <carl@oddbird.net> | 2012-01-11 14:11:45 -0700 |
commit | 86393d4d1117426bc2aafbfb9f11f96c463f05f1 (patch) | |
tree | 6f84f9c1ded5beb90a87301d64b5e1180048ee28 | |
parent | 1d2ca8d02e190460f85d20be47bbb1e02f268bd2 (diff) | |
download | factory-boy-86393d4d1117426bc2aafbfb9f11f96c463f05f1.tar factory-boy-86393d4d1117426bc2aafbfb9f11f96c463f05f1.tar.gz |
Allow public classmethods on factories.
-rw-r--r-- | factory/containers.py | 4 | ||||
-rw-r--r-- | tests/test_containers.py | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/factory/containers.py b/factory/containers.py index e280162..9fe8e46 100644 --- a/factory/containers.py +++ b/factory/containers.py @@ -107,13 +107,13 @@ class DeclarationDict(dict): """Updates the DeclarationDict from a class definition dict. Takes into account all public attributes and OrderedDeclaration - instances; ignores all attributes starting with '_'. + instances; ignores all classmethods and attributes starting with '_'. Returns a dict containing all remaining elements. """ remaining = {} for k, v in d.iteritems(): - if k.startswith('_') and not isinstance(v, declarations.OrderedDeclaration): + if isinstance(v, classmethod) or k.startswith('_') and not isinstance(v, declarations.OrderedDeclaration): remaining[k] = v else: self[k] = v diff --git a/tests/test_containers.py b/tests/test_containers.py index 34b61d4..b9eaab6 100644 --- a/tests/test_containers.py +++ b/tests/test_containers.py @@ -134,7 +134,7 @@ class DeclarationDictTestCase(unittest.TestCase): def test_update_with_public(self): d = containers.DeclarationDict() - d.update_with_public({'one': 1, '_two': 2, 'three': 3}) + d.update_with_public({'one': 1, '_two': 2, 'three': 3, 'four': classmethod(lambda c: 1)}) self.assertEqual(set(['one', 'three']), set(d)) self.assertEqual(set([1, 3]), set(d.values())) |