summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorKevin L. Mitchell <kevin.mitchell@rackspace.com>2012-01-10 11:22:33 -0600
committerKevin L. Mitchell <kevin.mitchell@rackspace.com>2012-01-10 11:22:33 -0600
commit8e2d6abc28cf749baed1ce545b09a1c5520b93eb (patch)
tree918d69239bb85eabe52b2b6a3ad8b18aefc07b72 /nova/tests
parent799801f856a0f3e7788e89ecdca02828fd64e6ad (diff)
Add @utils.deprecated().
This will allow us to mark deprecated classes and functions/methods as such. A warning is issued each time a deprecated function/method is called, or when a deprecated class is instantiated, or when any class or static method on a deprecated class is called. Change-Id: I4b5858492bc14768ac2e12c542bc343962761e34
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/test_utils.py110
1 files changed, 110 insertions, 0 deletions
diff --git a/nova/tests/test_utils.py b/nova/tests/test_utils.py
index d221212df..7062097ff 100644
--- a/nova/tests/test_utils.py
+++ b/nova/tests/test_utils.py
@@ -535,3 +535,113 @@ class MonkeyPatchTestCase(test.TestCase):
in nova.tests.monkey_patch_example.CALLED_FUNCTION)
self.assertFalse(package_b + 'ExampleClassB.example_method_add'
in nova.tests.monkey_patch_example.CALLED_FUNCTION)
+
+
+class DeprecationTest(test.TestCase):
+ def setUp(self):
+ super(DeprecationTest, self).setUp()
+
+ def fake_warn_deprecated_class(cls, msg):
+ self.warn = ('class', cls, msg)
+
+ def fake_warn_deprecated_function(func, msg):
+ self.warn = ('function', func, msg)
+
+ self.stubs.Set(utils, 'warn_deprecated_class',
+ fake_warn_deprecated_class)
+ self.stubs.Set(utils, 'warn_deprecated_function',
+ fake_warn_deprecated_function)
+ self.warn = None
+
+ def test_deprecated_function_no_message(self):
+ def test_function():
+ pass
+
+ decorated = utils.deprecated()(test_function)
+
+ decorated()
+ self.assertEqual(self.warn, ('function', test_function, ''))
+
+ def test_deprecated_function_with_message(self):
+ def test_function():
+ pass
+
+ decorated = utils.deprecated('string')(test_function)
+
+ decorated()
+ self.assertEqual(self.warn, ('function', test_function, 'string'))
+
+ def test_deprecated_class_no_message(self):
+ @utils.deprecated()
+ class TestClass(object):
+ pass
+
+ TestClass()
+ self.assertEqual(self.warn, ('class', TestClass, ''))
+
+ def test_deprecated_class_with_message(self):
+ @utils.deprecated('string')
+ class TestClass(object):
+ pass
+
+ TestClass()
+ self.assertEqual(self.warn, ('class', TestClass, 'string'))
+
+ def test_deprecated_classmethod_no_message(self):
+ @utils.deprecated()
+ class TestClass(object):
+ @classmethod
+ def class_method(cls):
+ pass
+
+ TestClass.class_method()
+ self.assertEqual(self.warn, ('class', TestClass, ''))
+
+ def test_deprecated_classmethod_with_message(self):
+ @utils.deprecated('string')
+ class TestClass(object):
+ @classmethod
+ def class_method(cls):
+ pass
+
+ TestClass.class_method()
+ self.assertEqual(self.warn, ('class', TestClass, 'string'))
+
+ def test_deprecated_staticmethod_no_message(self):
+ @utils.deprecated()
+ class TestClass(object):
+ @staticmethod
+ def static_method():
+ pass
+
+ TestClass.static_method()
+ self.assertEqual(self.warn, ('class', TestClass, ''))
+
+ def test_deprecated_staticmethod_with_message(self):
+ @utils.deprecated('string')
+ class TestClass(object):
+ @staticmethod
+ def static_method():
+ pass
+
+ TestClass.static_method()
+ self.assertEqual(self.warn, ('class', TestClass, 'string'))
+
+ def test_deprecated_instancemethod(self):
+ @utils.deprecated()
+ class TestClass(object):
+ def instance_method(self):
+ pass
+
+ # Instantiate the class...
+ obj = TestClass()
+ self.assertEqual(self.warn, ('class', TestClass, ''))
+
+ # Reset warn...
+ self.warn = None
+
+ # Call the instance method...
+ obj.instance_method()
+
+ # Make sure that did *not* generate a warning
+ self.assertEqual(self.warn, None)