From 50fbaf0fa23d3d6e89a45eb104b4cdea626b3e84 Mon Sep 17 00:00:00 2001 From: George Yoshida Date: Thu, 27 Mar 2014 02:01:30 +0900 Subject: [PATCH] fix table output for multibyte characters Encoding unicode text with `str` does not work for multibyte characters. --- awscli/table.py | 3 ++- tests/unit/test_table.py | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/awscli/table.py b/awscli/table.py index 8d355375ef2c..0bb5f991d05d 100644 --- a/awscli/table.py +++ b/awscli/table.py @@ -15,6 +15,7 @@ import struct import colorama +import six def determine_terminal_width(default_width=80): @@ -397,7 +398,7 @@ def add_row(self, row): self._update_max_widths(row) def _format_row(self, row): - return [str(r) for r in row] + return [six.text_type(r) for r in row] def _update_max_widths(self, row): if not self._max_widths: diff --git a/tests/unit/test_table.py b/tests/unit/test_table.py index 76ccbb50ea5c..0cf78a63b421 100644 --- a/tests/unit/test_table.py +++ b/tests/unit/test_table.py @@ -83,6 +83,14 @@ def test_title_accounts_for_outer_padding(self): self.assertEqual( self.section.total_width(padding=2, outer_padding=3), 17) + def test_unicode_text_row(self): + self.section.add_row([1]) + self.section.add_row(['check']) + self.section.add_row([u'\u2713']) + self.assertEqual( + self.section.rows, + [[u'1'], [u'check'], [u'\u2713']]) + class TestMultiTable(unittest.TestCase): def setUp(self):