From 99ffa8c49df4baa9681d649ce0b19b6d3b5ad99a Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Thu, 12 Jan 2012 09:01:46 -0700 Subject: Added support for staticmethods on factories as well. --- factory/containers.py | 2 +- tests/test_containers.py | 8 +++++++- tests/test_using.py | 8 ++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/factory/containers.py b/factory/containers.py index 847b2c0..68e1e9f 100644 --- a/factory/containers.py +++ b/factory/containers.py @@ -112,7 +112,7 @@ class DeclarationDict(dict): is private (name starts with '_') or a classmethod or staticmethod. """ - if isinstance(value, classmethod): + if isinstance(value, (classmethod, staticmethod)): return False elif isinstance(value, declarations.OrderedDeclaration): return True diff --git a/tests/test_containers.py b/tests/test_containers.py index b4c5c52..effb060 100644 --- a/tests/test_containers.py +++ b/tests/test_containers.py @@ -159,7 +159,13 @@ class DeclarationDictTestCase(unittest.TestCase): def test_update_with_public(self): d = containers.DeclarationDict() - d.update_with_public({'one': 1, '_two': 2, 'three': 3, 'four': classmethod(lambda c: 1)}) + d.update_with_public({ + 'one': 1, + '_two': 2, + 'three': 3, + 'classmethod': classmethod(lambda c: 1), + 'staticmethod': staticmethod(lambda: 1), + }) self.assertEqual(set(['one', 'three']), set(d)) self.assertEqual(set([1, 3]), set(d.values())) diff --git a/tests/test_using.py b/tests/test_using.py index 4256cc3..d1e4262 100644 --- a/tests/test_using.py +++ b/tests/test_using.py @@ -288,6 +288,14 @@ class FactoryTestCase(unittest.TestCase): self.assertEqual(TestObjectFactory.alt_create(foo=1), {"foo": 1}) + def testStaticMethodAccessible(self): + class TestObjectFactory(factory.Factory): + @staticmethod + def alt_create(**kwargs): + return kwargs + + self.assertEqual(TestObjectFactory.alt_create(foo=1), {"foo": 1}) + class SubFactoryTestCase(unittest.TestCase): def testSubFactory(self): -- cgit v1.2.3