def testPrintEmptyTable(self):
        formatter = table_formatter.SparsePrettyFormatter(
            skip_header_when_empty=False)
        formatter.AddColumns(('a', 'b'))
        table_repr = '\n'.join(('  a   b  ', ' --- --- '))
        self.assertEquals(table_repr, str(formatter))

        formatter = table_formatter.SparsePrettyFormatter()
        formatter.AddColumns(('a', 'b'))
        self.assertEquals(table_repr, str(formatter))

        formatter = table_formatter.SparsePrettyFormatter(
            skip_header_when_empty=True)
        formatter.AddColumns(('a', 'b'))
        self.assertEquals('', str(formatter))
 def testFormatHeader(self):
     formatter = table_formatter.SparsePrettyFormatter()
     formatter.AddColumns(('a', 'bcd\nefgh'))
     formatter.AddRow(['really long string', ''])
     self.assertEqual([
         '          a            bcd   ', '                       efgh  ',
         ' -------------------- ------ '
     ], list(formatter.FormatHeader()))
 def testEastAsian(self):
     formatter = table_formatter.SparsePrettyFormatter(
         skip_header_when_empty=False)
     formatter.AddColumns(('a', 'b'))
     formatter.AddRow([u'中文', u'中文'])
     formatter.AddRow([u'日本語', u'日本語'])
     table_repr = '\n'.join((
         '    a        b     ',
         ' -------- -------- ',
         '  中文     中文    ',
         '  日本語   日本語  ',
     ))
     table_repr = six.ensure_str(table_repr)
     self.assertEqual(table_repr, formatter._EncodedStr('utf8'))