diff options
author | Florent Xicluna <florent.xicluna@gmail.com> | 2010-03-19 19:00:44 (GMT) |
---|---|---|
committer | Florent Xicluna <florent.xicluna@gmail.com> | 2010-03-19 19:00:44 (GMT) |
commit | 9b86b9a086425c9c3a132ccad4ea8875083300c2 (patch) | |
tree | 0c463be0d181d3120984b50388f502f137922682 /Lib | |
parent | fb60f8002c3c9a6f496fb1d3cbb1a8b11d9ba793 (diff) | |
download | cpython-9b86b9a086425c9c3a132ccad4ea8875083300c2.zip cpython-9b86b9a086425c9c3a132ccad4ea8875083300c2.tar.gz cpython-9b86b9a086425c9c3a132ccad4ea8875083300c2.tar.bz2 |
Merged revisions 79100 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r79100 | florent.xicluna | 2010-03-19 19:34:55 +0100 (ven, 19 mar 2010) | 2 lines
Various tests cleanup: check_warnings/check_py3k_warnings, unittest.assert* and setUp/tearDown.
........
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_bytes.py | 4 | ||||
-rw-r--r-- | Lib/test/test_grammar.py | 78 | ||||
-rw-r--r-- | Lib/test/test_httpservers.py | 56 | ||||
-rw-r--r-- | Lib/test/test_index.py | 2 | ||||
-rw-r--r-- | Lib/test/test_minidom.py | 2 | ||||
-rw-r--r-- | Lib/test/test_profilehooks.py | 2 | ||||
-rw-r--r-- | Lib/test/test_scope.py | 3 | ||||
-rw-r--r-- | Lib/test/test_urllib2_localnet.py | 8 |
8 files changed, 75 insertions, 80 deletions
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py index 0af0685..6d3f8c8 100644 --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -876,9 +876,9 @@ class AssortedBytesTest(unittest.TestCase): self.assertEqual(bytes(b"abc") <= b"ab", False) def test_doc(self): - self.assertTrue(bytearray.__doc__ != None) + self.assertIsNotNone(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__) def test_from_bytearray(self): diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py index 4ef4969..05a036a 100644 --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -1,42 +1,36 @@ # Python test set -- part 1, grammar. # 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.support import run_unittest, check_syntax_error import unittest import sys # testing import * from sys import * + class TokenTests(unittest.TestCase): def testBackslash(self): # Backslash means line continuation: x = 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 :\ x = 0 - self.assertEquals(x, 0, 'backslash ending comment') + self.assertEqual(x, 0, 'backslash ending comment') def testPlainIntegers(self): - self.assertEquals(type(000), type(0)) - self.assertEquals(0xff, 255) - self.assertEquals(0o377, 255) - self.assertEquals(2147483647, 0o17777777777) - self.assertEquals(0b1001, 9) + self.assertEqual(type(000), type(0)) + self.assertEqual(0xff, 255) + self.assertEqual(0o377, 255) + self.assertEqual(2147483647, 0o17777777777) + self.assertEqual(0b1001, 9) # "0x" is not a valid literal self.assertRaises(SyntaxError, eval, "0x") from sys import maxsize if maxsize == 2147483647: - self.assertEquals(-2147483647-1, -0o20000000000) + self.assertEqual(-2147483647-1, -0o20000000000) # XXX -2147483648 self.assertTrue(0o37777777777 > 0) self.assertTrue(0xffffffff > 0) @@ -48,7 +42,7 @@ class TokenTests(unittest.TestCase): except OverflowError: self.fail("OverflowError on huge integer literal %r" % s) elif maxsize == 9223372036854775807: - self.assertEquals(-9223372036854775807-1, -0o1000000000000000000000) + self.assertEqual(-9223372036854775807-1, -0o1000000000000000000000) self.assertTrue(0o1777777777777777777777 > 0) self.assertTrue(0xffffffffffffffff > 0) self.assertTrue(0b11111111111111111111111111111111111111111111111111111111111111 > 0) @@ -103,28 +97,28 @@ jumps over the 'lazy' dog. """ y = '\nThe "quick"\nbrown fox\njumps over\nthe \'lazy\' dog.\n' - self.assertEquals(x, y) + self.assertEqual(x, y) y = ''' The "quick" brown fox jumps over the 'lazy' dog. ''' - self.assertEquals(x, y) + self.assertEqual(x, y) y = "\n\ The \"quick\"\n\ brown fox\n\ jumps over\n\ the 'lazy' dog.\n\ " - self.assertEquals(x, y) + self.assertEqual(x, y) y = '\n\ The \"quick\"\n\ brown fox\n\ jumps over\n\ the \'lazy\' dog.\n\ ' - self.assertEquals(x, y) + self.assertEqual(x, y) def testEllipsis(self): x = ... @@ -165,8 +159,8 @@ class GrammarTests(unittest.TestCase): f1(*(), **{}) def f2(one_argument): pass def f3(two, arguments): pass - self.assertEquals(f2.__code__.co_varnames, ('one_argument',)) - self.assertEquals(f3.__code__.co_varnames, ('two', 'arguments')) + self.assertEqual(f2.__code__.co_varnames, ('one_argument',)) + self.assertEqual(f3.__code__.co_varnames, ('two', 'arguments')) def a1(one_arg,): pass def a2(two, args,): pass def v0(*rest): pass @@ -287,37 +281,37 @@ class GrammarTests(unittest.TestCase): # keyword arguments after *arglist def f(*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})) self.assertRaises(SyntaxError, eval, "f(1, *(2,3), 4)") self.assertRaises(SyntaxError, eval, "f(1, x=2, *(3,4), x=5)") # argument annotation tests def f(x) -> list: pass - self.assertEquals(f.__annotations__, {'return': list}) + self.assertEqual(f.__annotations__, {'return': list}) def f(x:int): pass - self.assertEquals(f.__annotations__, {'x': int}) + self.assertEqual(f.__annotations__, {'x': int}) def f(*x:str): pass - self.assertEquals(f.__annotations__, {'x': str}) + self.assertEqual(f.__annotations__, {'x': str}) def f(**x:float): pass - self.assertEquals(f.__annotations__, {'x': float}) + self.assertEqual(f.__annotations__, {'x': float}) def f(x, y:1+2): pass - self.assertEquals(f.__annotations__, {'y': 3}) + self.assertEqual(f.__annotations__, {'y': 3}) def f(a, b:1, c:2, d): pass - self.assertEquals(f.__annotations__, {'b': 1, 'c': 2}) + self.assertEqual(f.__annotations__, {'b': 1, 'c': 2}) def f(a, b:1, c:2, d, e:3=4, f=5, *g:6): pass - self.assertEquals(f.__annotations__, + self.assertEqual(f.__annotations__, {'b': 1, 'c': 2, 'e': 3, 'g': 6}) def f(a, b:1, c:2, d, e:3=4, f=5, *g:6, h:7, i=8, j:9=10, **k:11) -> 12: pass - self.assertEquals(f.__annotations__, + self.assertEqual(f.__annotations__, {'b': 1, 'c': 2, 'e': 3, 'g': 6, 'h': 7, 'j': 9, 'k': 11, 'return': 12}) # Check for SF Bug #1697248 - mixing decorators and a return annotation def null(x): return x @null def f(x) -> list: pass - self.assertEquals(f.__annotations__, {'return': list}) + self.assertEqual(f.__annotations__, {'return': list}) # test MAKE_CLOSURE with a variety of oparg's closure = 1 @@ -333,20 +327,20 @@ class GrammarTests(unittest.TestCase): def testLambdef(self): ### lambdef: 'lambda' [varargslist] ':' test l1 = lambda : 0 - self.assertEquals(l1(), 0) + self.assertEqual(l1(), 0) l2 = lambda : a[d] # XXX just testing the expression l3 = lambda : [2 < x for x in [-1, 3, 0]] - self.assertEquals(l3(), [0, 1, 0]) + self.assertEqual(l3(), [0, 1, 0]) 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 - self.assertEquals(l5(1, 2), 5) - self.assertEquals(l5(1, 2, 3), 6) + self.assertEqual(l5(1, 2), 5) + self.assertEqual(l5(1, 2, 3), 6) check_syntax_error(self, "lambda x: x = 2") check_syntax_error(self, "lambda (None,): None") l6 = lambda x, y, *, k=20: x+y+k - self.assertEquals(l6(1,2), 1+2+20) - self.assertEquals(l6(1,2,k=10), 1+2+10) + self.assertEqual(l6(1,2), 1+2+20) + self.assertEqual(l6(1,2,k=10), 1+2+10) ### stmt: simple_stmt | compound_stmt @@ -502,7 +496,7 @@ class GrammarTests(unittest.TestCase): try: assert 0, "msg" except AssertionError as e: - self.assertEquals(e.args[0], "msg") + self.assertEqual(e.args[0], "msg") else: if __debug__: self.fail("AssertionError not raised by assert 0") @@ -536,7 +530,7 @@ class GrammarTests(unittest.TestCase): x = 1 else: x = 2 - self.assertEquals(x, 2) + self.assertEqual(x, 2) def testFor(self): # 'for' exprlist 'in' exprlist ':' suite ['else' ':' suite] @@ -688,7 +682,7 @@ class GrammarTests(unittest.TestCase): d[1,2,3] = 4 L = list(d) L.sort(key=lambda x: x if isinstance(x, tuple) else ()) - 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): ### atom: '(' [testlist] ')' | '[' [testlist] ']' | '{' [dictsetmaker] '}' | NAME | NUMBER | STRING diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py index 93a6ded..6cf5e3e 100644 --- a/Lib/test/test_httpservers.py +++ b/Lib/test/test_httpservers.py @@ -104,42 +104,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 @@ -147,21 +147,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' @@ -169,28 +169,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): @@ -222,8 +222,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) @@ -284,8 +284,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): @@ -356,14 +356,14 @@ class CGIHTTPServerTestCase(BaseTestCase): server._url_collapse_path_split, path) else: actual = server._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((b'Hello World\n', 'text/html', 200), \ - (res.read(), res.getheader('Content-type'), res.status)) + self.assertEqual((b'Hello World\n', 'text/html', 200), + (res.read(), res.getheader('Content-type'), res.status)) def test_post(self): params = urllib.parse.urlencode( @@ -371,24 +371,24 @@ class CGIHTTPServerTestCase(BaseTestCase): headers = {'Content-type' : 'application/x-www-form-urlencoded'} res = self.request('/cgi-bin/file2.py', 'POST', params, headers) - self.assertEquals(res.read(), b'1, python, 123456\n') + self.assertEqual(res.read(), b'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 = {b'Authorization' : b'Basic ' + base64.b64encode(b'username:pass')} res = self.request('/cgi-bin/file1.py', 'GET', headers=headers) - self.assertEquals((b'Hello World\n', 'text/html', 200), \ - (res.read(), res.getheader('Content-type'), res.status)) + self.assertEqual((b'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((b'Hello World\n', 'text/html', 200), + self.assertEqual((b'Hello World\n', 'text/html', 200), (res.read(), res.getheader('Content-type'), res.status)) diff --git a/Lib/test/test_index.py b/Lib/test/test_index.py index 4b4fe1b..79802e2 100644 --- a/Lib/test/test_index.py +++ b/Lib/test/test_index.py @@ -154,7 +154,7 @@ class ListTestCase(SeqTestCase): lst = [5, 6, 7, 8, 9, 11] l2 = lst.__imul__(self.n) - self.assertTrue(l2 is lst) + self.assertIs(l2, lst) self.assertEqual(lst, [5, 6, 7, 8, 9, 11] * 3) diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py index 70f1dbb..32863bf 100644 --- a/Lib/test/test_minidom.py +++ b/Lib/test/test_minidom.py @@ -949,7 +949,7 @@ class MinidomTest(unittest.TestCase): node = doc.documentElement node.childNodes[1].nodeValue = "" node.normalize() - self.confirm(node.childNodes[-1].nextSibling == None, + self.confirm(node.childNodes[-1].nextSibling is None, "Final child's .nextSibling should be None") def testSiblings(self): diff --git a/Lib/test/test_profilehooks.py b/Lib/test/test_profilehooks.py index 296c997..54267a0 100644 --- a/Lib/test/test_profilehooks.py +++ b/Lib/test/test_profilehooks.py @@ -12,7 +12,7 @@ class TestGetProfile(unittest.TestCase): sys.setprofile(None) def test_empty(self): - assert sys.getprofile() == None + assert sys.getprofile() is None def test_setget(self): def fn(*args): diff --git a/Lib/test/test_scope.py b/Lib/test/test_scope.py index ffe68c8..643dcbc 100644 --- a/Lib/test/test_scope.py +++ b/Lib/test/test_scope.py @@ -1,9 +1,6 @@ import unittest from test.support import check_syntax_error, run_unittest -import warnings -warnings.filterwarnings("ignore", r"import \*", SyntaxWarning, "<test string>") -warnings.filterwarnings("ignore", r"import \*", SyntaxWarning, "<string>") class ScopeTests(unittest.TestCase): diff --git a/Lib/test/test_urllib2_localnet.py b/Lib/test/test_urllib2_localnet.py index c0f20f5..5ffd779 100644 --- a/Lib/test/test_urllib2_localnet.py +++ b/Lib/test/test_urllib2_localnet.py @@ -223,10 +223,10 @@ class FakeProxyHandler(http.server.BaseHTTPRequestHandler): class BaseTestCase(unittest.TestCase): def setUp(self): - self._threads = test_support.threading_setup() + self._threads = support.threading_setup() def tearDown(self): - test_support.threading_cleanup(*self._threads) + support.threading_cleanup(*self._threads) class ProxyAuthTests(BaseTestCase): @@ -237,6 +237,7 @@ class ProxyAuthTests(BaseTestCase): REALM = "TestRealm" def setUp(self): + super(ProxyAuthTests, self).setUp() self.digest_auth_handler = DigestAuthHandler() self.digest_auth_handler.set_users({self.USER: self.PASSWD}) self.digest_auth_handler.set_realm(self.REALM) @@ -254,6 +255,7 @@ class ProxyAuthTests(BaseTestCase): def tearDown(self): self.server.stop() + super(ProxyAuthTests, self).tearDown() def test_proxy_with_bad_password_raises_httperror(self): self.proxy_digest_handler.add_password(self.REALM, self.URL, @@ -347,11 +349,13 @@ class TestUrlopen(BaseTestCase): """ def setUp(self): + super(TestUrlopen, self).setUp() self.server = None def tearDown(self): if self.server is not None: self.server.stop() + super(TestUrlopen, self).tearDown() def urlopen(self, url, data=None): l = [] |