def test_override_format(self): """ Checks that the format can be specified when the table is created :return: """ headers, data = self.get_data() table = Table(data, headers, title='Test Title') table_text = table.get_text(tablefmt='simple') expected_table = """Test Title header 1 header 2 header 3 ---------- ---------- ---------- cell11 1.2 cell13 cell21 21 cell23 cell31 3.2 cell33 """ self.assertEqual(str(table_text), expected_table)
def test_flask_title(self): """ Basic test """ headers, data = self.get_data() table = Table(data, headers, title='Test Title') flask_title = table.title_flask self.assertEqual(flask_title, '"Test Title"')
def test_create_table(self): """ Basic test """ headers, data = self.get_data() table = Table(data, headers, title='Test Title') table_text = table.get_text() expected_table = """Test Title +------------+------------+------------+ | header 1 | header 2 | header 3 | +============+============+============+ | cell11 | 1.2 | cell13 | +------------+------------+------------+ | cell21 | 21 | cell23 | +------------+------------+------------+ | cell31 | 3.2 | cell33 | +------------+------------+------------+ """ self.assertEqual(table_text, expected_table)
def test_override_columns(self): """ Checks that the format can be specified when the table is created :return: """ headers, data = self.get_data() table = Table(data, headers, title='Test Title') table_text = table.get_text(columns=2) expected_table = """Test Title +------------+------------+------------+ +------------+------------+------------+ | header 1 | header 2 | header 3 | | header 1 | header 2 | header 3 | +============+============+============+ +============+============+============+ | cell11 | 1.2 | cell13 | | cell31 | 3.2 | cell33 | +------------+------------+------------+ +------------+------------+------------+ | cell21 | 21 | cell23 | +------------+------------+------------+ """ self.assertEqual(str(table_text), expected_table)
def test_override_table_orientation(self): """ Checks that the format can be specified when the table is created :return: """ headers, data = self.get_data() table = Table(data, headers, title='Test Title') table_text = table.get_text(table_orientation='vertical') expected_table = """Test Title +----------+--------+--------+--------+ | header 1 | cell11 | cell21 | cell31 | +----------+--------+--------+--------+ | header 2 | 1.2 | 21.0 | 3.20 | +----------+--------+--------+--------+ | header 3 | cell13 | cell23 | cell33 | +----------+--------+--------+--------+ """ self.assertEqual(str(table_text), expected_table)
def test_set_table_orientation(self): """ Checks that the format can be specified when the table is created :return: """ headers, data = self.get_data() table = Table(data, headers, title='Test Title', table_orientation='vertical') table_text = table.get_text() expected_table = """Test Title +----------+--------+--------+--------+ | header 1 | cell11 | cell21 | cell31 | +----------+--------+--------+--------+ | header 2 | 1.2 | 21.0 | 3.20 | +----------+--------+--------+--------+ | header 3 | cell13 | cell23 | cell33 | +----------+--------+--------+--------+ """ self.assertEqual(str(table_text), expected_table)
def test_set_numalign(self): """ Checks that the format can be specified when the table is created :return: """ headers, data = self.get_data() table = Table(data, headers, title='Test Title', numalign='right') table_text = table.get_text() expected_table = """Test Title +------------+------------+------------+ | header 1 | header 2 | header 3 | +============+============+============+ | cell11 | 1.2 | cell13 | +------------+------------+------------+ | cell21 | 21 | cell23 | +------------+------------+------------+ | cell31 | 3.2 | cell33 | +------------+------------+------------+ """ self.assertEqual(str(table_text), expected_table)
def test_fix_str_in_data(self): """ Checks that any cell with None as the data is converted to a space :return: """ headers, data = self.get_data() data[1][2] = 5 table = Table(data, headers, title='Test Title') table_text = table.get_text() expected_table = """Test Title +------------+------------+------------+ | header 1 | header 2 | header 3 | +============+============+============+ | cell11 | 1.2 | cell13 | +------------+------------+------------+ | cell21 | 21 | 5 | +------------+------------+------------+ | cell31 | 3.2 | cell33 | +------------+------------+------------+ """ self.assertEqual(str(table_text), expected_table)