Sergey Schetinin avatar Sergey Schetinin committed 79bbaa0

replace some verbose testing code with assert_raises, remove some ok_(...)

Comments (0)

Files changed (2)

tests/test_exc.py

-import webob
-import webob.exc
-import webob.dec
+import sys
+from webob import *
+from webob.dec import wsgify
+from webob.exc import *
 
-import sys
-
-@webob.dec.wsgify
+@wsgify
 def method_not_allowed_app(req):
     if req.method != 'GET':
         if sys.version_info > (2,5):
-            raise webob.exc.HTTPMethodNotAllowed()
+            raise HTTPMethodNotAllowed()
         else:
-            raise webob.exc.HTTPMethodNotAllowed().exception
+            raise HTTPMethodNotAllowed().exception
     return 'hello!'
 
 def test_exception_with_unicode_data():
-    req = webob.Request.blank('/', method=u'POST')
+    req = Request.blank('/', method=u'POST')
     res = req.get_response(method_not_allowed_app)
     assert res.status_int == 405
 
 def test_WSGIHTTPException_headers():
-    from webob.exc import WSGIHTTPException
     exc = WSGIHTTPException(headers=[('Set-Cookie', 'a=1'),
                                      ('Set-Cookie', 'a=2')])
     mixed = exc.headers.mixed()

tests/test_headers.py

 # -*- coding: UTF-8 -*-
 from webob import headers
-from nose.tools import ok_,assert_raises
+from nose.tools import ok_, assert_raises, eq_ as eq
 
 class TestError(Exception):
     pass
     """Testing set_default for ResponseHeaders"""
     d = headers.ResponseHeaders(a=1)
     res = d.setdefault('b', 1)
-    ok_(res==1 and d['b']==1)
+    assert res == d['b'] == 1
     res = d.setdefault('b', 10)
-    ok_(res==1 and d['b']==1)
+    assert res == d['b'] == 1
     res = d.setdefault('B', 10)
-    ok_(res==1 and d['b']==1 and 'B' in d and d['B']==1)
+    assert res == d['b'] == d['B'] == 1
 
 def test_pop():
     """Testing if pop return TypeError when more than len(*args)>1 plus other
     assorted tests"""
     d = headers.ResponseHeaders(a=1, b=2, c=3, d=4)
-    try:
-        d.pop('a', *('z', 'y'))
-        raise(TestError('We did not get an error'))
-    except TypeError, e:
-        ok_(e.args[0]=='pop expected at most 2 arguments, got 3', 'Did not '
-            'raise the expected error. We got %r' % e.args[0])
-    else:
-        raise(TestError('We did not get the expected error. We got %r' % \
-                        e.args[0]))
-    ok_(d.pop('a')==1 and 'a' not in d)
-    ok_(d.pop('B')==2 and 'b' not in d)
-    ok_(d.pop('c', *('u',))==3 and 'c' not in d)
-    ok_(d.pop('e', *('u',))=='u' and 'e' not in d)
-    try:
-        d.pop('z')
-        raise(TestError('We did not get an error'))
-    except KeyError, e:
-        ok_(e.args[0]=='z')
-    else:
-        raise(TestError('We did not get the expected error. We got %r' % \
-                        e.args[0]))
+    assert_raises(TypeError, d.pop, 'a', 'z', 'y')
+    assert d.pop('a') == 1
+    assert 'a' not in d
+    assert d.pop('B') == 2
+    assert 'b' not in d
+    assert d.pop('c', 'u') == 3
+    assert 'c' not in d
+    assert d.pop('e', 'u') =='u'
+    assert 'e' not in d
+    assert_raises(KeyError, d.pop, 'z')
 
-def  test_delitem_environheaders():
-    """The name of this method pretty much explains it all"""
-    d = headers.EnvironHeaders({'CONTENT_LENGTH':10})
+def test_delitem_environheaders():
+    d = headers.EnvironHeaders({'CONTENT_LENGTH': '10'})
     del d['CONTENT-LENGTH']
-    ok_('CONTENT-LENGTH' not in d)
-    ok_(len(d)==0)
+    assert not d
     assert_raises(KeyError, d.__delitem__, 'CONTENT-LENGTH')
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.