From 48a4c8b4935203d18419f2d851cc258a625dbc4b Mon Sep 17 00:00:00 2001 From: zhangyangyang Date: Thu, 14 Sep 2017 14:48:50 +0800 Subject: [PATCH] change assert(Not)Equals to assert(Not)Equal According to http://docs.python.org/2/library/unittest.html assert(Not)Equals is a deprecated alias of assert(Not)Equal. Change-Id: I75845cb9b71bcbaec76e12492b38260e09a2df13 Closes-Bug: #1329757 --- test/functional/swift_on_file_tests.py | 2 +- test/functional/tests.py | 2 +- .../common/middleware/test_constraints.py | 30 +++++++++---------- test/unit/obj/test_diskfile.py | 7 +++-- test/unit/obj/test_server.py | 4 +-- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/test/functional/swift_on_file_tests.py b/test/functional/swift_on_file_tests.py index 26c045c..1fabfb3 100644 --- a/test/functional/swift_on_file_tests.py +++ b/test/functional/swift_on_file_tests.py @@ -134,7 +134,7 @@ class TestSwiftOnFile(Base): file_name), 'r') data_read_from_mountP = fhOnMountPoint.read() md5_returned = hashlib.md5(data_read_from_mountP).hexdigest() - self.assertEquals(md5_returned, file_info['etag']) + self.assertEqual(md5_returned, file_info['etag']) fhOnMountPoint.close() def test_GET_on_file_created_over_mountpoint(self): diff --git a/test/functional/tests.py b/test/functional/tests.py index 5f0a89d..926219f 100644 --- a/test/functional/tests.py +++ b/test/functional/tests.py @@ -2872,7 +2872,7 @@ class TestObjectVersioning(Base): container = self.env.container versions_container = self.env.versions_container cont_info = container.info() - self.assertEquals(cont_info['versions'], versions_container.name) + self.assertEqual(cont_info['versions'], versions_container.name) obj_name = Utils.create_name() diff --git a/test/unit/common/middleware/test_constraints.py b/test/unit/common/middleware/test_constraints.py index 14b0c30..0fa9b32 100644 --- a/test/unit/common/middleware/test_constraints.py +++ b/test/unit/common/middleware/test_constraints.py @@ -57,7 +57,7 @@ class TestConstraintsMiddleware(unittest.TestCase): self.policies_mock = Mock() self.sof_policy_mock = Mock() self.sof_policy_mock.name = 'swiftonfile' - attrs = {'get_by_index.return_value': self.sof_policy_mock } + attrs = {'get_by_index.return_value': self.sof_policy_mock} self.policies_mock.configure_mock(**attrs) self.test_check = check_constraints.filter_factory( @@ -67,13 +67,13 @@ class TestConstraintsMiddleware(unittest.TestCase): path = '/V1.0/a/c/o' resp = Request.blank(path, environ={'REQUEST_METHOD': 'GET'} ).get_response(self.test_check) - self.assertEquals(resp.status_int, 200) + self.assertEqual(resp.status_int, 200) def test_PUT_container(self): path = '/V1.0/a/c' resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'} ).get_response(self.test_check) - self.assertEquals(resp.status_int, 200) + self.assertEqual(resp.status_int, 200) def test_PUT_object_with_double_slashes(self): path = '/V1.0/a/c2//o' @@ -85,7 +85,7 @@ class TestConstraintsMiddleware(unittest.TestCase): "POLICIES", self.policies_mock)): resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'} ).get_response(self.test_check) - self.assertEquals(resp.status_int, 400) + self.assertEqual(resp.status_int, 400) self.assertTrue('Invalid object name' in resp.body) self.assertTrue('cannot begin, end, or have' in resp.body) @@ -99,7 +99,7 @@ class TestConstraintsMiddleware(unittest.TestCase): "POLICIES", self.policies_mock)): resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'} ).get_response(self.test_check) - self.assertEquals(resp.status_int, 400) + self.assertEqual(resp.status_int, 400) self.assertTrue('Invalid object name' in resp.body) self.assertTrue('can end with a slash only if it is a directory' in resp.body) @@ -114,7 +114,7 @@ class TestConstraintsMiddleware(unittest.TestCase): "POLICIES", self.policies_mock)): resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'} ).get_response(self.test_check) - self.assertEquals(resp.status_int, 400) + self.assertEqual(resp.status_int, 400) self.assertTrue('Invalid object name' in resp.body) self.assertTrue('cannot have . or ..' in resp.body) @@ -124,7 +124,7 @@ class TestConstraintsMiddleware(unittest.TestCase): resp = Request.blank(path, method='PUT', headers={'X-Storage-Policy': 'swiftonfile'} ).get_response(self.test_check) - self.assertEquals(resp.status_int, 400) + self.assertEqual(resp.status_int, 400) # test case where storage policy is not defined in header and # container would be created in default policy, which happens to be @@ -132,15 +132,15 @@ class TestConstraintsMiddleware(unittest.TestCase): default_policies_mock = Mock() sof_policy_mock = Mock() sof_policy_mock.name = 'swiftonfile' - attrs = {'default.return_value': self.sof_policy_mock } + attrs = {'default.return_value': self.sof_policy_mock} default_policies_mock.configure_mock(**attrs) with patch("swiftonfile.swift.common.middleware.check_constraints." "POLICIES", default_policies_mock): - resp = Request.blank(path, method='PUT').get_response(self.test_check) - self.assertEquals(resp.status_int, 400) + resp = Request.blank(path, method='PUT').get_response(self.test_check) + self.assertEqual(resp.status_int, 400) def test_PUT_object_with_long_names(self): - for i in (220,221): + for i in (220, 221): longname = 'o' * i path = '/V1.0/a/c2/' + longname @@ -152,7 +152,7 @@ class TestConstraintsMiddleware(unittest.TestCase): "check_constraints.POLICIES", self.policies_mock)): resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'} ).get_response(self.test_check) - self.assertEquals(resp.status_int, 200) + self.assertEqual(resp.status_int, 200) longname = 'o' * 222 path = '/V1.0/a/c2/' + longname @@ -164,7 +164,7 @@ class TestConstraintsMiddleware(unittest.TestCase): "POLICIES", self.policies_mock)): resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'} ).get_response(self.test_check) - self.assertEquals(resp.status_int, 400) + self.assertEqual(resp.status_int, 400) self.assertTrue('too long' in resp.body) def test_PUT_object_with_policy0(self): @@ -175,7 +175,7 @@ class TestConstraintsMiddleware(unittest.TestCase): self.container1_info_mock): resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'} ).get_response(self.test_check) - self.assertEquals(resp.status_int, 200) + self.assertEqual(resp.status_int, 200) longname = 'o' * 222 path = '/V1.0/a/c2/' + longname @@ -184,4 +184,4 @@ class TestConstraintsMiddleware(unittest.TestCase): "get_container_info", self.container1_info_mock): resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'} ).get_response(self.test_check) - self.assertEquals(resp.status_int, 200) + self.assertEqual(resp.status_int, 200) diff --git a/test/unit/obj/test_diskfile.py b/test/unit/obj/test_diskfile.py index a01aa0b..136dc96 100644 --- a/test/unit/obj/test_diskfile.py +++ b/test/unit/obj/test_diskfile.py @@ -100,6 +100,7 @@ class MockRenamerCalled(Exception): def _mock_renamer(a, b): raise MockRenamerCalled() + class TestDiskFileWriter(unittest.TestCase): """ Tests for swiftonfile.swift.obj.diskfile.DiskFileWriter """ @@ -119,6 +120,7 @@ class TestDiskFileWriter(unittest.TestCase): self.assertEqual(None, dw._fd) self.assertEqual(1, mock_close.call_count) + class TestDiskFile(unittest.TestCase): """ Tests for swiftonfile.swift.obj.diskfile """ @@ -561,7 +563,7 @@ class TestDiskFile(unittest.TestCase): md = {'Content-Type': 'application/octet-stream', 'a': 'b'} gdf.write_metadata(md.copy()) self.assertTrue(_metadata[_mapit(the_file)]['a'], 'b') - newmd = {'X-Object-Meta-test':'1234'} + newmd = {'X-Object-Meta-test': '1234'} gdf.write_metadata(newmd.copy()) on_disk_md = _metadata[_mapit(the_file)] self.assertTrue(on_disk_md['Content-Length'], 4) @@ -604,7 +606,7 @@ class TestDiskFile(unittest.TestCase): the_dir = os.path.join(the_cont, "dir") os.makedirs(the_dir) gdf = self._get_diskfile("vol0", "p57", "ufo47", "bar", "dir") - self.assertEquals(gdf._metadata, None) + self.assertEqual(gdf._metadata, None) init_md = { 'X-Type': 'Object', 'Content-Length': 0, @@ -632,7 +634,6 @@ class TestDiskFile(unittest.TestCase): DIR_OBJECT) self.assertFalse('X-Object-Meta-test' in _metadata[_mapit(the_dir)]) - def test_write_metadata_w_meta_file(self): the_path = os.path.join(self.td, "vol0", "ufo47", "bar") the_file = os.path.join(the_path, "z") diff --git a/test/unit/obj/test_server.py b/test/unit/obj/test_server.py index dcf8da0..c1cdd88 100644 --- a/test/unit/obj/test_server.py +++ b/test/unit/obj/test_server.py @@ -54,11 +54,11 @@ class TestObjectController(unittest.TestCase): environ={'REQUEST_METHOD': 'REPLICATE'}, headers={}) resp = req.get_response(self.object_controller) - self.assertEquals(resp.status_int, 501) # HTTPNotImplemented + self.assertEqual(resp.status_int, 501) # HTTPNotImplemented def test_REPLICATION(self): req = Request.blank('/sda1/p/suff', environ={'REQUEST_METHOD': 'REPLICATION'}, headers={}) resp = req.get_response(self.object_controller) - self.assertEquals(resp.status_int, 501) # HTTPNotImplemented + self.assertEqual(resp.status_int, 501) # HTTPNotImplemented