mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
Various tests cleanup: check_warnings/check_py3k_warnings, unittest.assert* and setUp/tearDown.
This commit is contained in:
parent
4854c969fb
commit
bc27c6a5aa
10 changed files with 89 additions and 91 deletions
|
@ -103,42 +103,42 @@ class BaseHTTPServerTestCase(BaseTestCase):
|
|||
def test_command(self):
|
||||
self.con.request('GET', '/')
|
||||
res = self.con.getresponse()
|
||||
self.assertEquals(res.status, 501)
|
||||
self.assertEqual(res.status, 501)
|
||||
|
||||
def test_request_line_trimming(self):
|
||||
self.con._http_vsn_str = 'HTTP/1.1\n'
|
||||
self.con.putrequest('GET', '/')
|
||||
self.con.endheaders()
|
||||
res = self.con.getresponse()
|
||||
self.assertEquals(res.status, 501)
|
||||
self.assertEqual(res.status, 501)
|
||||
|
||||
def test_version_bogus(self):
|
||||
self.con._http_vsn_str = 'FUBAR'
|
||||
self.con.putrequest('GET', '/')
|
||||
self.con.endheaders()
|
||||
res = self.con.getresponse()
|
||||
self.assertEquals(res.status, 400)
|
||||
self.assertEqual(res.status, 400)
|
||||
|
||||
def test_version_digits(self):
|
||||
self.con._http_vsn_str = 'HTTP/9.9.9'
|
||||
self.con.putrequest('GET', '/')
|
||||
self.con.endheaders()
|
||||
res = self.con.getresponse()
|
||||
self.assertEquals(res.status, 400)
|
||||
self.assertEqual(res.status, 400)
|
||||
|
||||
def test_version_none_get(self):
|
||||
self.con._http_vsn_str = ''
|
||||
self.con.putrequest('GET', '/')
|
||||
self.con.endheaders()
|
||||
res = self.con.getresponse()
|
||||
self.assertEquals(res.status, 501)
|
||||
self.assertEqual(res.status, 501)
|
||||
|
||||
def test_version_none(self):
|
||||
self.con._http_vsn_str = ''
|
||||
self.con.putrequest('PUT', '/')
|
||||
self.con.endheaders()
|
||||
res = self.con.getresponse()
|
||||
self.assertEquals(res.status, 400)
|
||||
self.assertEqual(res.status, 400)
|
||||
|
||||
def test_version_invalid(self):
|
||||
self.con._http_vsn = 99
|
||||
|
@ -146,21 +146,21 @@ class BaseHTTPServerTestCase(BaseTestCase):
|
|||
self.con.putrequest('GET', '/')
|
||||
self.con.endheaders()
|
||||
res = self.con.getresponse()
|
||||
self.assertEquals(res.status, 505)
|
||||
self.assertEqual(res.status, 505)
|
||||
|
||||
def test_send_blank(self):
|
||||
self.con._http_vsn_str = ''
|
||||
self.con.putrequest('', '')
|
||||
self.con.endheaders()
|
||||
res = self.con.getresponse()
|
||||
self.assertEquals(res.status, 400)
|
||||
self.assertEqual(res.status, 400)
|
||||
|
||||
def test_header_close(self):
|
||||
self.con.putrequest('GET', '/')
|
||||
self.con.putheader('Connection', 'close')
|
||||
self.con.endheaders()
|
||||
res = self.con.getresponse()
|
||||
self.assertEquals(res.status, 501)
|
||||
self.assertEqual(res.status, 501)
|
||||
|
||||
def test_head_keep_alive(self):
|
||||
self.con._http_vsn_str = 'HTTP/1.1'
|
||||
|
@ -168,28 +168,28 @@ class BaseHTTPServerTestCase(BaseTestCase):
|
|||
self.con.putheader('Connection', 'keep-alive')
|
||||
self.con.endheaders()
|
||||
res = self.con.getresponse()
|
||||
self.assertEquals(res.status, 501)
|
||||
self.assertEqual(res.status, 501)
|
||||
|
||||
def test_handler(self):
|
||||
self.con.request('TEST', '/')
|
||||
res = self.con.getresponse()
|
||||
self.assertEquals(res.status, 204)
|
||||
self.assertEqual(res.status, 204)
|
||||
|
||||
def test_return_header_keep_alive(self):
|
||||
self.con.request('KEEP', '/')
|
||||
res = self.con.getresponse()
|
||||
self.assertEquals(res.getheader('Connection'), 'keep-alive')
|
||||
self.assertEqual(res.getheader('Connection'), 'keep-alive')
|
||||
self.con.request('TEST', '/')
|
||||
|
||||
def test_internal_key_error(self):
|
||||
self.con.request('KEYERROR', '/')
|
||||
res = self.con.getresponse()
|
||||
self.assertEquals(res.status, 999)
|
||||
self.assertEqual(res.status, 999)
|
||||
|
||||
def test_return_custom_status(self):
|
||||
self.con.request('CUSTOM', '/')
|
||||
res = self.con.getresponse()
|
||||
self.assertEquals(res.status, 999)
|
||||
self.assertEqual(res.status, 999)
|
||||
|
||||
|
||||
class SimpleHTTPServerTestCase(BaseTestCase):
|
||||
|
@ -221,8 +221,8 @@ class SimpleHTTPServerTestCase(BaseTestCase):
|
|||
def check_status_and_reason(self, response, status, data=None):
|
||||
body = response.read()
|
||||
self.assertTrue(response)
|
||||
self.assertEquals(response.status, status)
|
||||
self.assertTrue(response.reason != None)
|
||||
self.assertEqual(response.status, status)
|
||||
self.assertIsNotNone(response.reason)
|
||||
if data:
|
||||
self.assertEqual(data, body)
|
||||
|
||||
|
@ -283,8 +283,8 @@ print "Content-type: text/html"
|
|||
print
|
||||
|
||||
form = cgi.FieldStorage()
|
||||
print "%%s, %%s, %%s" %% (form.getfirst("spam"), form.getfirst("eggs"),\
|
||||
form.getfirst("bacon"))
|
||||
print "%%s, %%s, %%s" %% (form.getfirst("spam"), form.getfirst("eggs"),
|
||||
form.getfirst("bacon"))
|
||||
"""
|
||||
|
||||
class CGIHTTPServerTestCase(BaseTestCase):
|
||||
|
@ -355,38 +355,38 @@ class CGIHTTPServerTestCase(BaseTestCase):
|
|||
CGIHTTPServer._url_collapse_path_split, path)
|
||||
else:
|
||||
actual = CGIHTTPServer._url_collapse_path_split(path)
|
||||
self.assertEquals(expected, actual,
|
||||
msg='path = %r\nGot: %r\nWanted: %r' % (
|
||||
path, actual, expected))
|
||||
self.assertEqual(expected, actual,
|
||||
msg='path = %r\nGot: %r\nWanted: %r' %
|
||||
(path, actual, expected))
|
||||
|
||||
def test_headers_and_content(self):
|
||||
res = self.request('/cgi-bin/file1.py')
|
||||
self.assertEquals(('Hello World\n', 'text/html', 200), \
|
||||
(res.read(), res.getheader('Content-type'), res.status))
|
||||
self.assertEqual(('Hello World\n', 'text/html', 200),
|
||||
(res.read(), res.getheader('Content-type'), res.status))
|
||||
|
||||
def test_post(self):
|
||||
params = urllib.urlencode({'spam' : 1, 'eggs' : 'python', 'bacon' : 123456})
|
||||
headers = {'Content-type' : 'application/x-www-form-urlencoded'}
|
||||
res = self.request('/cgi-bin/file2.py', 'POST', params, headers)
|
||||
|
||||
self.assertEquals(res.read(), '1, python, 123456\n')
|
||||
self.assertEqual(res.read(), '1, python, 123456\n')
|
||||
|
||||
def test_invaliduri(self):
|
||||
res = self.request('/cgi-bin/invalid')
|
||||
res.read()
|
||||
self.assertEquals(res.status, 404)
|
||||
self.assertEqual(res.status, 404)
|
||||
|
||||
def test_authorization(self):
|
||||
headers = {'Authorization' : 'Basic %s' % \
|
||||
base64.b64encode('username:pass')}
|
||||
headers = {'Authorization' : 'Basic %s' %
|
||||
base64.b64encode('username:pass')}
|
||||
res = self.request('/cgi-bin/file1.py', 'GET', headers=headers)
|
||||
self.assertEquals(('Hello World\n', 'text/html', 200), \
|
||||
(res.read(), res.getheader('Content-type'), res.status))
|
||||
self.assertEqual(('Hello World\n', 'text/html', 200),
|
||||
(res.read(), res.getheader('Content-type'), res.status))
|
||||
|
||||
def test_no_leading_slash(self):
|
||||
# http://bugs.python.org/issue2254
|
||||
res = self.request('cgi-bin/file1.py')
|
||||
self.assertEquals(('Hello World\n', 'text/html', 200),
|
||||
self.assertEqual(('Hello World\n', 'text/html', 200),
|
||||
(res.read(), res.getheader('Content-type'), res.status))
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue