1. Ian Bicking
  2. WebOb

Commits

Sergey Schetinin  committed f2fa749

attempt to silence deprecation warnings during testing

  • Participants
  • Parent commits e61ed6d
  • Branches default

Comments (0)

Files changed (5)

File docs/test_request.txt

View file
  • Ignore whitespace
 This demonstrates how the Request object works, and tests it.
 
-To test for absense of PendingDeprecationWarning's we should reset
-default warning filters
-
-    >>> import warnings
-    >>> warnings.resetwarnings()
-
-
 You can instantiate a request using ``Request.blank()``, to create a
 fresh environment dictionary with all the basic keys such a dictionary
 should have.

File tests/test_misc.py

View file
  • Ignore whitespace
     eq(ub.getall('key'), [u'\xf8'])
     eq(repr(ub.getall('fs')), "[FieldStorage(None, u'\\xf8', [])]")
 
-def test_multidict_update_warning():
-    fcapture = StringIO()
-    stderr, sys.stderr = sys.stderr, fcapture
-
-    # test warning when duplicate keys are passed
-    r = Response()
-    r.headers.update([
-        ('Set-Cookie', 'a=b'),
-        ('Set-Cookie', 'x=y'),
-    ])
-    fcapture.seek(0)
-    assert 'Consider using .extend()' in fcapture.readline()
-
-    # but no warning on normal operation
-    fcapture.seek(0)
-    fcapture.truncate()
-    r.headers.update([('Set-Cookie', 'a=b')])
-    assert not fcapture.getvalue()
-
-    sys.stderr = stderr

File tests/test_request.py

View file
  • Ignore whitespace
 
 _marker = object()
 
+warnings.showwarning = lambda *args, **kw: None
+
 class BaseRequestTests(unittest.TestCase):
     def _makeStringIO(self, text):
         try:

File tests/test_util.py

View file
  • Ignore whitespace
 import unittest
+from webob import Request, Response
 
 class Test_warn_deprecation(unittest.TestCase):
     def setUp(self):
         self.assertEqual(deprecation_warning['type'], DeprecationWarning)
 
     def test_decode_param_names_attr(self):
-        from webob import Request
         class BadRequest(Request):
             decode_param_names = False
         req = BadRequest.blank('?a=b')
         self.assertEqual(len(self.warnings), 1)
         deprecation_warning = self.warnings[0]
         self.assertEqual(deprecation_warning['type'], DeprecationWarning)
+
+    def test_multidict_update_warning(self):
+        # test warning when duplicate keys are passed
+        r = Response()
+        r.headers.update([
+            ('Set-Cookie', 'a=b'),
+            ('Set-Cookie', 'x=y'),
+        ])
+        self.assertEqual(len(self.warnings), 1)
+        deprecation_warning = self.warnings[0]
+        self.assertEqual(deprecation_warning['type'], UserWarning)
+        assert 'Consider using .extend()' in deprecation_warning['text']
+
+    def test_multidict_update_warning_unnecessary(self):
+        # no warning on normal operation
+        r = Response()
+        r.headers.update([('Set-Cookie', 'a=b')])
+        self.assertEqual(len(self.warnings), 0)

File webob/multidict.py

View file
  • Ignore whitespace
                 msg = ("Behavior of MultiDict.update() has changed "
                     "and overwrites duplicate keys. Consider using .extend()"
                 )
-                warnings.warn(msg, stacklevel=2)
+                warnings.warn(msg, UserWarning, stacklevel=2)
         DictMixin.update(self, *args, **kw)
 
     def extend(self, other=None, **kwargs):