From f4fbbc177036ef7b88e48889461dfc049e26aa36 Mon Sep 17 00:00:00 2001 From: Ngo Quoc Cuong Date: Mon, 10 Jul 2017 02:55:20 -0400 Subject: [PATCH] Fix N529 Method's default argument should not be mutable See: [1] http://python-guide-pt-br.readthedocs.io/en/latest/writing/gotchas/#mutable-default-arguments Partial-Bug: #1704691 Change-Id: Ibd202f1970a6138299648040f635278ba9d9d71b --- .../tests/unit/connector/cloudconnector/test_openstack.py | 8 ++++++-- fuxi/tests/unit/connector/test_osbrickconnector.py | 8 ++++++-- fuxi/tests/unit/fake_client.py | 4 +++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/fuxi/tests/unit/connector/cloudconnector/test_openstack.py b/fuxi/tests/unit/connector/cloudconnector/test_openstack.py index 2eb3c58..7510d4b 100644 --- a/fuxi/tests/unit/connector/cloudconnector/test_openstack.py +++ b/fuxi/tests/unit/connector/cloudconnector/test_openstack.py @@ -23,7 +23,9 @@ from cinderclient import exceptions as cinder_exception from novaclient import exceptions as nova_exception -def mock_list_with_attach_to_this(cls, search_opts={}): +def mock_list_with_attach_to_this(cls, search_opts=None): + if search_opts is None: + search_opts = {} attachments = [{u'server_id': u'123', u'attachment_id': u'123', u'attached_at': u'2016-05-20T09:19:57.000000', @@ -34,7 +36,9 @@ def mock_list_with_attach_to_this(cls, search_opts={}): attachments=attachments)] -def mock_list_with_attach_to_other(cls, search_opts={}): +def mock_list_with_attach_to_other(cls, search_opts=None): + if search_opts is None: + search_opts = {} attachments = [{u'server_id': u'1234', u'attachment_id': u'123', u'attached_at': u'2016-05-20T09:19:57.000000', diff --git a/fuxi/tests/unit/connector/test_osbrickconnector.py b/fuxi/tests/unit/connector/test_osbrickconnector.py index cd57d86..d8556cc 100644 --- a/fuxi/tests/unit/connector/test_osbrickconnector.py +++ b/fuxi/tests/unit/connector/test_osbrickconnector.py @@ -38,7 +38,9 @@ def mock_get_connector_properties(multipath=False, enforce_multipath=False): return props -def mock_list_with_attach_to_this(cls, search_opts={}): +def mock_list_with_attach_to_this(cls, search_opts=None): + if search_opts is None: + search_opts = {} attachments = [{u'server_id': u'123', u'attachment_id': u'123', u'attached_at': u'2016-05-20T09:19:57.000000', @@ -49,7 +51,9 @@ def mock_list_with_attach_to_this(cls, search_opts={}): attachments=attachments)] -def mock_list_with_attach_to_other(cls, search_opts={}): +def mock_list_with_attach_to_other(cls, search_opts=None): + if search_opts is None: + search_opts = {} attachments = [{u'server_id': u'123', u'attachment_id': u'123', u'attached_at': u'2016-05-20T09:19:57.000000', diff --git a/fuxi/tests/unit/fake_client.py b/fuxi/tests/unit/fake_client.py index 7df52a5..2ad76bf 100644 --- a/fuxi/tests/unit/fake_client.py +++ b/fuxi/tests/unit/fake_client.py @@ -20,7 +20,9 @@ class FakeCinderClient(object): def get(self, volume_id): return fake_object.FakeCinderVolume(id=volume_id) - def list(self, search_opts={}): + def list(self, search_opts=None): + if search_opts is None: + search_opts = {} return [fake_object.FakeCinderVolume(name='fake-vol1')] def create(self, *args, **kwargs):