Convert to int can cause different error messages

Starting from python3.4.3 casting list to int, i.e. int([]) returns
exception with another messge. Try to fix.

Co-Authored-By: Pavlo Shchelokovskyy <pshchelokovskyy@mirantis.com>
Closes-Bug: #1499470
Change-Id: I2a312a58ed4b722b998a0ba26a8d2b8fcdc99bd6
This commit is contained in:
Oleksii Chuprykov 2015-09-24 20:26:51 +03:00
parent 8f1ff524f8
commit 2f2a91d2bb
2 changed files with 12 additions and 9 deletions

View File

@ -420,12 +420,13 @@ class CeilometerAlarmTest(common.HeatTestCase):
resource_defns = stack.t.resource_definitions(stack)
rsrc = alarm.CeilometerAlarm(
'MEMAlarmHigh', resource_defns['MEMAlarmHigh'], stack)
error = self.assertRaises(exception.StackValidationFailed,
rsrc.validate)
self.assertEqual(
"Property error: Resources.MEMAlarmHigh.Properties.%s: "
"int() argument must be a string or a number, not "
"'list'" % p, six.text_type(error))
# python 3.4.3 returns another error message
# so try to handle this by regexp
msg = ("Property error: Resources.MEMAlarmHigh.Properties.%s: "
"int\(\) argument must be a string(, a bytes-like "
"object)? or a number, not 'list'" % p)
self.assertRaisesRegexp(exception.StackValidationFailed,
msg, rsrc.validate)
def test_mem_alarm_high_check_not_required_parameters(self):
snippet = template_format.parse(not_string_alarm_template)

View File

@ -743,9 +743,11 @@ class PropertyTest(common.HeatTestCase):
def test_int_bad(self):
schema = {'Type': 'Integer'}
p = properties.Property(schema)
ex = self.assertRaises(TypeError, p.get_value, [1])
self.assertEqual("int() argument must be a string or a number, "
"not 'list'", six.text_type(ex))
# python 3.4.3 returns another error message
# try to handle this by regexp
self.assertRaisesRegexp(
TypeError, "int\(\) argument must be a string(, a bytes-like "
"object)? or a number, not 'list'", p.get_value, [1])
def test_str_from_int(self):
schema = {'Type': 'String'}