Commits

Gael Pasgrimaud committed b75282e

always use unittest2

Comments (0)

Files changed (10)

     def u(value):
         return unicode(value, 'utf-8')
 
+def raises(exc, func, *args, **kw):
+    try:
+        func(*args, **kw)
+    except exc:
+        pass
+    else:
+        raise AssertionError(
+            "Expected exception %s from %s"
+            % (exc, func))
+

tests/test_click.py

 import webtest
 from webtest.app import _parse_attrs
 from webob import Request
-from tests.test_testing import raises
-
-try:
-    unicode()
-except NameError:
-    u = str
-else:
-    def u(value):
-        return unicode(value, 'utf-8')
+from tests.compat import unittest
+from tests.compat import u
 
 
 def links_app(environ, start_response):
     start_response(status, headers)
     return [body]
 
+class TestClick(unittest.TestCase):
 
-def test_click():
-    app = webtest.TestApp(links_app)
-    assert('This is foo.' in app.get('/').click('Foo'))
-    assert('This is foobar.' in app.get('/').click('Foo').click('Bar'))
-    assert('This is bar.' in app.get('/').click('Bar'))
-    assert('This is baz.' in app.get('/').click('Baz')) # should skip non-clickable links
-    assert('This is baz.' in app.get('/').click(linkid='id_baz'))
-    assert('This is baz.' in app.get('/').click(href='baz/'))
-    assert('This is baz.' in app.get('/').click(anchor="<a href='baz/' id='id_baz'>Baz</a>"))
-    assert('This is spam.' in app.get('/').click('Click me!', index=0))
-    assert('Just eggs.' in app.get('/').click('Click me!', index=1))
+    def test_click(self):
+        app = webtest.TestApp(links_app)
+        self.assertIn('This is foo.', app.get('/').click('Foo'))
+        self.assertIn('This is foobar.', app.get('/').click('Foo').click('Bar'))
+        self.assertIn('This is bar.', app.get('/').click('Bar'))
+        self.assertIn('This is baz.', app.get('/').click('Baz')) # should skip non-clickable links
+        self.assertIn('This is baz.', app.get('/').click(linkid='id_baz'))
+        self.assertIn('This is baz.', app.get('/').click(href='baz/'))
+        self.assertIn('This is baz.', app.get('/').click(anchor="<a href='baz/' id='id_baz'>Baz</a>"))
+        self.assertIn('This is spam.', app.get('/').click('Click me!', index=0))
+        self.assertIn('Just eggs.', app.get('/').click('Click me!', index=1))
 
-    def multiple_links():
-        app.get('/').click('Click me!')
-    raises(IndexError, multiple_links)
+        def multiple_links():
+            app.get('/').click('Click me!')
+        self.assertRaises(IndexError, multiple_links)
 
-    def invalid_index():
-        app.get('/').click('Click me!', index=2)
-    raises(IndexError, invalid_index)
+        def invalid_index():
+            app.get('/').click('Click me!', index=2)
+        self.assertRaises(IndexError, invalid_index)
 
-    def no_links_found():
-        app.get('/').click('Ham')
-    raises(IndexError, no_links_found)
+        def no_links_found():
+            app.get('/').click('Ham')
+        self.assertRaises(IndexError, no_links_found)
 
-    def tag_inside_script():
-        app.get('/').click('Boo')
-    raises(IndexError, tag_inside_script)
+        def tag_inside_script():
+            app.get('/').click('Boo')
+        self.assertRaises(IndexError, tag_inside_script)
 
 
-def test_click_utf8():
-    app = webtest.TestApp(links_app, use_unicode=False)
-    resp = app.get('/utf8/')
-    assert(resp.charset == 'utf-8')
-    assert(u("Тестовая страница").encode('utf8') in resp)
-    assert(u("Тестовая страница") in resp)
-    assert('This is foo.' in resp.click(u('Менделеев').encode('utf8')))
+    def test_click_utf8(self):
+        app = webtest.TestApp(links_app, use_unicode=False)
+        resp = app.get('/utf8/')
+        self.assertEqual(resp.charset, 'utf-8')
+        self.assertIn(u("Тестовая страница").encode('utf8'), resp)
+        self.assertIn(u("Тестовая страница"), resp)
+        self.assertIn('This is foo.', resp.click(u('Менделеев').encode('utf8')))
 
-    # should skip the img tag
-    anchor_re = u(".*title='Поэт'.*").encode('utf8')
-    assert('This is baz.' in resp.click(anchor=anchor_re))
+        # should skip the img tag
+        anchor_re = u(".*title='Поэт'.*").encode('utf8')
+        self.assertIn('This is baz.', resp.click(anchor=anchor_re))
 
 
-def test_click_u():
-    app = webtest.TestApp(links_app)
-    resp = app.get('/utf8/')
+    def test_click_u(self):
+        app = webtest.TestApp(links_app)
+        resp = app.get('/utf8/')
 
-    assert(u("Тестовая страница") in resp)
-    assert('This is foo.' in resp.click(u('Менделеев')))
-    assert('This is baz.' in resp.click(anchor=u(".*title='Поэт'.*")))
+        self.assertIn(u("Тестовая страница"), resp)
+        self.assertIn('This is foo.', resp.click(u('Менделеев')))
+        self.assertIn('This is baz.', resp.click(anchor=u(".*title='Поэт'.*")))
 
 
-def test_parse_attrs():
-    assert(_parse_attrs("href='foo'") == {'href': 'foo'})
-    assert(_parse_attrs('href="foo"') == {'href': 'foo'})
-    assert(_parse_attrs('href=""') == {'href': ''})
-    assert(_parse_attrs('href="foo" id="bar"') == {'href': 'foo', 'id': 'bar'})
-    assert(_parse_attrs('href="foo" id="bar"') == {'href': 'foo', 'id': 'bar'})
-    assert(_parse_attrs("href='foo' id=\"bar\" ") == {'href': 'foo', 'id': 'bar'})
-    assert(_parse_attrs("href='foo' id='bar' ") == {'href': 'foo', 'id': 'bar'})
-    assert(_parse_attrs("tag='foo\"'") == {'tag': 'foo"'})
+    def test_parse_attrs(self):
+        self.assertEqual(_parse_attrs("href='foo'"), {'href': 'foo'})
+        self.assertEqual(_parse_attrs('href="foo"'), {'href': 'foo'})
+        self.assertEqual(_parse_attrs('href=""'), {'href': ''})
+        self.assertEqual(_parse_attrs('href="foo" id="bar"'), {'href': 'foo', 'id': 'bar'})
+        self.assertEqual(_parse_attrs('href="foo" id="bar"'), {'href': 'foo', 'id': 'bar'})
+        self.assertEqual(_parse_attrs("href='foo' id=\"bar\" "), {'href': 'foo', 'id': 'bar'})
+        self.assertEqual(_parse_attrs("href='foo' id='bar' "), {'href': 'foo', 'id': 'bar'})
+        self.assertEqual(_parse_attrs("tag='foo\"'"), {'tag': 'foo"'})

tests/test_cookie.py

 import webtest
 from webob import Request
+from tests.compat import unittest
 
 
 def cookie_app(environ, start_response):
     start_response(status, headers)
     return [body]
 
-
-def test_cookies():
-    app = webtest.TestApp(cookie_app)
-    assert(not app.cookies, 'App should initially contain no cookies')
-    res = app.get('/')
-    cookies = app.cookies
-    assert(cookies, 'Response should have set cookies')
-    assert(cookies['spam'] == 'eggs')
-    assert(cookies['foo'] == 'bar;baz')
-
-
-def test_preserve_cookies():
-    app = webtest.TestApp(cookie_app)
-    res = app.get('/')
-    assert(app.cookies)
-    go_page = res.click('go')
-    assert(app.cookies)
-
-
 def cookie_app2(environ, start_response):
     status = '200 OK'
     body = ''
     start_response(status, headers)
     return [body]
 
+class TestCookies(unittest.TestCase):
 
-def test_cookies2():
-    app = webtest.TestApp(cookie_app)
-    assert(not app.cookies, 'App should initially contain no cookies')
+    def test_cookies(self):
+        app = webtest.TestApp(cookie_app)
+        self.assertTrue(not app.cookies, 'App should initially contain no cookies')
+        res = app.get('/')
+        cookies = app.cookies
+        self.assert_(cookies, 'Response should have set cookies')
+        self.assertEqual(cookies['spam'], 'eggs')
+        self.assertEqual(cookies['foo'], 'bar;baz')
 
-    res = app.get('/')
-    assert(app.cookies, 'Response should have set cookies')
-    assert(app.cookies['spam'] == 'eggs')
-    assert(app.cookies['foo'] == 'bar;baz')
+
+    def test_preserve_cookies(self):
+        app = webtest.TestApp(cookie_app)
+        res = app.get('/')
+        self.assert_(app.cookies)
+        go_page = res.click('go')
+        self.assert_(app.cookies)
+
+
+
+    def test_cookies2(self):
+        app = webtest.TestApp(cookie_app)
+        self.assertTrue(not app.cookies, 'App should initially contain no cookies')
+
+        res = app.get('/')
+        self.assert_(app.cookies, 'Response should have set cookies')
+        self.assertIn(app.cookies['spam'], 'eggs')
+        self.assertIn(app.cookies['foo'], 'bar;baz')

tests/test_extra_environ.py

 import webtest
 from webtest.debugapp import debug_app
+from tests.compat import unittest
 
+class TestEnviron(unittest.TestCase):
 
-def test_get_extra_environ():
-    app = webtest.TestApp(debug_app,
-                          extra_environ={'HTTP_ACCEPT_LANGUAGE': 'ru',
-                                         'foo': 'bar'})
-    res = app.get('http://localhost/')
-    assert('HTTP_ACCEPT_LANGUAGE: ru' in res, res)
-    assert("foo: 'bar'" in res, res)
+    def test_get_extra_environ(self):
+        app = webtest.TestApp(debug_app,
+                              extra_environ={'HTTP_ACCEPT_LANGUAGE': 'ru',
+                                             'foo': 'bar'})
+        res = app.get('http://localhost/')
+        self.assertIn('HTTP_ACCEPT_LANGUAGE: ru', res, res)
+        self.assertIn("foo: 'bar'", res, res)
 
-    res = app.get('http://localhost/', extra_environ={'foo': 'baz'})
-    assert('HTTP_ACCEPT_LANGUAGE: ru' in res, res)
-    assert("foo: 'baz'" in res, res)
+        res = app.get('http://localhost/', extra_environ={'foo': 'baz'})
+        self.assertIn('HTTP_ACCEPT_LANGUAGE: ru', res, res)
+        self.assertIn("foo: 'baz'", res, res)
 
 
-def test_post_extra_environ():
-    app = webtest.TestApp(debug_app,
-                          extra_environ={'HTTP_ACCEPT_LANGUAGE': 'ru',
-                                         'foo': 'bar'})
-    res = app.post('http://localhost/')
-    assert('HTTP_ACCEPT_LANGUAGE: ru' in res, res)
-    assert("foo: 'bar'" in res, res)
+    def test_post_extra_environ(self):
+        app = webtest.TestApp(debug_app,
+                              extra_environ={'HTTP_ACCEPT_LANGUAGE': 'ru',
+                                             'foo': 'bar'})
+        res = app.post('http://localhost/')
+        self.assertIn('HTTP_ACCEPT_LANGUAGE: ru', res, res)
+        self.assertIn("foo: 'bar'", res, res)
 
-    res = app.post('http://localhost/', extra_environ={'foo': 'baz'})
-    assert('HTTP_ACCEPT_LANGUAGE: ru' in res, res)
-    assert("foo: 'baz'" in res, res)
+        res = app.post('http://localhost/', extra_environ={'foo': 'baz'})
+        self.assertIn('HTTP_ACCEPT_LANGUAGE: ru', res, res)
+        self.assertIn("foo: 'baz'", res, res)
 
 
-def test_request_extra_environ():
-    app = webtest.TestApp(debug_app,
-                          extra_environ={'HTTP_ACCEPT_LANGUAGE': 'ru',
-                                         'foo': 'bar'})
-    res = app.request('http://localhost/', method='GET')
-    assert('HTTP_ACCEPT_LANGUAGE: ru' in res, res)
-    assert("foo: 'bar'" in res, res)
+    def test_request_extra_environ(self):
+        app = webtest.TestApp(debug_app,
+                              extra_environ={'HTTP_ACCEPT_LANGUAGE': 'ru',
+                                             'foo': 'bar'})
+        res = app.request('http://localhost/', method='GET')
+        self.assertIn('HTTP_ACCEPT_LANGUAGE: ru', res, res)
+        self.assertIn("foo: 'bar'", res, res)
 
-    res = app.request('http://localhost/', method='GET', environ={'foo': 'baz'})
-    assert('HTTP_ACCEPT_LANGUAGE: ru' in res, res)
-    assert("foo: 'baz'" in res, res)
+        res = app.request('http://localhost/', method='GET',
+                                               environ={'foo': 'baz'})
+        self.assertIn('HTTP_ACCEPT_LANGUAGE: ru', res, res)
+        self.assertIn("foo: 'baz'", res, res)

tests/test_file_upload.py

 import os.path
 import struct
+from tests.compat import unittest
 
 from webob import Request
 import webtest
     start_response(status, headers)
     return [body]
 
+class TestFileUpload(unittest.TestCase):
 
-def test_no_uploads_error():
-    app = webtest.TestApp(single_upload_file_app)
-    uploads = app.get('/').forms["file_upload_form"].upload_fields()
+    def test_no_uploads_error(self):
+        app = webtest.TestApp(single_upload_file_app)
+        uploads = app.get('/').forms["file_upload_form"].upload_fields()
 
 
-def test_upload_without_file():
-    app = webtest.TestApp(single_upload_file_app)
-    upload_form = app.get('/').forms["file_upload_form"]
-    upload_form.submit()
+    def test_upload_without_file(self):
+        app = webtest.TestApp(single_upload_file_app)
+        upload_form = app.get('/').forms["file_upload_form"]
+        upload_form.submit()
 
 
-def test_file_upload_with_filename_only():
-    uploaded_file_name = \
-        os.path.join(os.path.dirname(__file__), "__init__.py")
-    uploaded_file_contents = file(uploaded_file_name).read()
+    def test_file_upload_with_filename_only(self):
+        uploaded_file_name = \
+            os.path.join(os.path.dirname(__file__), "__init__.py")
+        uploaded_file_contents = file(uploaded_file_name).read()
 
-    app = webtest.TestApp(single_upload_file_app)
-    res = app.get('/')
-    assert(res.status_int == 200)
-    assert(res.headers['content-type'] == 'text/html; charset=utf-8')
-    assert(res.content_type == 'text/html')
-    assert(res.charset == 'utf-8')
+        app = webtest.TestApp(single_upload_file_app)
+        res = app.get('/')
+        self.assertEqual(res.status_int, 200)
+        self.assertEqual(res.headers['content-type'], 'text/html; charset=utf-8')
+        self.assertEqual(res.content_type, 'text/html')
+        self.assertEqual(res.charset, 'utf-8')
 
-    single_form = res.forms["file_upload_form"]
-    single_form.set("file-field", (uploaded_file_name,))
-    display = single_form.submit("button")
-    assert("<p>You selected '%s'</p>" % uploaded_file_name in display, display)
-    assert("<p>with contents: '%s'</p>" % uploaded_file_contents in display, \
-        display)
+        single_form = res.forms["file_upload_form"]
+        single_form.set("file-field", (uploaded_file_name,))
+        display = single_form.submit("button")
+        self.assertIn("<p>You selected '%s'</p>" % uploaded_file_name, display, display)
+        self.assertIn("<p>with contents: '%s'</p>" % uploaded_file_contents, display, \
+            display)
 
 
-def test_file_upload_with_filename_and_contents():
-    uploaded_file_name = \
-        os.path.join(os.path.dirname(__file__), "__init__.py")
-    uploaded_file_contents = file(uploaded_file_name).read()
+    def test_file_upload_with_filename_and_contents(self):
+        uploaded_file_name = \
+            os.path.join(os.path.dirname(__file__), "__init__.py")
+        uploaded_file_contents = file(uploaded_file_name).read()
 
-    app = webtest.TestApp(single_upload_file_app)
-    res = app.get('/')
-    assert(res.status_int == 200)
-    assert(res.headers['content-type'] == 'text/html; charset=utf-8')
-    assert(res.content_type == 'text/html')
+        app = webtest.TestApp(single_upload_file_app)
+        res = app.get('/')
+        self.assertEqual(res.status_int, 200)
+        self.assertEqual(res.headers['content-type'], 'text/html; charset=utf-8')
+        self.assertEqual(res.content_type, 'text/html')
 
-    single_form = res.forms["file_upload_form"]
-    single_form.set("file-field",
-                    (uploaded_file_name, uploaded_file_contents))
-    display = single_form.submit("button")
-    assert("<p>You selected '%s'</p>" % uploaded_file_name in display, display)
-    assert("<p>with contents: '%s'</p>" % uploaded_file_contents in display, \
-        display)
+        single_form = res.forms["file_upload_form"]
+        single_form.set("file-field",
+                        (uploaded_file_name, uploaded_file_contents))
+        display = single_form.submit("button")
+        self.assertIn("<p>You selected '%s'</p>" % uploaded_file_name, display, display)
+        self.assertIn("<p>with contents: '%s'</p>" % uploaded_file_contents, display, \
+            display)
 
 
-def test_file_upload_binary():
-    binary_data = struct.pack('255h', *range(0,255))
-    app = webtest.TestApp(upload_binary_app)
-    res = app.get('/')
-    single_form = res.forms["binary_upload_form"]
-    single_form.set("binary-file-field", ('my_file.dat', binary_data))
-    display = single_form.submit("button")
-    assert(','.join([str(n) for n in range(0,255)]) in display, display)
+    def test_file_upload_binary(self):
+        binary_data = struct.pack('255h', *range(0,255))
+        app = webtest.TestApp(upload_binary_app)
+        res = app.get('/')
+        single_form = res.forms["binary_upload_form"]
+        single_form.set("binary-file-field", ('my_file.dat', binary_data))
+        display = single_form.submit("button")
+        self.assertIn(','.join([str(n) for n in range(0,255)]), display)
 
 
-def test_multiple_file_uploads_with_filename_and_contents():
-    uploaded_file1_name = \
-        os.path.join(os.path.dirname(__file__), "__init__.py")
-    uploaded_file1_contents = file(uploaded_file1_name).read()
-    uploaded_file2_name = \
-        os.path.join(os.path.dirname(__file__), "test_input.py")
-    uploaded_file2_contents = file(uploaded_file2_name).read()
+    def test_multiple_file_uploads_with_filename_and_contents(self):
+        uploaded_file1_name = \
+            os.path.join(os.path.dirname(__file__), "__init__.py")
+        uploaded_file1_contents = file(uploaded_file1_name).read()
+        uploaded_file2_name = \
+            os.path.join(os.path.dirname(__file__), "test_input.py")
+        uploaded_file2_contents = file(uploaded_file2_name).read()
 
-    app = webtest.TestApp(multiple_upload_file_app)
-    res = app.get('/')
-    assert(res.status_int == 200)
-    assert(res.headers['content-type'] == 'text/html; charset=utf-8')
-    assert(res.content_type == 'text/html')
+        app = webtest.TestApp(multiple_upload_file_app)
+        res = app.get('/')
+        self.assertEqual(res.status_int, 200)
+        self.assertEqual(res.headers['content-type'], 'text/html; charset=utf-8')
+        self.assertEqual(res.content_type, 'text/html')
 
-    single_form = res.forms["file_upload_form"]
-    single_form.set("file-field-1", (uploaded_file1_name, uploaded_file1_contents))
-    single_form.set("file-field-2", (uploaded_file2_name, uploaded_file2_contents))
-    display = single_form.submit("button")
-    assert("<p>You selected '%s'</p>" % uploaded_file1_name in display, display)
-    assert("<p>with contents: '%s'</p>" % uploaded_file1_contents in display, \
-        display)
-    assert("<p>You selected '%s'</p>" % uploaded_file2_name in display, display)
-    assert("<p>with contents: '%s'</p>" % uploaded_file2_contents in display, \
-        display)
+        single_form = res.forms["file_upload_form"]
+        single_form.set("file-field-1", (uploaded_file1_name, uploaded_file1_contents))
+        single_form.set("file-field-2", (uploaded_file2_name, uploaded_file2_contents))
+        display = single_form.submit("button")
+        self.assertIn("<p>You selected '%s'</p>" % uploaded_file1_name, display, display)
+        self.assertIn("<p>with contents: '%s'</p>" % uploaded_file1_contents, display, \
+            display)
+        self.assertIn("<p>You selected '%s'</p>" % uploaded_file2_name, display, display)
+        self.assertIn("<p>with contents: '%s'</p>" % uploaded_file2_contents, display, \
+            display)

tests/test_fragments.py

 
 import webtest
 from webtest.debugapp import debug_app
+from tests.compat import unittest
 
-def raises(exc, func, *args, **kw):
-    try:
-        func(*args, **kw)
-    except exc:
-        pass
-    else:
-        raise AssertionError(
-            "Expected exception %s from %s"
-            % (exc, func))
+class TestFragemts(unittest.TestCase):
 
-def test_url_without_fragments():
-    app = webtest.TestApp(debug_app)
-    res = app.get('http://localhost/')
-    assert(res.status_int == 200)
+    def test_url_without_fragments(self):
+        app = webtest.TestApp(debug_app)
+        res = app.get('http://localhost/')
+        self.assertEqual(res.status_int, 200)
 
-def test_url_with_fragments():
-    app = webtest.TestApp(debug_app)
-    res = app.get('http://localhost/#ananchor')
-    assert(res.status_int == 200)
+    def test_url_with_fragments(self):
+        app = webtest.TestApp(debug_app)
+        res = app.get('http://localhost/#ananchor')
+        self.assertEqual(res.status_int, 200)

tests/test_input.py

 # -*- coding: utf-8 -*-
 from webob import Request
 import webtest
-import unittest
+from tests.compat import unittest
+from tests.compat import u
 
-try:
-    unicode()
-except NameError:
-    u = str
-else:
-    def u(value):
-        return unicode(value, 'utf-8')
 
 def input_app(environ, start_response):
     req = Request(environ)
     start_response(status, headers)
     return [body]
 
+class TestInput(unittest.TestCase):
 
-def test_input():
-    app = webtest.TestApp(input_app)
-    res = app.get('/')
-    assert(res.status_int == 200)
-    assert(res.headers['content-type'] == 'text/html')
-    assert(res.content_type == 'text/html')
+    def test_input(self):
+        app = webtest.TestApp(input_app)
+        res = app.get('/')
+        self.assertEqual(res.status_int, 200)
+        self.assertEqual(res.headers['content-type'], 'text/html')
+        self.assertEqual(res.content_type, 'text/html')
 
-    form = res.forms['text_input_form']
-    assert(form['foo'].value == 'bar')
-    assert(form.submit_fields() == [('foo', 'bar')])
+        form = res.forms['text_input_form']
+        self.assertEqual(form['foo'].value, 'bar')
+        self.assertEqual(form.submit_fields(), [('foo', 'bar')])
 
-    form = res.forms['radio_input_form']
-    assert(form['foo'].value == 'baz')
-    assert(form.submit_fields() == [('foo', 'baz')])
+        form = res.forms['radio_input_form']
+        self.assertEqual(form['foo'].value, 'baz')
+        self.assertEqual(form.submit_fields(), [('foo', 'baz')])
 
-    form = res.forms['checkbox_input_form']
-    assert(form['foo'].value == 'bar')
-    assert(form.submit_fields() == [('foo', 'bar')])
+        form = res.forms['checkbox_input_form']
+        self.assertEqual(form['foo'].value, 'bar')
+        self.assertEqual(form.submit_fields(), [('foo', 'bar')])
 
 
-def test_input_unicode():
-    app = webtest.TestApp(input_unicode_app)
-    res = app.get('/')
-    assert(res.status_int == 200)
-    assert(res.content_type == 'text/html')
-    assert(res.charset == 'utf-8')
+    def test_input_unicode(self):
+        app = webtest.TestApp(input_unicode_app)
+        res = app.get('/')
+        self.assertEqual(res.status_int, 200)
+        self.assertEqual(res.content_type, 'text/html')
+        self.assertEqual(res.charset, 'utf-8')
 
-    form = res.forms['text_input_form']
-    assert(form['foo'].value == u('Хармс'))
-    assert(form.submit_fields() == [('foo', u('Хармс'))])
+        form = res.forms['text_input_form']
+        self.assertEqual(form['foo'].value, u('Хармс'))
+        self.assertEqual(form.submit_fields(), [('foo', u('Хармс'))])
 
-    form = res.forms['radio_input_form']
-    assert(form['foo'].value == u('Блок'))
-    assert(form.submit_fields() == [('foo', u('Блок'))])
+        form = res.forms['radio_input_form']
+        self.assertEqual(form['foo'].value, u('Блок'))
+        self.assertEqual(form.submit_fields(), [('foo', u('Блок'))])
 
-    form = res.forms['checkbox_input_form']
-    assert(form['foo'].value == u('Хармс'))
-    assert(form.submit_fields() == [('foo', u('Хармс'))])
+        form = res.forms['checkbox_input_form']
+        self.assertEqual(form['foo'].value, u('Хармс'))
+        self.assertEqual(form.submit_fields(), [('foo', u('Хармс'))])
 
 
-def test_input_no_default():
-    app = webtest.TestApp(input_app_without_default)
-    res = app.get('/')
-    assert(res.status_int == 200)
-    assert(res.headers['content-type'] == 'text/html')
-    assert(res.content_type == 'text/html')
+    def test_input_no_default(self):
+        app = webtest.TestApp(input_app_without_default)
+        res = app.get('/')
+        self.assertEqual(res.status_int, 200)
+        self.assertEqual(res.headers['content-type'], 'text/html')
+        self.assertEqual(res.content_type, 'text/html')
 
-    form = res.forms['text_input_form']
-    assert(form['foo'].value == '')
-    assert(form.submit_fields() == [('foo', '')])
+        form = res.forms['text_input_form']
+        self.assertEqual(form['foo'].value, '')
+        self.assertEqual(form.submit_fields(), [('foo', '')])
 
-    form = res.forms['radio_input_form']
-    assert(form['foo'].value is None)
-    assert(form.submit_fields() == [])
+        form = res.forms['radio_input_form']
+        self.assertTrue(form['foo'].value is None)
+        self.assertEqual(form.submit_fields(), [])
 
-    form = res.forms['checkbox_input_form']
-    assert(form['foo'].value is None)
-    assert(form.submit_fields() == [])
+        form = res.forms['checkbox_input_form']
+        self.assertTrue(form['foo'].value is None)
+        self.assertEqual(form.submit_fields(), [])
 
 
 class TestFormLint(unittest.TestCase):

tests/test_script_name.py

 # -*- coding: utf-8 -*-
 import webtest
 from webob import Request, Response, exc
+from tests.compat import unittest
 
 def application(environ, start_response):
     req = Request(environ)
         resp.body = '<html><body><a href="%s">link</a></body></html>' % req.path
     return resp(environ, start_response)
 
-def test_script_name():
-    app = webtest.TestApp(application)
+class TestScriptName(unittest.TestCase):
 
-    resp = app.get('/script', extra_environ={'SCRIPT_NAME':'/script'})
-    resp.mustcontain('href="/script"')
+    def test_script_name(self):
+        app = webtest.TestApp(application)
 
-    resp = app.get('/script/redirect', extra_environ={'SCRIPT_NAME':'/script'})
-    assert(resp.status_int == 302)
-    assert(resp.location == 'http://localhost/script/path', resp.location)
+        resp = app.get('/script', extra_environ={'SCRIPT_NAME':'/script'})
+        resp.mustcontain('href="/script"')
 
-    resp = resp.follow(extra_environ={'SCRIPT_NAME':'/script'})
-    resp.mustcontain('href="/script/path"')
-    resp = resp.click('link')
-    resp.mustcontain('href="/script/path"')
+        resp = app.get('/script/redirect', extra_environ={'SCRIPT_NAME':'/script'})
+        self.assertEqual(resp.status_int, 302)
+        self.assertEqual(resp.location, 'http://localhost/script/path', resp.location)
 
-def test_app_script_name():
-    app = webtest.TestApp(application, extra_environ={'SCRIPT_NAME':'/script'})
-    resp = app.get('/script/redirect')
-    assert(resp.status_int == 302)
-    assert(resp.location == 'http://localhost/script/path', resp.location)
+        resp = resp.follow(extra_environ={'SCRIPT_NAME':'/script'})
+        resp.mustcontain('href="/script/path"')
+        resp = resp.click('link')
+        resp.mustcontain('href="/script/path"')
 
-    resp = resp.follow()
-    resp.mustcontain('href="/script/path"')
-    resp = resp.click('link')
-    resp.mustcontain('href="/script/path"')
+    def test_app_script_name(self):
+        app = webtest.TestApp(application, extra_environ={'SCRIPT_NAME':'/script'})
+        resp = app.get('/script/redirect')
+        self.assertEqual(resp.status_int, 302)
+        self.assertEqual(resp.location, 'http://localhost/script/path', resp.location)
 
-def test_script_name_doesnt_match():
-    app = webtest.TestApp(application)
-    resp = app.get('/path', extra_environ={'SCRIPT_NAME':'/script'})
-    resp.mustcontain('href="/script/path"')
+        resp = resp.follow()
+        resp.mustcontain('href="/script/path"')
+        resp = resp.click('link')
+        resp.mustcontain('href="/script/path"')
 
+    def test_script_name_doesnt_match(self):
+        app = webtest.TestApp(application)
+        resp = app.get('/path', extra_environ={'SCRIPT_NAME':'/script'})
+        resp.mustcontain('href="/script/path"')
+

tests/test_select.py

 # -*- coding: utf-8 -*-
 from webob import Request
 import webtest
-
-try:
-    unicode()
-except NameError:
-    u = str
-else:
-    def u(value):
-        return unicode(value, 'utf-8')
+from tests.compat import unittest
+from tests.compat import u
 
 def select_app(environ, start_response):
     req = Request(environ)
         ('Content-Type', 'text/html; charset=utf-8'),
         ('Content-Length', str(len(body)))]
     start_response(status, headers)
-    assert(isinstance(body, str))
+    if not isinstance(body, str):
+        raise AssertionError('Body is not str')
     return [body]
 
+class TestSelect(unittest.TestCase):
 
+    def test_unicode_select(self):
+        app = webtest.TestApp(select_app_unicode)
+        res = app.get('/')
+        single_form = res.forms["single_select_form"]
+        self.assertEqual(single_form["single"].value, u("МСК"))
 
-def test_unicode_select():
-    app = webtest.TestApp(select_app_unicode)
-    res = app.get('/')
-    single_form = res.forms["single_select_form"]
-    assert(single_form["single"].value == u("МСК"))
+        display = single_form.submit("button")
+        self.assertIn(u("<p>You selected МСК</p>"), display, display)
 
-    display = single_form.submit("button")
-    assert(u("<p>You selected МСК</p>") in display, display)
+        res = app.get('/')
+        single_form = res.forms["single_select_form"]
+        self.assertEqual(single_form["single"].value, u("МСК"))
+        single_form.set("single", u("СПБ"))
+        self.assertEqual(single_form["single"].value, u("СПБ"))
+        display = single_form.submit("button")
+        self.assertIn(u("<p>You selected СПБ</p>"), display, display)
 
-    res = app.get('/')
-    single_form = res.forms["single_select_form"]
-    assert(single_form["single"].value == u("МСК"))
-    single_form.set("single", u("СПБ"))
-    assert(single_form["single"].value == u("СПБ"))
-    display = single_form.submit("button")
-    assert(u("<p>You selected СПБ</p>") in display, display)
 
 
+    def test_single_select(self):
+        app = webtest.TestApp(select_app)
+        res = app.get('/')
+        self.assertEqual(res.status_int, 200)
+        self.assertEqual(res.headers['content-type'], 'text/html; charset=utf-8')
+        self.assertEqual(res.content_type, 'text/html')
 
-def test_single_select():
-    app = webtest.TestApp(select_app)
-    res = app.get('/')
-    assert(res.status_int == 200)
-    assert(res.headers['content-type'] == 'text/html; charset=utf-8')
-    assert(res.content_type == 'text/html')
+        single_form = res.forms["single_select_form"]
+        self.assertEqual(single_form["single"].value, "5")
+        display = single_form.submit("button")
+        self.assertIn("<p>You selected 5</p>", display, display)
 
-    single_form = res.forms["single_select_form"]
-    assert(single_form["single"].value == "5")
-    display = single_form.submit("button")
-    assert("<p>You selected 5</p>" in display, display)
+        res = app.get('/')
+        self.assertEqual(res.status_int, 200)
+        self.assertEqual(res.headers['content-type'], 'text/html; charset=utf-8')
+        self.assertEqual(res.content_type, 'text/html')
 
-    res = app.get('/')
-    assert(res.status_int == 200)
-    assert(res.headers['content-type'] == 'text/html; charset=utf-8')
-    assert(res.content_type == 'text/html')
+        single_form = res.forms["single_select_form"]
+        self.assertEqual(single_form["single"].value, "5")
+        single_form.set("single", "6")
+        self.assertEqual(single_form["single"].value, "6")
+        display = single_form.submit("button")
+        self.assertIn("<p>You selected 6</p>", display, display)
 
-    single_form = res.forms["single_select_form"]
-    assert(single_form["single"].value == "5")
-    single_form.set("single", "6")
-    assert(single_form["single"].value == "6")
-    display = single_form.submit("button")
-    assert("<p>You selected 6</p>" in display, display)
+    def test_single_select_forced_value(self):
+        app = webtest.TestApp(select_app)
+        res = app.get('/')
+        self.assertEqual(res.status_int, 200)
+        self.assertEqual(res.headers['content-type'], 'text/html; charset=utf-8')
+        self.assertEqual(res.content_type, 'text/html')
 
-def test_single_select_forced_value():
-    app = webtest.TestApp(select_app)
-    res = app.get('/')
-    assert(res.status_int == 200)
-    assert(res.headers['content-type'] == 'text/html; charset=utf-8')
-    assert(res.content_type == 'text/html')
+        single_form = res.forms["single_select_form"]
+        self.assertEqual(single_form["single"].value, "5")
+        try:
+            single_form.set("single", "984")
+            self.assertTrue(False, "not-an-option value error should have been raised")
+        except ValueError:
+            pass
+        single_form["single"].force_value("984")
+        self.assertEqual(single_form["single"].value, "984")
+        display = single_form.submit("button")
+        self.assertIn("<p>You selected 984</p>", display, display)
 
-    single_form = res.forms["single_select_form"]
-    assert(single_form["single"].value == "5")
-    try:
-        single_form.set("single", "984")
-        assert(False, "not-an-option value error should have been raised")
-    except ValueError:
-        pass
-    single_form["single"].force_value("984")
-    assert(single_form["single"].value == "984")
-    display = single_form.submit("button")
-    assert("<p>You selected 984</p>" in display, display)
+    def test_single_select_no_default(self):
+        app = webtest.TestApp(select_app_without_default)
+        res = app.get('/')
+        self.assertEqual(res.status_int, 200)
+        self.assertEqual(res.headers['content-type'], 'text/html; charset=utf-8')
+        self.assertEqual(res.content_type, 'text/html')
 
-def test_single_select_no_default():
-    app = webtest.TestApp(select_app_without_default)
-    res = app.get('/')
-    assert(res.status_int == 200)
-    assert(res.headers['content-type'] == 'text/html; charset=utf-8')
-    assert(res.content_type == 'text/html')
+        single_form = res.forms["single_select_form"]
+        self.assertEqual(single_form["single"].value, "4")
+        display = single_form.submit("button")
+        self.assertIn("<p>You selected 4</p>", display, display)
 
-    single_form = res.forms["single_select_form"]
-    assert(single_form["single"].value == "4")
-    display = single_form.submit("button")
-    assert("<p>You selected 4</p>" in display, display)
+        res = app.get('/')
+        self.assertEqual(res.status_int, 200)
+        self.assertEqual(res.headers['content-type'], 'text/html; charset=utf-8')
+        self.assertEqual(res.content_type, 'text/html')
 
-    res = app.get('/')
-    assert(res.status_int == 200)
-    assert(res.headers['content-type'] == 'text/html; charset=utf-8')
-    assert(res.content_type == 'text/html')
+        single_form = res.forms["single_select_form"]
+        self.assertEqual(single_form["single"].value, "4")
+        single_form.set("single", 6)
+        self.assertEqual(single_form["single"].value, "6")
+        display = single_form.submit("button")
+        self.assertIn("<p>You selected 6</p>", display, display)
 
-    single_form = res.forms["single_select_form"]
-    assert(single_form["single"].value == "4")
-    single_form.set("single", 6)
-    assert(single_form["single"].value == "6")
-    display = single_form.submit("button")
-    assert("<p>You selected 6</p>" in display, display)
+    def test_multiple_select(self):
+        app = webtest.TestApp(select_app)
+        res = app.get('/')
+        self.assertEqual(res.status_int, 200)
+        self.assertEqual(res.headers['content-type'], 'text/html; charset=utf-8')
+        self.assertEqual(res.content_type, 'text/html')
 
-def test_multiple_select():
-    app = webtest.TestApp(select_app)
-    res = app.get('/')
-    assert(res.status_int == 200)
-    assert(res.headers['content-type'] == 'text/html; charset=utf-8')
-    assert(res.content_type == 'text/html')
+        multiple_form = res.forms["multiple_select_form"]
+        self.assertEqual(multiple_form["multiple"].value, ['8', '11'],\
+            multiple_form["multiple"].value)
+        display = multiple_form.submit("button")
+        self.assertIn("<p>You selected 8, 11</p>", display, display)
 
-    multiple_form = res.forms["multiple_select_form"]
-    assert(multiple_form["multiple"].value == ['8', '11'],\
-        multiple_form["multiple"].value)
-    display = multiple_form.submit("button")
-    assert("<p>You selected 8, 11</p>" in display, display)
+        res = app.get('/')
+        self.assertEqual(res.status_int, 200)
+        self.assertEqual(res.headers['content-type'], 'text/html; charset=utf-8')
+        self.assertEqual(res.content_type, 'text/html')
 
-    res = app.get('/')
-    assert(res.status_int == 200)
-    assert(res.headers['content-type'] == 'text/html; charset=utf-8')
-    assert(res.content_type == 'text/html')
+        multiple_form = res.forms["multiple_select_form"]
+        self.assertEqual(multiple_form["multiple"].value, ["8", "11"],\
+            multiple_form["multiple"].value)
+        multiple_form.set("multiple", ["9"])
+        self.assertEqual(multiple_form["multiple"].value, ["9"],\
+            multiple_form["multiple"].value)
+        display = multiple_form.submit("button")
+        self.assertIn("<p>You selected 9</p>", display, display)
 
-    multiple_form = res.forms["multiple_select_form"]
-    assert(multiple_form["multiple"].value == ["8", "11"],\
-        multiple_form["multiple"].value)
-    multiple_form.set("multiple", ["9"])
-    assert(multiple_form["multiple"].value == ["9"],\
-        multiple_form["multiple"].value)
-    display = multiple_form.submit("button")
-    assert("<p>You selected 9</p>" in display, display)
+    def test_multiple_select_forced_values(self):
+        app = webtest.TestApp(select_app)
+        res = app.get('/')
+        self.assertEqual(res.status_int, 200)
+        self.assertEqual(res.headers['content-type'], 'text/html; charset=utf-8')
+        self.assertEqual(res.content_type, 'text/html')
 
-def test_multiple_select_forced_values():
-    app = webtest.TestApp(select_app)
-    res = app.get('/')
-    assert(res.status_int == 200)
-    assert(res.headers['content-type'] == 'text/html; charset=utf-8')
-    assert(res.content_type == 'text/html')
+        multiple_form = res.forms["multiple_select_form"]
+        self.assertEqual(multiple_form["multiple"].value, ["8", "11"],\
+            multiple_form["multiple"].value)
+        try:
+            multiple_form.set("multiple", ["24", "88"])
+            self.assertTrue(False, "not-an-option value error should have been raised")
+        except ValueError:
+            pass
+        multiple_form["multiple"].force_value(["24", "88"])
+        self.assertEqual(multiple_form["multiple"].value, ["24", "88"],\
+            multiple_form["multiple"].value)
+        display = multiple_form.submit("button")
+        self.assertIn("<p>You selected 24, 88</p>", display, display)
 
-    multiple_form = res.forms["multiple_select_form"]
-    assert(multiple_form["multiple"].value == ["8", "11"],\
-        multiple_form["multiple"].value)
-    try:
-        multiple_form.set("multiple", ["24", "88"])
-        assert(False, "not-an-option value error should have been raised")
-    except ValueError:
-        pass
-    multiple_form["multiple"].force_value(["24", "88"])
-    assert(multiple_form["multiple"].value == ["24", "88"],\
-        multiple_form["multiple"].value)
-    display = multiple_form.submit("button")
-    assert("<p>You selected 24, 88</p>" in display, display)
+    def test_multiple_select_no_default(self):
+        app = webtest.TestApp(select_app_without_default)
+        res = app.get('/')
+        self.assertEqual(res.status_int, 200)
+        self.assertEqual(res.headers['content-type'], 'text/html; charset=utf-8')
+        self.assertEqual(res.content_type, 'text/html')
 
-def test_multiple_select_no_default():
-    app = webtest.TestApp(select_app_without_default)
-    res = app.get('/')
-    assert(res.status_int == 200)
-    assert(res.headers['content-type'] == 'text/html; charset=utf-8')
-    assert(res.content_type == 'text/html')
+        multiple_form = res.forms["multiple_select_form"]
+        self.assertTrue(multiple_form["multiple"].value is None,\
+            repr(multiple_form["multiple"].value))
+        display = multiple_form.submit("button")
+        self.assertIn("<p>You selected </p>", display, display)
 
-    multiple_form = res.forms["multiple_select_form"]
-    assert(multiple_form["multiple"].value is None,\
-        repr(multiple_form["multiple"].value))
-    display = multiple_form.submit("button")
-    assert("<p>You selected </p>" in display, display)
+        res = app.get('/')
+        self.assertEqual(res.status_int, 200)
+        self.assertEqual(res.headers['content-type'], 'text/html; charset=utf-8')
+        self.assertEqual(res.content_type, 'text/html')
 
-    res = app.get('/')
-    assert(res.status_int == 200)
-    assert(res.headers['content-type'] == 'text/html; charset=utf-8')
-    assert(res.content_type == 'text/html')
-
-    multiple_form = res.forms["multiple_select_form"]
-    assert(multiple_form["multiple"].value is None,\
-        multiple_form["multiple"].value)
-    multiple_form.set("multiple", ["9"])
-    assert(multiple_form["multiple"].value == ["9"],\
-        multiple_form["multiple"].value)
-    display = multiple_form.submit("button")
-    assert("<p>You selected 9</p>" in display, display)
+        multiple_form = res.forms["multiple_select_form"]
+        self.assertTrue(multiple_form["multiple"].value is None,\
+            multiple_form["multiple"].value)
+        multiple_form.set("multiple", ["9"])
+        self.assertEqual(multiple_form["multiple"].value, ["9"],\
+            multiple_form["multiple"].value)
+        display = multiple_form.submit("button")
+        self.assertIn("<p>You selected 9</p>", display, display)

tests/test_testing.py

 from webtest.debugapp import debug_app
 from tests.compat import unittest
 
-def raises(exc, func, *args, **kw):
-    try:
-        func(*args, **kw)
-    except exc:
-        pass
-    else:
-        raise AssertionError(
-            "Expected exception %s from %s"
-            % (exc, func))
-
 class TestTesting(unittest.TestCase):
 
     def setUp(self):