def test(file_path, markdown_file_path): file_path = 'temp2.csv' loader = ExcelTableFileLoader(file_path) writer = MarkdownTableWriter() writer.is_write_header = False tabledata = loader.load() tabledata[1] = tabledata[2][0] writer.from_tabledata(tabledata, False) #writer.table_name=table_name writer.dump(markdown_file_path)
def test_normal_multi_sheet(self, tmpdir): for writer_class in table_writer_class_list: test_filepath = str(tmpdir.join("test.xlsx")) data_list = [ TableData( table_name="first", header_list=["ha1", "hb1", "hc1"], row_list=[[1.0, 2.0, 3.0], [11.0, 12.0, 13.0]], ), TableData( table_name="second", header_list=["ha2", "hb2", "hc2"], row_list=[[11.0, 12.0, 13.0], [1.0, 2.0, 3.0]], ), ] writer = writer_class() for data in data_list: writer.from_tabledata(data) writer.dump(test_filepath, close_after_write=False) writer.close() for data, expected in zip( data_list, ExcelTableFileLoader(test_filepath).load()): assert data == expected
def test_normal_single_sheet(self, tmpdir): for writer_class in table_writer_class_list: test_filepath = str(tmpdir.join("test.xlsx")) data = TableData( table_name="tablename", header_list=["ha", "hb", "hc"], row_list=[ [1.0, 2.0, 3.0], [11.0, 12.0, 13.0], [1.0, 2.0, 3.0], [11.0, 12.0, 13.0], [101.0, 102.0, 103.0], [1001.0, 1002.0, 1003.0], ], ) writer = writer_class() writer.from_tabledata(data) writer.dump(test_filepath) assert writer.first_data_row == 1 assert writer.last_data_row == 7 for expected in ExcelTableFileLoader(test_filepath).load(): assert data == expected
def test_normal(self, tmpdir, writer_class, table, header, value, expected): if writer_class == ptw.ExcelXlsTableWriter and not HAS_XLWT: pytest.skip() test_file_path = tmpdir.join("test.xlsx") writer = writer_class() writer.open(str(test_file_path)) writer.make_worksheet(table) writer.headers = header writer.value_matrix = value writer.iteration_length = len(value) writer.write_table_iter() writer.close() assert writer.first_data_row == 1 assert writer.last_data_row == 7 for table_data in ExcelTableFileLoader(str(test_file_path)).load(): assert table_data == expected
def test_normal(self, tmpdir, writer_class, table, header, value, expected): if writer_class == ptw.ExcelXlsTableWriter and not HAS_XLWT: pytest.skip() test_file_path = tmpdir.join("test.xlsx") writer = writer_class() writer.open(str(test_file_path)) writer.make_worksheet(table) writer.headers = header writer.value_matrix = value writer.write_table() writer.close() for table_data in ExcelTableFileLoader(str(test_file_path)).load(): expected_dump = ptw.dumps_tabledata(expected) actual_dump = ptw.dumps_tabledata(table_data) print_test_result(expected=expected_dump, actual=actual_dump) assert actual_dump == expected_dump