From 7bea148d2fe22daa9d1fbbc5cd16ebd390b64b1b Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sun, 16 Aug 2015 10:34:26 +0200 Subject: [PATCH] pep8: replace deprecated calls to assert_() The TestCase.assert_() has been deprecated in Python 2.7. Replace it with assertTrue() or even better methods (assertIn, assertNotIn, assertIsInstance) which provide better error messages. Change-Id: I21c730351470031a2dabe5238693095eabdb8964 --- test/functional/tests.py | 8 ++++---- test/unit/common/test_wsgi.py | 2 +- test/unit/proxy/test_server.py | 14 +++++++------- tox.ini | 3 +-- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/test/functional/tests.py b/test/functional/tests.py index 56e7fdc6bd..8c64d8d12d 100644 --- a/test/functional/tests.py +++ b/test/functional/tests.py @@ -441,14 +441,14 @@ class TestContainer(Base): def testListDelimiter(self): cont = self.env.account.container(Utils.create_name()) - self.assert_(cont.create()) + self.assertTrue(cont.create()) delimiter = '-' files = ['test', delimiter.join(['test', 'bar']), delimiter.join(['test', 'foo'])] for f in files: file_item = cont.file(f) - self.assert_(file_item.write_random()) + self.assertTrue(file_item.write_random()) results = cont.files() results = cont.files(parms={'delimiter': delimiter}) @@ -456,13 +456,13 @@ class TestContainer(Base): def testListDelimiterAndPrefix(self): cont = self.env.account.container(Utils.create_name()) - self.assert_(cont.create()) + self.assertTrue(cont.create()) delimiter = 'a' files = ['bar', 'bazar'] for f in files: file_item = cont.file(f) - self.assert_(file_item.write_random()) + self.assertTrue(file_item.write_random()) results = cont.files(parms={'delimiter': delimiter, 'prefix': 'ba'}) self.assertEqual(results, ['bar', 'baza']) diff --git a/test/unit/common/test_wsgi.py b/test/unit/common/test_wsgi.py index 7a5b03696e..1e786e273c 100644 --- a/test/unit/common/test_wsgi.py +++ b/test/unit/common/test_wsgi.py @@ -144,7 +144,7 @@ class TestWSGI(unittest.TestCase): app = app.app expected = \ swift.common.middleware.versioned_writes.VersionedWritesMiddleware - self.assert_(isinstance(app, expected)) + self.assertIsInstance(app, expected) app = app.app expected = swift.proxy.server.Application diff --git a/test/unit/proxy/test_server.py b/test/unit/proxy/test_server.py index 26903d0a92..04eb3d6eb7 100644 --- a/test/unit/proxy/test_server.py +++ b/test/unit/proxy/test_server.py @@ -8597,7 +8597,7 @@ class TestSocketObjectVersions(unittest.TestCase): headers, body = get_container() exp = 'HTTP/1.1 2' # 2xx series response self.assertEqual(headers[:len(exp)], exp) - self.assert_('X-Versions-Location: %s' % vc in headers) + self.assertIn('X-Versions-Location: %s' % vc, headers) def put_version_container(): sock = connect_tcp(('localhost', prolis.getsockname()[1])) @@ -8654,8 +8654,8 @@ class TestSocketObjectVersions(unittest.TestCase): headers, body = get() exp = 'HTTP/1.1 200' self.assertEqual(headers[:len(exp)], exp) - self.assert_('Content-Type: text/jibberish%s' % version in headers) - self.assert_('X-Object-Meta-Foo: barbaz' not in headers) + self.assertIn('Content-Type: text/jibberish%s' % version, headers) + self.assertNotIn('X-Object-Meta-Foo: barbaz', headers) self.assertEqual(body, '%05d' % version) def get_version_container(): @@ -8738,8 +8738,8 @@ class TestSocketObjectVersions(unittest.TestCase): self.assertEqual(headers[:len(exp)], exp) headers, body = get() - self.assert_('Content-Type: foo/bar' in headers) - self.assert_('X-Object-Meta-Bar: foo' in headers) + self.assertIn('Content-Type: foo/bar', headers) + self.assertIn('X-Object-Meta-Bar: foo', headers) self.assertEqual(body, '%05d' % version) # check container listing @@ -8758,8 +8758,8 @@ class TestSocketObjectVersions(unittest.TestCase): headers, body = get() exp = 'HTTP/1.1 200' self.assertEqual(headers[:len(exp)], exp) - self.assert_('Content-Type: text/jibberish%s' % (segment - 1) - in headers) + self.assertIn('Content-Type: text/jibberish%s' % (segment - 1), + headers) self.assertEqual(body, '%05d' % (segment - 1)) # Ensure we have the right number of versions saved sock = connect_tcp(('localhost', prolis.getsockname()[1])) diff --git a/tox.ini b/tox.ini index a98035cd44..50236788c4 100644 --- a/tox.ini +++ b/tox.ini @@ -61,7 +61,6 @@ commands = bandit -c bandit.yaml -r swift bin -n 5 -p gate # H202: assertRaises Exception too broad # H233: Python 3.x incompatible use of print operator # H234: assertEquals is deprecated, use assertEqual -# H235: assert_ is deprecated, use assertTrue # H301: one import per line # H306: imports not in alphabetical order (time, os) # H401: docstring should not start with a space @@ -71,6 +70,6 @@ commands = bandit -c bandit.yaml -r swift bin -n 5 -p gate # H501: Do not use self.__dict__ for string formatting # H702: Formatting operation should be outside of localization method call # H703: Multiple positional placeholders -ignore = F402,F812,H101,H202,H233,H234,H235,H301,H306,H401,H403,H404,H405,H501,H702,H703 +ignore = F402,F812,H101,H202,H233,H234,H301,H306,H401,H403,H404,H405,H501,H702,H703 exclude = .venv,.tox,dist,doc,*egg show-source = True