diff options
Diffstat (limited to 'tests/test_using.py')
-rw-r--r-- | tests/test_using.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/tests/test_using.py b/tests/test_using.py index 681daa9..7b8b3d6 100644 --- a/tests/test_using.py +++ b/tests/test_using.py @@ -21,9 +21,12 @@ """Tests using factory.""" -import factory +import functools import os import sys +import warnings + +import factory from .compat import unittest @@ -70,6 +73,15 @@ class TestModel(FakeModel): pass +def disable_warnings(fun): + @functools.wraps(fun) + def decorated(*args, **kwargs): + with warnings.catch_warnings(): + warnings.simplefilter('ignore') + return fun(*args, **kwargs) + return decorated + + class SimpleBuildTestCase(unittest.TestCase): """Tests the minimalist 'factory.build/create' functions.""" @@ -100,11 +112,13 @@ class SimpleBuildTestCase(unittest.TestCase): self.assertEqual(obj.three, 3) self.assertEqual(obj.four, None) + @disable_warnings def test_create(self): obj = factory.create(FakeModel, foo='bar') self.assertEqual(obj.id, 2) self.assertEqual(obj.foo, 'bar') + @disable_warnings def test_create_batch(self): objs = factory.create_batch(FakeModel, 4, foo='bar') @@ -135,6 +149,7 @@ class SimpleBuildTestCase(unittest.TestCase): self.assertEqual(obj.id, None) self.assertEqual(obj.foo, 'bar') + @disable_warnings def test_generate_create(self): obj = factory.generate(FakeModel, factory.CREATE_STRATEGY, foo='bar') self.assertEqual(obj.id, 2) @@ -155,6 +170,7 @@ class SimpleBuildTestCase(unittest.TestCase): self.assertEqual(obj.id, None) self.assertEqual(obj.foo, 'bar') + @disable_warnings def test_generate_batch_create(self): objs = factory.generate_batch(FakeModel, factory.CREATE_STRATEGY, 20, foo='bar') @@ -180,6 +196,7 @@ class SimpleBuildTestCase(unittest.TestCase): self.assertEqual(obj.id, None) self.assertEqual(obj.foo, 'bar') + @disable_warnings def test_simple_generate_create(self): obj = factory.simple_generate(FakeModel, True, foo='bar') self.assertEqual(obj.id, 2) @@ -195,6 +212,7 @@ class SimpleBuildTestCase(unittest.TestCase): self.assertEqual(obj.id, None) self.assertEqual(obj.foo, 'bar') + @disable_warnings def test_simple_generate_batch_create(self): objs = factory.simple_generate_batch(FakeModel, True, 20, foo='bar') @@ -623,6 +641,7 @@ class UsingFactoryTestCase(unittest.TestCase): self.assertEqual('three', obj.three) self.assertEqual('four', obj.four) + @disable_warnings def testSetCreationFunction(self): def creation_function(class_to_create, **kwargs): return "This doesn't even return an instance of {0}".format(class_to_create.__name__) |