]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Remove use of contextlib.nested (api-tests)
authorankitagrawal <ankit11.agrawal@nttdata.com>
Thu, 14 May 2015 12:19:44 +0000 (05:19 -0700)
committerankitagrawal <ankit11.agrawal@nttdata.com>
Tue, 26 May 2015 09:57:08 +0000 (02:57 -0700)
Removed use of contextlib.nested call from codebase, as it has been
deprecated since Python 2.7.

There are also known issues with contextlib.nested that were addressed
by the native support for multiple "with" variables. For instance, if
the first object is created but the second one throws an exception,
the first object's __exit__ is never called. For more information see
https://docs.python.org/2/library/contextlib.html#contextlib.nested
contextlib.nested is also not compatible with Python 3.

Multi-patch set for easier chunks. This one addresses the tests from
neutron/tests/unit/api directory.

Line continuation markers (e.g. '\') had to be used or syntax
errors were thrown. While using parentheses is the preferred way
for multiple line statements, but in case of long with statements
backslashes are acceptable.

Partial-Bug: 1428424
Change-Id: I09673f9d4c7f07d3043804676fef018905dd1239

neutron/hacking/checks.py
neutron/tests/unit/api/rpc/handlers/test_securitygroups_rpc.py

index e013b7deb36decc8fb7bed8cd82aedcf0535322e..c2eabbd7771334be665b3dfbbb857243bd2d2424 100644 (file)
@@ -146,7 +146,6 @@ def check_no_contextlib_nested(logical_line, filename):
     # these issues. It should be removed completely
     # when bug 1428424 is closed.
     ignore_dirs = [
-        "neutron/tests/unit/api",
         "neutron/tests/unit/db",
         "neutron/tests/unit/extensions",
         "neutron/tests/unit/plugins",
index 7c8b79f67d1c8b5bdb10ccc58db41fe0b605be5c..6728062091e971e1956c4066e3056d33b191fad6 100644 (file)
@@ -12,7 +12,6 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import contextlib
 import mock
 
 from neutron.api.rpc.handlers import securitygroups_rpc
@@ -24,12 +23,8 @@ class SecurityGroupServerRpcApiTestCase(base.BaseTestCase):
     def test_security_group_rules_for_devices(self):
         rpcapi = securitygroups_rpc.SecurityGroupServerRpcApi('fake_topic')
 
-        with contextlib.nested(
-            mock.patch.object(rpcapi.client, 'call'),
-            mock.patch.object(rpcapi.client, 'prepare'),
-        ) as (
-            rpc_mock, prepare_mock
-        ):
+        with mock.patch.object(rpcapi.client, 'call') as rpc_mock,\
+                mock.patch.object(rpcapi.client, 'prepare') as prepare_mock:
             prepare_mock.return_value = rpcapi.client
             rpcapi.security_group_rules_for_devices('context', ['fake_device'])