summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2013-03-03 18:05:17 +0100
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2013-03-03 21:38:46 +0100
commitaa900c9f00d6777b57440e660e24df1a15f2f20e (patch)
tree0c188028b9b0d7c1f6de8619c89e1f1000a01d3b
parentebdfb8cc5bab1e59b593a4ea60e55b9e7af455ef (diff)
downloadfactory-boy-aa900c9f00d6777b57440e660e24df1a15f2f20e.tar
factory-boy-aa900c9f00d6777b57440e660e24df1a15f2f20e.tar.gz
Tests: move disable_warnings to its own class.
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
-rw-r--r--tests/test_using.py32
-rw-r--r--tests/tools.py36
2 files changed, 48 insertions, 20 deletions
diff --git a/tests/test_using.py b/tests/test_using.py
index fb8c207..2bab8c0 100644
--- a/tests/test_using.py
+++ b/tests/test_using.py
@@ -29,6 +29,7 @@ import warnings
import factory
from .compat import is_python2, unittest
+from . import tools
class TestObject(object):
@@ -73,15 +74,6 @@ 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."""
@@ -112,13 +104,13 @@ class SimpleBuildTestCase(unittest.TestCase):
self.assertEqual(obj.three, 3)
self.assertEqual(obj.four, None)
- @disable_warnings
+ @tools.disable_warnings
def test_create(self):
obj = factory.create(FakeModel, foo='bar')
self.assertEqual(obj.id, 2)
self.assertEqual(obj.foo, 'bar')
- @disable_warnings
+ @tools.disable_warnings
def test_create_batch(self):
objs = factory.create_batch(FakeModel, 4, foo='bar')
@@ -149,7 +141,7 @@ class SimpleBuildTestCase(unittest.TestCase):
self.assertEqual(obj.id, None)
self.assertEqual(obj.foo, 'bar')
- @disable_warnings
+ @tools.disable_warnings
def test_generate_create(self):
obj = factory.generate(FakeModel, factory.CREATE_STRATEGY, foo='bar')
self.assertEqual(obj.id, 2)
@@ -170,7 +162,7 @@ class SimpleBuildTestCase(unittest.TestCase):
self.assertEqual(obj.id, None)
self.assertEqual(obj.foo, 'bar')
- @disable_warnings
+ @tools.disable_warnings
def test_generate_batch_create(self):
objs = factory.generate_batch(FakeModel, factory.CREATE_STRATEGY, 20, foo='bar')
@@ -196,7 +188,7 @@ class SimpleBuildTestCase(unittest.TestCase):
self.assertEqual(obj.id, None)
self.assertEqual(obj.foo, 'bar')
- @disable_warnings
+ @tools.disable_warnings
def test_simple_generate_create(self):
obj = factory.simple_generate(FakeModel, True, foo='bar')
self.assertEqual(obj.id, 2)
@@ -212,7 +204,7 @@ class SimpleBuildTestCase(unittest.TestCase):
self.assertEqual(obj.id, None)
self.assertEqual(obj.foo, 'bar')
- @disable_warnings
+ @tools.disable_warnings
def test_simple_generate_batch_create(self):
objs = factory.simple_generate_batch(FakeModel, True, 20, foo='bar')
@@ -668,7 +660,7 @@ class UsingFactoryTestCase(unittest.TestCase):
self.assertEqual('three', obj.three)
self.assertEqual('four', obj.four)
- @disable_warnings
+ @tools.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__)
@@ -1090,7 +1082,7 @@ class IteratorTestCase(unittest.TestCase):
self.assertIn('InfiniteIterator', str(w[0].message))
self.assertIn('deprecated', str(w[0].message))
- @disable_warnings
+ @tools.disable_warnings
def test_infinite_iterator(self):
class TestObjectFactory(factory.Factory):
FACTORY_FOR = TestObject
@@ -1103,7 +1095,7 @@ class IteratorTestCase(unittest.TestCase):
self.assertEqual(i % 5, obj.one)
@unittest.skipUnless(is_python2, "Scope bleeding fixed in Python3+")
- @disable_warnings
+ @tools.disable_warnings
def test_infinite_iterator_list_comprehension_scope_bleeding(self):
class TestObjectFactory(factory.Factory):
FACTORY_FOR = TestObject
@@ -1114,7 +1106,7 @@ class IteratorTestCase(unittest.TestCase):
self.assertRaises(TypeError, TestObjectFactory.build)
- @disable_warnings
+ @tools.disable_warnings
def test_infinite_iterator_list_comprehension_protected(self):
class TestObjectFactory(factory.Factory):
FACTORY_FOR = TestObject
@@ -1158,7 +1150,7 @@ class IteratorTestCase(unittest.TestCase):
self.assertIn('infinite_iterator', str(w[0].message))
self.assertIn('deprecated', str(w[0].message))
- @disable_warnings
+ @tools.disable_warnings
def test_infinite_iterator_decorator(self):
class TestObjectFactory(factory.Factory):
FACTORY_FOR = TestObject
diff --git a/tests/tools.py b/tests/tools.py
new file mode 100644
index 0000000..571899b
--- /dev/null
+++ b/tests/tools.py
@@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2010 Mark Sandstrom
+# Copyright (c) 2011-2013 Raphaël Barrois
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+
+
+import functools
+import warnings
+
+
+def disable_warnings(fun):
+ @functools.wraps(fun)
+ def decorated(*args, **kwargs):
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore')
+ return fun(*args, **kwargs)
+ return decorated
+
+