Merge "Support unicode for alarm"

This commit is contained in:
Jenkins 2015-03-11 08:00:05 +00:00 committed by Gerrit Code Review
commit 5fba56d5c4
2 changed files with 14 additions and 7 deletions

View File

@ -98,12 +98,12 @@ def print_dict(d, dict_property="Property", wrap=0):
col1 = k
for line in lines:
if wrap > 0:
line = textwrap.fill(str(line), wrap)
line = textwrap.fill(six.text_type(line), wrap)
pt.add_row([col1, line])
col1 = ''
else:
if wrap > 0:
v = textwrap.fill(str(v), wrap)
v = textwrap.fill(six.text_type(v), wrap)
pt.add_row([k, v])
encoded = encodeutils.safe_encode(pt.get_string())
# FIXME(gordc): https://bugs.launchpad.net/oslo-incubator/+bug/1370710

View File

@ -43,7 +43,8 @@ class UtilsTest(test_utils.BaseTestCase):
with mock.patch('sys.stdout', new=six.StringIO()) as stdout:
utils.print_dict({'alarm_id': '262567fd-d79a-4bbb-a9d0-59d879b6',
'description': 'test alarm',
'name': u'\u6d4b\u8bd5',
'description': u'\u6d4b\u8bd5',
'state': 'insufficient data',
'repeat_actions': 'False',
'type': 'threshold',
@ -53,13 +54,15 @@ class UtilsTest(test_utils.BaseTestCase):
'\\n description: test,'
'\\n start: 0 18 * * *,'
'\\n duration: 1,'
'\\n timezone: US}]'})
self.assertEqual('''\
'\\n timezone: US}]'},
wrap=72)
expected = u'''\
+------------------+----------------------------------+
| Property | Value |
+------------------+----------------------------------+
| alarm_id | 262567fd-d79a-4bbb-a9d0-59d879b6 |
| description | test alarm |
| description | \u6d4b\u8bd5 |
| name | \u6d4b\u8bd5 |
| repeat_actions | False |
| state | insufficient data |
| statistic | avg |
@ -71,7 +74,11 @@ class UtilsTest(test_utils.BaseTestCase):
| | timezone: US}] |
| type | threshold |
+------------------+----------------------------------+
''', stdout.getvalue())
'''
# py2 prints str type, py3 prints unicode type
if six.PY2:
expected = expected.encode('utf-8')
self.assertEqual(expected, stdout.getvalue())
def test_print_list(self):
class Foo(object):