Kaydet (Commit) bc27c6a5 authored tarafından Florent Xicluna's avatar Florent Xicluna

Various tests cleanup: check_warnings/check_py3k_warnings, unittest.assert* and setUp/tearDown.

üst 4854c969
...@@ -8,12 +8,9 @@ This should generate Barry's example, modulo some quotes and newlines. ...@@ -8,12 +8,9 @@ This should generate Barry's example, modulo some quotes and newlines.
""" """
import unittest, StringIO import unittest, StringIO
from test.test_support import run_unittest from test.test_support import run_unittest, import_module
import warnings
warnings.filterwarnings("ignore", "the MimeWriter module is deprecated.*",
DeprecationWarning)
import_module("MimeWriter", deprecated=True)
from MimeWriter import MimeWriter from MimeWriter import MimeWriter
SELLER = '''\ SELLER = '''\
......
...@@ -841,9 +841,9 @@ class AssortedBytesTest(unittest.TestCase): ...@@ -841,9 +841,9 @@ class AssortedBytesTest(unittest.TestCase):
self.assertEqual(bytes(b"abc") <= b"ab", False) self.assertEqual(bytes(b"abc") <= b"ab", False)
def test_doc(self): def test_doc(self):
self.assertTrue(bytearray.__doc__ != None) self.assertIsNotNone(bytearray.__doc__)
self.assertTrue(bytearray.__doc__.startswith("bytearray("), bytearray.__doc__) self.assertTrue(bytearray.__doc__.startswith("bytearray("), bytearray.__doc__)
self.assertTrue(bytes.__doc__ != None) self.assertIsNotNone(bytes.__doc__)
self.assertTrue(bytes.__doc__.startswith("bytes("), bytes.__doc__) self.assertTrue(bytes.__doc__.startswith("bytes("), bytes.__doc__)
def test_from_bytearray(self): def test_from_bytearray(self):
......
# Python test set -- part 1, grammar. # Python test set -- part 1, grammar.
# This just tests whether the parser accepts them all. # This just tests whether the parser accepts them all.
# NOTE: When you run this test as a script from the command line, you
# get warnings about certain hex/oct constants. Since those are
# issued by the parser, you can't suppress them by adding a
# filterwarnings() call to this module. Therefore, to shut up the
# regression test, the filterwarnings() call has been added to
# regrtest.py.
from test.test_support import run_unittest, check_syntax_error, \ from test.test_support import run_unittest, check_syntax_error, \
check_py3k_warnings check_py3k_warnings
import unittest import unittest
...@@ -15,27 +8,28 @@ import sys ...@@ -15,27 +8,28 @@ import sys
# testing import * # testing import *
from sys import * from sys import *
class TokenTests(unittest.TestCase): class TokenTests(unittest.TestCase):
def testBackslash(self): def testBackslash(self):
# Backslash means line continuation: # Backslash means line continuation:
x = 1 \ x = 1 \
+ 1 + 1
self.assertEquals(x, 2, 'backslash for line continuation') self.assertEqual(x, 2, 'backslash for line continuation')
# Backslash does not means continuation in comments :\ # Backslash does not means continuation in comments :\
x = 0 x = 0
self.assertEquals(x, 0, 'backslash ending comment') self.assertEqual(x, 0, 'backslash ending comment')
def testPlainIntegers(self): def testPlainIntegers(self):
self.assertEquals(0xff, 255) self.assertEqual(0xff, 255)
self.assertEquals(0377, 255) self.assertEqual(0377, 255)
self.assertEquals(2147483647, 017777777777) self.assertEqual(2147483647, 017777777777)
# "0x" is not a valid literal # "0x" is not a valid literal
self.assertRaises(SyntaxError, eval, "0x") self.assertRaises(SyntaxError, eval, "0x")
from sys import maxint from sys import maxint
if maxint == 2147483647: if maxint == 2147483647:
self.assertEquals(-2147483647-1, -020000000000) self.assertEqual(-2147483647-1, -020000000000)
# XXX -2147483648 # XXX -2147483648
self.assertTrue(037777777777 > 0) self.assertTrue(037777777777 > 0)
self.assertTrue(0xffffffff > 0) self.assertTrue(0xffffffff > 0)
...@@ -45,7 +39,7 @@ class TokenTests(unittest.TestCase): ...@@ -45,7 +39,7 @@ class TokenTests(unittest.TestCase):
except OverflowError: except OverflowError:
self.fail("OverflowError on huge integer literal %r" % s) self.fail("OverflowError on huge integer literal %r" % s)
elif maxint == 9223372036854775807: elif maxint == 9223372036854775807:
self.assertEquals(-9223372036854775807-1, -01000000000000000000000) self.assertEqual(-9223372036854775807-1, -01000000000000000000000)
self.assertTrue(01777777777777777777777 > 0) self.assertTrue(01777777777777777777777 > 0)
self.assertTrue(0xffffffffffffffff > 0) self.assertTrue(0xffffffffffffffff > 0)
for s in '9223372036854775808', '02000000000000000000000', \ for s in '9223372036854775808', '02000000000000000000000', \
...@@ -98,28 +92,28 @@ jumps over ...@@ -98,28 +92,28 @@ jumps over
the 'lazy' dog. the 'lazy' dog.
""" """
y = '\nThe "quick"\nbrown fox\njumps over\nthe \'lazy\' dog.\n' y = '\nThe "quick"\nbrown fox\njumps over\nthe \'lazy\' dog.\n'
self.assertEquals(x, y) self.assertEqual(x, y)
y = ''' y = '''
The "quick" The "quick"
brown fox brown fox
jumps over jumps over
the 'lazy' dog. the 'lazy' dog.
''' '''
self.assertEquals(x, y) self.assertEqual(x, y)
y = "\n\ y = "\n\
The \"quick\"\n\ The \"quick\"\n\
brown fox\n\ brown fox\n\
jumps over\n\ jumps over\n\
the 'lazy' dog.\n\ the 'lazy' dog.\n\
" "
self.assertEquals(x, y) self.assertEqual(x, y)
y = '\n\ y = '\n\
The \"quick\"\n\ The \"quick\"\n\
brown fox\n\ brown fox\n\
jumps over\n\ jumps over\n\
the \'lazy\' dog.\n\ the \'lazy\' dog.\n\
' '
self.assertEquals(x, y) self.assertEqual(x, y)
class GrammarTests(unittest.TestCase): class GrammarTests(unittest.TestCase):
...@@ -156,18 +150,18 @@ class GrammarTests(unittest.TestCase): ...@@ -156,18 +150,18 @@ class GrammarTests(unittest.TestCase):
# Silence Py3k warning # Silence Py3k warning
exec('def f4(two, (compound, (argument, list))): pass') exec('def f4(two, (compound, (argument, list))): pass')
exec('def f5((compound, first), two): pass') exec('def f5((compound, first), two): pass')
self.assertEquals(f2.func_code.co_varnames, ('one_argument',)) self.assertEqual(f2.func_code.co_varnames, ('one_argument',))
self.assertEquals(f3.func_code.co_varnames, ('two', 'arguments')) self.assertEqual(f3.func_code.co_varnames, ('two', 'arguments'))
if sys.platform.startswith('java'): if sys.platform.startswith('java'):
self.assertEquals(f4.func_code.co_varnames, self.assertEqual(f4.func_code.co_varnames,
('two', '(compound, (argument, list))', 'compound', 'argument', ('two', '(compound, (argument, list))', 'compound', 'argument',
'list',)) 'list',))
self.assertEquals(f5.func_code.co_varnames, self.assertEqual(f5.func_code.co_varnames,
('(compound, first)', 'two', 'compound', 'first')) ('(compound, first)', 'two', 'compound', 'first'))
else: else:
self.assertEquals(f4.func_code.co_varnames, self.assertEqual(f4.func_code.co_varnames,
('two', '.1', 'compound', 'argument', 'list')) ('two', '.1', 'compound', 'argument', 'list'))
self.assertEquals(f5.func_code.co_varnames, self.assertEqual(f5.func_code.co_varnames,
('.0', 'two', 'compound', 'first')) ('.0', 'two', 'compound', 'first'))
def a1(one_arg,): pass def a1(one_arg,): pass
def a2(two, args,): pass def a2(two, args,): pass
...@@ -204,10 +198,10 @@ class GrammarTests(unittest.TestCase): ...@@ -204,10 +198,10 @@ class GrammarTests(unittest.TestCase):
# ceval unpacks the formal arguments into the first argcount names; # ceval unpacks the formal arguments into the first argcount names;
# thus, the names nested inside tuples must appear after these names. # thus, the names nested inside tuples must appear after these names.
if sys.platform.startswith('java'): if sys.platform.startswith('java'):
self.assertEquals(v3.func_code.co_varnames, ('a', '(b, c)', 'rest', 'b', 'c')) self.assertEqual(v3.func_code.co_varnames, ('a', '(b, c)', 'rest', 'b', 'c'))
else: else:
self.assertEquals(v3.func_code.co_varnames, ('a', '.1', 'rest', 'b', 'c')) self.assertEqual(v3.func_code.co_varnames, ('a', '.1', 'rest', 'b', 'c'))
self.assertEquals(v3(1, (2, 3), 4), (1, 2, 3, (4,))) self.assertEqual(v3(1, (2, 3), 4), (1, 2, 3, (4,)))
def d01(a=1): pass def d01(a=1): pass
d01() d01()
d01(1) d01(1)
...@@ -289,7 +283,7 @@ class GrammarTests(unittest.TestCase): ...@@ -289,7 +283,7 @@ class GrammarTests(unittest.TestCase):
# keyword arguments after *arglist # keyword arguments after *arglist
def f(*args, **kwargs): def f(*args, **kwargs):
return args, kwargs return args, kwargs
self.assertEquals(f(1, x=2, *[3, 4], y=5), ((1, 3, 4), self.assertEqual(f(1, x=2, *[3, 4], y=5), ((1, 3, 4),
{'x':2, 'y':5})) {'x':2, 'y':5}))
self.assertRaises(SyntaxError, eval, "f(1, *(2,3), 4)") self.assertRaises(SyntaxError, eval, "f(1, *(2,3), 4)")
self.assertRaises(SyntaxError, eval, "f(1, x=2, *(3,4), x=5)") self.assertRaises(SyntaxError, eval, "f(1, x=2, *(3,4), x=5)")
...@@ -301,15 +295,15 @@ class GrammarTests(unittest.TestCase): ...@@ -301,15 +295,15 @@ class GrammarTests(unittest.TestCase):
def testLambdef(self): def testLambdef(self):
### lambdef: 'lambda' [varargslist] ':' test ### lambdef: 'lambda' [varargslist] ':' test
l1 = lambda : 0 l1 = lambda : 0
self.assertEquals(l1(), 0) self.assertEqual(l1(), 0)
l2 = lambda : a[d] # XXX just testing the expression l2 = lambda : a[d] # XXX just testing the expression
l3 = lambda : [2 < x for x in [-1, 3, 0L]] l3 = lambda : [2 < x for x in [-1, 3, 0L]]
self.assertEquals(l3(), [0, 1, 0]) self.assertEqual(l3(), [0, 1, 0])
l4 = lambda x = lambda y = lambda z=1 : z : y() : x() l4 = lambda x = lambda y = lambda z=1 : z : y() : x()
self.assertEquals(l4(), 1) self.assertEqual(l4(), 1)
l5 = lambda x, y, z=2: x + y + z l5 = lambda x, y, z=2: x + y + z
self.assertEquals(l5(1, 2), 5) self.assertEqual(l5(1, 2), 5)
self.assertEquals(l5(1, 2, 3), 6) self.assertEqual(l5(1, 2, 3), 6)
check_syntax_error(self, "lambda x: x = 2") check_syntax_error(self, "lambda x: x = 2")
check_syntax_error(self, "lambda (None,): None") check_syntax_error(self, "lambda (None,): None")
...@@ -545,8 +539,6 @@ hello world ...@@ -545,8 +539,6 @@ hello world
g = {} g = {}
l = {} l = {}
import warnings
warnings.filterwarnings("ignore", "global statement", module="<string>")
exec 'global a; a = 1; b = 2' in g, l exec 'global a; a = 1; b = 2' in g, l
if '__builtins__' in g: del g['__builtins__'] if '__builtins__' in g: del g['__builtins__']
if '__builtins__' in l: del l['__builtins__'] if '__builtins__' in l: del l['__builtins__']
...@@ -562,7 +554,7 @@ hello world ...@@ -562,7 +554,7 @@ hello world
try: try:
assert 0, "msg" assert 0, "msg"
except AssertionError, e: except AssertionError, e:
self.assertEquals(e.args[0], "msg") self.assertEqual(e.args[0], "msg")
else: else:
if __debug__: if __debug__:
self.fail("AssertionError not raised by assert 0") self.fail("AssertionError not raised by assert 0")
...@@ -596,7 +588,7 @@ hello world ...@@ -596,7 +588,7 @@ hello world
x = 1 x = 1
else: else:
x = 2 x = 2
self.assertEquals(x, 2) self.assertEqual(x, 2)
def testFor(self): def testFor(self):
# 'for' exprlist 'in' exprlist ':' suite ['else' ':' suite] # 'for' exprlist 'in' exprlist ':' suite ['else' ':' suite]
...@@ -751,7 +743,7 @@ hello world ...@@ -751,7 +743,7 @@ hello world
d[1,2,3] = 4 d[1,2,3] = 4
L = list(d) L = list(d)
L.sort() L.sort()
self.assertEquals(str(L), '[1, (1,), (1, 2), (1, 2, 3)]') self.assertEqual(str(L), '[1, (1,), (1, 2), (1, 2, 3)]')
def testAtoms(self): def testAtoms(self):
### atom: '(' [testlist] ')' | '[' [testlist] ']' | '{' [dictmaker] '}' | '`' testlist '`' | NAME | NUMBER | STRING ### atom: '(' [testlist] ')' | '[' [testlist] ']' | '{' [dictmaker] '}' | '`' testlist '`' | NAME | NUMBER | STRING
......
...@@ -103,42 +103,42 @@ class BaseHTTPServerTestCase(BaseTestCase): ...@@ -103,42 +103,42 @@ class BaseHTTPServerTestCase(BaseTestCase):
def test_command(self): def test_command(self):
self.con.request('GET', '/') self.con.request('GET', '/')
res = self.con.getresponse() res = self.con.getresponse()
self.assertEquals(res.status, 501) self.assertEqual(res.status, 501)
def test_request_line_trimming(self): def test_request_line_trimming(self):
self.con._http_vsn_str = 'HTTP/1.1\n' self.con._http_vsn_str = 'HTTP/1.1\n'
self.con.putrequest('GET', '/') self.con.putrequest('GET', '/')
self.con.endheaders() self.con.endheaders()
res = self.con.getresponse() res = self.con.getresponse()
self.assertEquals(res.status, 501) self.assertEqual(res.status, 501)
def test_version_bogus(self): def test_version_bogus(self):
self.con._http_vsn_str = 'FUBAR' self.con._http_vsn_str = 'FUBAR'
self.con.putrequest('GET', '/') self.con.putrequest('GET', '/')
self.con.endheaders() self.con.endheaders()
res = self.con.getresponse() res = self.con.getresponse()
self.assertEquals(res.status, 400) self.assertEqual(res.status, 400)
def test_version_digits(self): def test_version_digits(self):
self.con._http_vsn_str = 'HTTP/9.9.9' self.con._http_vsn_str = 'HTTP/9.9.9'
self.con.putrequest('GET', '/') self.con.putrequest('GET', '/')
self.con.endheaders() self.con.endheaders()
res = self.con.getresponse() res = self.con.getresponse()
self.assertEquals(res.status, 400) self.assertEqual(res.status, 400)
def test_version_none_get(self): def test_version_none_get(self):
self.con._http_vsn_str = '' self.con._http_vsn_str = ''
self.con.putrequest('GET', '/') self.con.putrequest('GET', '/')
self.con.endheaders() self.con.endheaders()
res = self.con.getresponse() res = self.con.getresponse()
self.assertEquals(res.status, 501) self.assertEqual(res.status, 501)
def test_version_none(self): def test_version_none(self):
self.con._http_vsn_str = '' self.con._http_vsn_str = ''
self.con.putrequest('PUT', '/') self.con.putrequest('PUT', '/')
self.con.endheaders() self.con.endheaders()
res = self.con.getresponse() res = self.con.getresponse()
self.assertEquals(res.status, 400) self.assertEqual(res.status, 400)
def test_version_invalid(self): def test_version_invalid(self):
self.con._http_vsn = 99 self.con._http_vsn = 99
...@@ -146,21 +146,21 @@ class BaseHTTPServerTestCase(BaseTestCase): ...@@ -146,21 +146,21 @@ class BaseHTTPServerTestCase(BaseTestCase):
self.con.putrequest('GET', '/') self.con.putrequest('GET', '/')
self.con.endheaders() self.con.endheaders()
res = self.con.getresponse() res = self.con.getresponse()
self.assertEquals(res.status, 505) self.assertEqual(res.status, 505)
def test_send_blank(self): def test_send_blank(self):
self.con._http_vsn_str = '' self.con._http_vsn_str = ''
self.con.putrequest('', '') self.con.putrequest('', '')
self.con.endheaders() self.con.endheaders()
res = self.con.getresponse() res = self.con.getresponse()
self.assertEquals(res.status, 400) self.assertEqual(res.status, 400)
def test_header_close(self): def test_header_close(self):
self.con.putrequest('GET', '/') self.con.putrequest('GET', '/')
self.con.putheader('Connection', 'close') self.con.putheader('Connection', 'close')
self.con.endheaders() self.con.endheaders()
res = self.con.getresponse() res = self.con.getresponse()
self.assertEquals(res.status, 501) self.assertEqual(res.status, 501)
def test_head_keep_alive(self): def test_head_keep_alive(self):
self.con._http_vsn_str = 'HTTP/1.1' self.con._http_vsn_str = 'HTTP/1.1'
...@@ -168,28 +168,28 @@ class BaseHTTPServerTestCase(BaseTestCase): ...@@ -168,28 +168,28 @@ class BaseHTTPServerTestCase(BaseTestCase):
self.con.putheader('Connection', 'keep-alive') self.con.putheader('Connection', 'keep-alive')
self.con.endheaders() self.con.endheaders()
res = self.con.getresponse() res = self.con.getresponse()
self.assertEquals(res.status, 501) self.assertEqual(res.status, 501)
def test_handler(self): def test_handler(self):
self.con.request('TEST', '/') self.con.request('TEST', '/')
res = self.con.getresponse() res = self.con.getresponse()
self.assertEquals(res.status, 204) self.assertEqual(res.status, 204)
def test_return_header_keep_alive(self): def test_return_header_keep_alive(self):
self.con.request('KEEP', '/') self.con.request('KEEP', '/')
res = self.con.getresponse() res = self.con.getresponse()
self.assertEquals(res.getheader('Connection'), 'keep-alive') self.assertEqual(res.getheader('Connection'), 'keep-alive')
self.con.request('TEST', '/') self.con.request('TEST', '/')
def test_internal_key_error(self): def test_internal_key_error(self):
self.con.request('KEYERROR', '/') self.con.request('KEYERROR', '/')
res = self.con.getresponse() res = self.con.getresponse()
self.assertEquals(res.status, 999) self.assertEqual(res.status, 999)
def test_return_custom_status(self): def test_return_custom_status(self):
self.con.request('CUSTOM', '/') self.con.request('CUSTOM', '/')
res = self.con.getresponse() res = self.con.getresponse()
self.assertEquals(res.status, 999) self.assertEqual(res.status, 999)
class SimpleHTTPServerTestCase(BaseTestCase): class SimpleHTTPServerTestCase(BaseTestCase):
...@@ -221,8 +221,8 @@ class SimpleHTTPServerTestCase(BaseTestCase): ...@@ -221,8 +221,8 @@ class SimpleHTTPServerTestCase(BaseTestCase):
def check_status_and_reason(self, response, status, data=None): def check_status_and_reason(self, response, status, data=None):
body = response.read() body = response.read()
self.assertTrue(response) self.assertTrue(response)
self.assertEquals(response.status, status) self.assertEqual(response.status, status)
self.assertTrue(response.reason != None) self.assertIsNotNone(response.reason)
if data: if data:
self.assertEqual(data, body) self.assertEqual(data, body)
...@@ -283,8 +283,8 @@ print "Content-type: text/html" ...@@ -283,8 +283,8 @@ print "Content-type: text/html"
print print
form = cgi.FieldStorage() form = cgi.FieldStorage()
print "%%s, %%s, %%s" %% (form.getfirst("spam"), form.getfirst("eggs"),\ print "%%s, %%s, %%s" %% (form.getfirst("spam"), form.getfirst("eggs"),
form.getfirst("bacon")) form.getfirst("bacon"))
""" """
class CGIHTTPServerTestCase(BaseTestCase): class CGIHTTPServerTestCase(BaseTestCase):
...@@ -355,38 +355,38 @@ class CGIHTTPServerTestCase(BaseTestCase): ...@@ -355,38 +355,38 @@ class CGIHTTPServerTestCase(BaseTestCase):
CGIHTTPServer._url_collapse_path_split, path) CGIHTTPServer._url_collapse_path_split, path)
else: else:
actual = CGIHTTPServer._url_collapse_path_split(path) actual = CGIHTTPServer._url_collapse_path_split(path)
self.assertEquals(expected, actual, self.assertEqual(expected, actual,
msg='path = %r\nGot: %r\nWanted: %r' % ( msg='path = %r\nGot: %r\nWanted: %r' %
path, actual, expected)) (path, actual, expected))
def test_headers_and_content(self): def test_headers_and_content(self):
res = self.request('/cgi-bin/file1.py') 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)) (res.read(), res.getheader('Content-type'), res.status))
def test_post(self): def test_post(self):
params = urllib.urlencode({'spam' : 1, 'eggs' : 'python', 'bacon' : 123456}) params = urllib.urlencode({'spam' : 1, 'eggs' : 'python', 'bacon' : 123456})
headers = {'Content-type' : 'application/x-www-form-urlencoded'} headers = {'Content-type' : 'application/x-www-form-urlencoded'}
res = self.request('/cgi-bin/file2.py', 'POST', params, headers) 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): def test_invaliduri(self):
res = self.request('/cgi-bin/invalid') res = self.request('/cgi-bin/invalid')
res.read() res.read()
self.assertEquals(res.status, 404) self.assertEqual(res.status, 404)
def test_authorization(self): def test_authorization(self):
headers = {'Authorization' : 'Basic %s' % \ headers = {'Authorization' : 'Basic %s' %
base64.b64encode('username:pass')} base64.b64encode('username:pass')}
res = self.request('/cgi-bin/file1.py', 'GET', headers=headers) res = self.request('/cgi-bin/file1.py', 'GET', headers=headers)
self.assertEquals(('Hello World\n', 'text/html', 200), \ self.assertEqual(('Hello World\n', 'text/html', 200),
(res.read(), res.getheader('Content-type'), res.status)) (res.read(), res.getheader('Content-type'), res.status))
def test_no_leading_slash(self): def test_no_leading_slash(self):
# http://bugs.python.org/issue2254 # http://bugs.python.org/issue2254
res = self.request('cgi-bin/file1.py') 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)) (res.read(), res.getheader('Content-type'), res.status))
......
...@@ -247,7 +247,7 @@ class ImportHooksTestCase(ImportHooksBaseTestCase): ...@@ -247,7 +247,7 @@ class ImportHooksTestCase(ImportHooksBaseTestCase):
for n in sys.modules.keys(): for n in sys.modules.keys():
if n.startswith(parent): if n.startswith(parent):
del sys.modules[n] del sys.modules[n]
with test_support.check_py3k_warnings(), test_support.check_warnings(): with test_support.check_warnings():
for mname in mnames: for mname in mnames:
m = __import__(mname, globals(), locals(), ["__dummy__"]) m = __import__(mname, globals(), locals(), ["__dummy__"])
m.__loader__ # to make sure we actually handled the import m.__loader__ # to make sure we actually handled the import
......
...@@ -170,7 +170,7 @@ class ListTestCase(SeqTestCase): ...@@ -170,7 +170,7 @@ class ListTestCase(SeqTestCase):
lst = [5, 6, 7, 8, 9, 11] lst = [5, 6, 7, 8, 9, 11]
l2 = lst.__imul__(self.n) l2 = lst.__imul__(self.n)
self.assertTrue(l2 is lst) self.assertIs(l2, lst)
self.assertEqual(lst, [5, 6, 7, 8, 9, 11] * 3) self.assertEqual(lst, [5, 6, 7, 8, 9, 11] * 3)
...@@ -214,6 +214,9 @@ class TupleTestCase(SeqTestCase): ...@@ -214,6 +214,9 @@ class TupleTestCase(SeqTestCase):
class StringTestCase(SeqTestCase): class StringTestCase(SeqTestCase):
seq = "this is a test" seq = "this is a test"
class ByteArrayTestCase(SeqTestCase):
seq = bytearray("this is a test")
class UnicodeTestCase(SeqTestCase): class UnicodeTestCase(SeqTestCase):
seq = u"this is a test" seq = u"this is a test"
...@@ -265,7 +268,7 @@ class OverflowTestCase(unittest.TestCase): ...@@ -265,7 +268,7 @@ class OverflowTestCase(unittest.TestCase):
def _getslice_helper_deprecated(self, base): def _getslice_helper_deprecated(self, base):
class GetItem(base): class GetItem(base):
def __len__(self): def __len__(self):
return maxint #cannot return long here return maxint # cannot return long here
def __getitem__(self, key): def __getitem__(self, key):
return key return key
def __getslice__(self, i, j): def __getslice__(self, i, j):
...@@ -299,6 +302,7 @@ def test_main(): ...@@ -299,6 +302,7 @@ def test_main():
BaseTestCase, BaseTestCase,
ListTestCase, ListTestCase,
TupleTestCase, TupleTestCase,
ByteArrayTestCase,
StringTestCase, StringTestCase,
UnicodeTestCase, UnicodeTestCase,
ClassicSeqTestCase, ClassicSeqTestCase,
......
...@@ -950,7 +950,7 @@ class MinidomTest(unittest.TestCase): ...@@ -950,7 +950,7 @@ class MinidomTest(unittest.TestCase):
node = doc.documentElement node = doc.documentElement
node.childNodes[1].nodeValue = "" node.childNodes[1].nodeValue = ""
node.normalize() node.normalize()
self.confirm(node.childNodes[-1].nextSibling == None, self.confirm(node.childNodes[-1].nextSibling is None,
"Final child's .nextSibling should be None") "Final child's .nextSibling should be None")
def testSiblings(self): def testSiblings(self):
......
...@@ -12,7 +12,7 @@ class TestGetProfile(unittest.TestCase): ...@@ -12,7 +12,7 @@ class TestGetProfile(unittest.TestCase):
sys.setprofile(None) sys.setprofile(None)
def test_empty(self): def test_empty(self):
assert sys.getprofile() == None assert sys.getprofile() is None
def test_setget(self): def test_setget(self):
def fn(*args): def fn(*args):
......
import unittest import unittest
from test.test_support import check_syntax_error, run_unittest from test.test_support import check_syntax_error, check_py3k_warnings, \
check_warnings, run_unittest
import warnings
warnings.filterwarnings("ignore", r"import \*", SyntaxWarning, "<test string>")
warnings.filterwarnings("ignore", r"import \*", SyntaxWarning, "<string>")
class ScopeTests(unittest.TestCase): class ScopeTests(unittest.TestCase):
...@@ -321,11 +319,14 @@ else: ...@@ -321,11 +319,14 @@ else:
self.assertEqual(makeReturner2(a=11)()['a'], 11) self.assertEqual(makeReturner2(a=11)()['a'], 11)
def makeAddPair((a, b)): with check_py3k_warnings(("tuple parameter unpacking has been removed",
def addPair((c, d)): SyntaxWarning)):
return (a + c, b + d) exec """\
return addPair def makeAddPair((a, b)):
def addPair((c, d)):
return (a + c, b + d)
return addPair
""" in locals()
self.assertEqual(makeAddPair((1, 2))((100, 200)), (101,202)) self.assertEqual(makeAddPair((1, 2))((100, 200)), (101,202))
def testScopeOfGlobalStmt(self): def testScopeOfGlobalStmt(self):
...@@ -471,7 +472,7 @@ self.assertTrue(X.passed) ...@@ -471,7 +472,7 @@ self.assertTrue(X.passed)
return g return g
d = f(2)(4) d = f(2)(4)
self.assertTrue(d.has_key('h')) self.assertIn('h', d)
del d['h'] del d['h']
self.assertEqual(d, {'x': 2, 'y': 7, 'w': 6}) self.assertEqual(d, {'x': 2, 'y': 7, 'w': 6})
...@@ -648,7 +649,9 @@ result2 = h() ...@@ -648,7 +649,9 @@ result2 = h()
def test_main(): def test_main():
run_unittest(ScopeTests) with check_warnings(("import \* only allowed at module level",
SyntaxWarning)):
run_unittest(ScopeTests)
if __name__ == '__main__': if __name__ == '__main__':
test_main() test_main()
...@@ -236,6 +236,7 @@ class ProxyAuthTests(BaseTestCase): ...@@ -236,6 +236,7 @@ class ProxyAuthTests(BaseTestCase):
REALM = "TestRealm" REALM = "TestRealm"
def setUp(self): def setUp(self):
super(ProxyAuthTests, self).setUp()
self.digest_auth_handler = DigestAuthHandler() self.digest_auth_handler = DigestAuthHandler()
self.digest_auth_handler.set_users({self.USER: self.PASSWD}) self.digest_auth_handler.set_users({self.USER: self.PASSWD})
self.digest_auth_handler.set_realm(self.REALM) self.digest_auth_handler.set_realm(self.REALM)
...@@ -252,6 +253,7 @@ class ProxyAuthTests(BaseTestCase): ...@@ -252,6 +253,7 @@ class ProxyAuthTests(BaseTestCase):
def tearDown(self): def tearDown(self):
self.server.stop() self.server.stop()
super(ProxyAuthTests, self).tearDown()
def test_proxy_with_bad_password_raises_httperror(self): def test_proxy_with_bad_password_raises_httperror(self):
self.proxy_digest_handler.add_password(self.REALM, self.URL, self.proxy_digest_handler.add_password(self.REALM, self.URL,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment