Chris McDonough avatar Chris McDonough committed 0681066

add test for warn_deprecation

Comments (0)

Files changed (1)

tests/test_util.py

+import unittest
+
+class Test_warn_deprecation(unittest.TestCase):
+    def setUp(self):
+        import warnings
+        self.oldwarn = warnings.warn
+        warnings.warn = self._warn
+        self.warnings = []
+
+    def tearDown(self):
+        import warnings
+        warnings.warn = self.oldwarn
+        del self.warnings
+        
+    def _callFUT(self, text, version, stacklevel):
+        from webob.util import warn_deprecation
+        return warn_deprecation(text, version, stacklevel)
+
+    def _warn(self, text, type, stacklevel=1):
+        self.warnings.append(locals())
+
+    def test_not_1_2(self):
+        self._callFUT('text', 'version', 1)
+        self.assertEqual(len(self.warnings), 2)
+        unknown_version_warning = self.warnings[0]
+        self.assertEqual(unknown_version_warning['text'],
+                         "Unknown warn_deprecation version arg: 'version'")
+        self.assertEqual(unknown_version_warning['type'], RuntimeWarning)
+        self.assertEqual(unknown_version_warning['stacklevel'], 1)
+        deprecation_warning = self.warnings[1]
+        self.assertEqual(deprecation_warning['text'], 'text')
+        self.assertEqual(deprecation_warning['type'], DeprecationWarning)
+        self.assertEqual(deprecation_warning['stacklevel'], 2)
+        
+    def test_is_1_2(self):
+        self._callFUT('text', '1.2', 1)
+        self.assertEqual(len(self.warnings), 1)
+        deprecation_warning = self.warnings[0]
+        self.assertEqual(deprecation_warning['text'], 'text')
+        self.assertEqual(deprecation_warning['type'], DeprecationWarning)
+        self.assertEqual(deprecation_warning['stacklevel'], 2)
+        
+    
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.