From aa900c9f00d6777b57440e660e24df1a15f2f20e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Barrois?= Date: Sun, 3 Mar 2013 18:05:17 +0100 Subject: Tests: move disable_warnings to its own class. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Raphaƫl Barrois --- tests/test_using.py | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'tests/test_using.py') 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 -- cgit v1.2.3