diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-02-08 12:51:10 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-02-08 12:51:10 (GMT) |
commit | d3e1207191dcb84a58706a5101177f36c09c5681 (patch) | |
tree | dd8bafcf64e4b1fa8bdf65f21f44a2d04fc89861 /Lib | |
parent | 6c9678e1a5651bbaa2bfa31d564f2117033fd494 (diff) | |
parent | 25d8aeac7c1e24df79c18f6391b7e42b873d66d8 (diff) | |
download | cpython-d3e1207191dcb84a58706a5101177f36c09c5681.zip cpython-d3e1207191dcb84a58706a5101177f36c09c5681.tar.gz cpython-d3e1207191dcb84a58706a5101177f36c09c5681.tar.bz2 |
Issue #20555: Use specific asserts in urllib, httplib, ftplib, cgi, wsgiref tests.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_cgi.py | 2 | ||||
-rw-r--r-- | Lib/test/test_ftplib.py | 6 | ||||
-rw-r--r-- | Lib/test/test_httplib.py | 6 | ||||
-rw-r--r-- | Lib/test/test_httpservers.py | 2 | ||||
-rw-r--r-- | Lib/test/test_urllib.py | 4 | ||||
-rw-r--r-- | Lib/test/test_urllib2.py | 7 | ||||
-rw-r--r-- | Lib/test/test_urllib2net.py | 22 | ||||
-rw-r--r-- | Lib/test/test_wsgiref.py | 4 |
8 files changed, 27 insertions, 26 deletions
diff --git a/Lib/test/test_cgi.py b/Lib/test/test_cgi.py index e604c92..86e1f3a 100644 --- a/Lib/test/test_cgi.py +++ b/Lib/test/test_cgi.py @@ -227,7 +227,7 @@ class CgiTests(unittest.TestCase): # if we're not chunking properly, readline is only called twice # (by read_binary); if we are chunking properly, it will be called 5 times # as long as the chunksize is 1 << 16. - self.assertTrue(f.numcalls > 2) + self.assertGreater(f.numcalls, 2) f.close() def test_fieldstorage_multipart(self): diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py index d0fd92e..a9bf30b 100644 --- a/Lib/test/test_ftplib.py +++ b/Lib/test/test_ftplib.py @@ -1001,7 +1001,7 @@ class TestTimeouts(TestCase): def testTimeoutDefault(self): # default -- use global socket timeout - self.assertTrue(socket.getdefaulttimeout() is None) + self.assertIsNone(socket.getdefaulttimeout()) socket.setdefaulttimeout(30) try: ftp = ftplib.FTP(HOST) @@ -1013,13 +1013,13 @@ class TestTimeouts(TestCase): def testTimeoutNone(self): # no timeout -- do not use global socket timeout - self.assertTrue(socket.getdefaulttimeout() is None) + self.assertIsNone(socket.getdefaulttimeout()) socket.setdefaulttimeout(30) try: ftp = ftplib.FTP(HOST, timeout=None) finally: socket.setdefaulttimeout(None) - self.assertTrue(ftp.sock.gettimeout() is None) + self.assertIsNone(ftp.sock.gettimeout()) self.evt.wait() ftp.close() diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index bcd0a02..30b6c0c 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -134,7 +134,7 @@ class HeaderTests(TestCase): conn.sock = FakeSocket(None) conn.putrequest('GET','/') conn.putheader('Content-length', 42) - self.assertTrue(b'Content-length: 42' in conn._buffer) + self.assertIn(b'Content-length: 42', conn._buffer) def test_ipv6host_header(self): # Default host header on IPv6 transaction should wrapped by [] if @@ -723,7 +723,7 @@ class TimeoutTest(TestCase): # and into the socket. # default -- use global socket timeout - self.assertTrue(socket.getdefaulttimeout() is None) + self.assertIsNone(socket.getdefaulttimeout()) socket.setdefaulttimeout(30) try: httpConn = client.HTTPConnection(HOST, TimeoutTest.PORT) @@ -734,7 +734,7 @@ class TimeoutTest(TestCase): httpConn.close() # no timeout -- do not use global socket default - self.assertTrue(socket.getdefaulttimeout() is None) + self.assertIsNone(socket.getdefaulttimeout()) socket.setdefaulttimeout(30) try: httpConn = client.HTTPConnection(HOST, TimeoutTest.PORT, diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py index e758cb9..15694af 100644 --- a/Lib/test/test_httpservers.py +++ b/Lib/test/test_httpservers.py @@ -552,7 +552,7 @@ class BaseHTTPRequestHandlerTestCase(unittest.TestCase): def verify_http_server_response(self, response): match = self.HTTPResponseMatch.search(response) - self.assertTrue(match is not None) + self.assertIsNotNone(match) def test_http_1_1(self): result = self.send_typical_request(b'GET / HTTP/1.1\r\n\r\n') diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py index 94f640b..1a40566 100644 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -1340,7 +1340,7 @@ class URLopener_Tests(unittest.TestCase): # def testTimeoutNone(self): # # global default timeout is ignored # import socket -# self.assertTrue(socket.getdefaulttimeout() is None) +# self.assertIsNone(socket.getdefaulttimeout()) # socket.setdefaulttimeout(30) # try: # ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, []) @@ -1352,7 +1352,7 @@ class URLopener_Tests(unittest.TestCase): # def testTimeoutDefault(self): # # global default timeout is used # import socket -# self.assertTrue(socket.getdefaulttimeout() is None) +# self.assertIsNone(socket.getdefaulttimeout()) # socket.setdefaulttimeout(30) # try: # ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, []) diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index dbd1c60..b32b409 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -603,8 +603,8 @@ class OpenerDirectorTests(unittest.TestCase): self.assertIsInstance(args[0], Request) # response from opener.open is None, because there's no # handler that defines http_open to handle it - self.assertTrue(args[1] is None or - isinstance(args[1], MockResponse)) + if args[1] is not None: + self.assertIsInstance(args[1], MockResponse) def sanepathname2url(path): try: @@ -1018,7 +1018,8 @@ class HandlerTests(unittest.TestCase): MockHeaders({"location": to_url})) except urllib.error.HTTPError: # 307 in response to POST requires user OK - self.assertTrue(code == 307 and data is not None) + self.assertEqual(code, 307) + self.assertIsNotNone(data) self.assertEqual(o.req.get_full_url(), to_url) try: self.assertEqual(o.req.get_method(), "GET") diff --git a/Lib/test/test_urllib2net.py b/Lib/test/test_urllib2net.py index 21ce3ab..78891fd 100644 --- a/Lib/test/test_urllib2net.py +++ b/Lib/test/test_urllib2net.py @@ -87,7 +87,7 @@ class CloseSocketTest(unittest.TestCase): with support.transient_internet(url): response = _urlopen_with_retry(url) sock = response.fp - self.assertTrue(not sock.closed) + self.assertFalse(sock.closed) response.close() self.assertTrue(sock.closed) @@ -262,15 +262,15 @@ class OtherNetworkTests(unittest.TestCase): class TimeoutTest(unittest.TestCase): def test_http_basic(self): - self.assertTrue(socket.getdefaulttimeout() is None) + self.assertIsNone(socket.getdefaulttimeout()) url = "http://www.python.org" with support.transient_internet(url, timeout=None): u = _urlopen_with_retry(url) self.addCleanup(u.close) - self.assertTrue(u.fp.raw._sock.gettimeout() is None) + self.assertIsNone(u.fp.raw._sock.gettimeout()) def test_http_default_timeout(self): - self.assertTrue(socket.getdefaulttimeout() is None) + self.assertIsNone(socket.getdefaulttimeout()) url = "http://www.python.org" with support.transient_internet(url): socket.setdefaulttimeout(60) @@ -282,7 +282,7 @@ class TimeoutTest(unittest.TestCase): self.assertEqual(u.fp.raw._sock.gettimeout(), 60) def test_http_no_timeout(self): - self.assertTrue(socket.getdefaulttimeout() is None) + self.assertIsNone(socket.getdefaulttimeout()) url = "http://www.python.org" with support.transient_internet(url): socket.setdefaulttimeout(60) @@ -291,7 +291,7 @@ class TimeoutTest(unittest.TestCase): self.addCleanup(u.close) finally: socket.setdefaulttimeout(None) - self.assertTrue(u.fp.raw._sock.gettimeout() is None) + self.assertIsNone(u.fp.raw._sock.gettimeout()) def test_http_timeout(self): url = "http://www.python.org" @@ -303,14 +303,14 @@ class TimeoutTest(unittest.TestCase): FTP_HOST = "ftp://ftp.mirror.nl/pub/gnu/" def test_ftp_basic(self): - self.assertTrue(socket.getdefaulttimeout() is None) + self.assertIsNone(socket.getdefaulttimeout()) with support.transient_internet(self.FTP_HOST, timeout=None): u = _urlopen_with_retry(self.FTP_HOST) self.addCleanup(u.close) - self.assertTrue(u.fp.fp.raw._sock.gettimeout() is None) + self.assertIsNone(u.fp.fp.raw._sock.gettimeout()) def test_ftp_default_timeout(self): - self.assertTrue(socket.getdefaulttimeout() is None) + self.assertIsNone(socket.getdefaulttimeout()) with support.transient_internet(self.FTP_HOST): socket.setdefaulttimeout(60) try: @@ -321,7 +321,7 @@ class TimeoutTest(unittest.TestCase): self.assertEqual(u.fp.fp.raw._sock.gettimeout(), 60) def test_ftp_no_timeout(self): - self.assertTrue(socket.getdefaulttimeout() is None) + self.assertIsNone(socket.getdefaulttimeout()) with support.transient_internet(self.FTP_HOST): socket.setdefaulttimeout(60) try: @@ -329,7 +329,7 @@ class TimeoutTest(unittest.TestCase): self.addCleanup(u.close) finally: socket.setdefaulttimeout(None) - self.assertTrue(u.fp.fp.raw._sock.gettimeout() is None) + self.assertIsNone(u.fp.fp.raw._sock.gettimeout()) def test_ftp_timeout(self): with support.transient_internet(self.FTP_HOST): diff --git a/Lib/test/test_wsgiref.py b/Lib/test/test_wsgiref.py index 4107664..901f3c9 100644 --- a/Lib/test/test_wsgiref.py +++ b/Lib/test/test_wsgiref.py @@ -196,7 +196,7 @@ class UtilityTests(TestCase): # Check existing value env = {key:alt} util.setup_testing_defaults(env) - self.assertTrue(env[key] is alt) + self.assertIs(env[key], alt) def checkCrossDefault(self,key,value,**kw): util.setup_testing_defaults(kw) @@ -343,7 +343,7 @@ class HeaderTests(TestCase): self.assertEqual(Headers(test[:]).keys(), ['x']) self.assertEqual(Headers(test[:]).values(), ['y']) self.assertEqual(Headers(test[:]).items(), test) - self.assertFalse(Headers(test).items() is test) # must be copy! + self.assertIsNot(Headers(test).items(), test) # must be copy! h=Headers([]) del h['foo'] # should not raise an error |