Use None instead of mutables in test method params defaults

Mutables in the method params defaults might cause errors and
that's why it's anti-pattern in most of the cases and should be
removed.

Change-Id: Ie9897aae6e95962e0991ac9d9fc5c175f2da12a4
This commit is contained in:
Ilya Tyaptin 2014-07-21 18:43:05 +04:00
parent 9164d6f60b
commit ea7978d946
4 changed files with 14 additions and 12 deletions

View File

@ -154,11 +154,11 @@ class TestCoordinate(tests_base.BaseTestCase):
return (pid, younger)
def _check_assignments(self, others, alarm_ids, per_worker,
expect_uneffected=[]):
expect_uneffected=None):
rpc = self.partition_coordinator.coordination_rpc
calls = rpc.assign.call_args_list
return self._check_distribution(others, alarm_ids, per_worker, calls,
expect_uneffected)
expect_uneffected or [])
def _check_allocation(self, others, alarm_ids, per_worker):
rpc = self.partition_coordinator.coordination_rpc
@ -166,7 +166,8 @@ class TestCoordinate(tests_base.BaseTestCase):
return self._check_distribution(others, alarm_ids, per_worker, calls)
def _check_distribution(self, others, alarm_ids, per_worker, calls,
expect_uneffected=[]):
expect_uneffected=None):
expect_uneffected = expect_uneffected or []
uneffected = [pid for pid, _ in others]
uneffected.extend(expect_uneffected)
remainder = list(alarm_ids)

View File

@ -1294,12 +1294,12 @@ class TestAlarms(v2.FunctionalTest,
alarms[0].rule.get('alarm_ids'))
def _test_post_alarm_combination_rule_less_than_two_alarms(self,
alarm_ids=[]):
alarm_ids=None):
json_body = {
'name': 'one_alarm_in_combination_rule',
'type': 'combination',
'combination_rule': {
'alarm_ids': alarm_ids
'alarm_ids': alarm_ids or []
}
}
@ -1511,12 +1511,12 @@ class TestAlarms(v2.FunctionalTest,
self.assertEqual(msg, resp.json['error_message']['faultstring'])
def _test_put_alarm_combination_rule_less_than_two_alarms(self,
alarm_ids=[]):
alarm_ids=None):
json_body = {
'name': 'name4',
'type': 'combination',
'combination_rule': {
'alarm_ids': alarm_ids
'alarm_ids': alarm_ids or []
}
}

View File

@ -35,8 +35,9 @@ from ceilometer.tests import base as tests_base
class FakeApp(object):
def __init__(self, body=['This string is 28 bytes long']):
self.body = body
def __init__(self, body=None):
self.body = body or ['This string is 28 bytes long']
def __call__(self, env, start_response):
yield

View File

@ -35,14 +35,14 @@ from ceilometer.tests import db as tests_db
class DBTestBase(tests_db.TestBase):
def create_and_store_sample(self, timestamp=datetime.datetime.utcnow(),
metadata={
'display_name': 'test-server',
'tag': 'self.counter'},
metadata=None,
name='instance',
sample_type=sample.TYPE_CUMULATIVE, unit='',
volume=1, user_id='user-id',
project_id='project-id',
resource_id='resource-id', source=None):
metadata = metadata or {'display_name': 'test-server',
'tag': 'self.counter'}
s = sample.Sample(
name, sample_type, unit=unit, volume=volume, user_id=user_id,
project_id=project_id, resource_id=resource_id,