def test_bold_text_table(self): # bold version data = [['a', 'Ä'], [1, 2]] print_table(data, "title", bold=True) output = self.out.getvalue().strip() # includes control chars expected_table = u'*** \x1b[31mtitle\x1b[0m ***\n\n' +\ u'+---+---+\n' +\ u'| \x1b[32ma\x1b[0m | \x1b[32mÄ\x1b[0m |\n' +\ u'+---+---+\n' +\ u'| \x1b[32m1\x1b[0m | 2 |\n' +\ u'+---+---+' self.assertEqual(output, expected_table)
def test_text_table(self): # 2D data data = [['a', 'b', 'c'], [1, 2, 3], [4, 5, 6]] print_table(data, "title", bold=False) output = self.out.getvalue().strip() expected_table = u'*** title ***\n\n' +\ u'+---+---+---+\n' +\ u'| a | b | c |\n' +\ u'+---+---+---+\n' +\ u'| 1 | 2 | 3 |\n' +\ u'| 4 | 5 | 6 |\n' +\ u'+---+---+---+' self.assertEqual(output, expected_table)