From 86393d4d1117426bc2aafbfb9f11f96c463f05f1 Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Wed, 11 Jan 2012 14:11:45 -0700 Subject: Allow public classmethods on factories. --- factory/containers.py | 4 ++-- 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())) -- cgit v1.2.3