def test_from_code_array(self): """Test from_code_array method""" self.xls_in.to_code_array() wb = xlwt.Workbook() xls_out = Xls(self.code_array, wb) worksheets = [] xls_out._shape2xls(worksheets) xls_out._code2xls(worksheets) xls_out._row_heights2xls(worksheets) self.write_xls_out(xls_out, wb, "_col_widths2xls", worksheets) new_code_array = CodeArray((1000, 100, 3)) xls_outfile = xlrd.open_workbook(self.xls_outfile_path, formatting_info=True) xls_out = Xls(new_code_array, xls_outfile) xls_out.to_code_array() assert self.code_array.shape == new_code_array.shape assert self.code_array.macros == new_code_array.macros assert self.code_array.dict_grid == new_code_array.dict_grid # There may be additional standard heights in copy --> 1 way test for height in self.code_array.row_heights: assert height in new_code_array.row_heights assert self.code_array.col_widths == new_code_array.col_widths # Clean up the test dir os.remove(self.xls_outfile_path)
def test_shape2xls(self, tabs, res): """Test _shape2xls method""" self.code_array.dict_grid.shape = (99, 99, tabs) workbook = xlwt.Workbook() xls_out = Xls(self.code_array, workbook) self.write_xls_out(xls_out, workbook, "_shape2xls", []) workbook = self.read_xls_out() assert len(workbook.sheets()) == res
def test_pys_width2xls_width(self, pys_width): """Unit test for pys_width2xls_width and xls_width2pys_width Roundtrip test """ wb = xlwt.Workbook() xls_out = Xls(self.code_array, wb) xls_width = xls_out.pys_width2xls_width(pys_width) roundtrip_width = xls_out.xls_width2pys_width(xls_width) assert round(pys_width) == round(roundtrip_width)
def setup_method(self, method): """Creates Xls class with code_array and temporary test.xls file""" # All data structures are initially empty # The test file xls_file has entries in each category self.top_window = wx.Frame(None, -1) wx.GetApp().SetTopWindow(self.top_window) self.code_array = CodeArray((1000, 100, 3)) self.xls_infile = xlrd.open_workbook(TESTPATH + "xls_test1.xls", formatting_info=True) self.xls_outfile_path = TESTPATH + "xls_test2.xls" self.xls_in = Xls(self.code_array, self.xls_infile)
def test_col_widths2xls(self, col, tab, width): """Test _col_widths2xls method""" self.code_array.shape = (1000, 100, 30) self.code_array.dict_grid.col_widths = {(col, tab): width} wb = xlwt.Workbook() xls_out = Xls(self.code_array, wb) worksheets = [] xls_out._shape2xls(worksheets) self.write_xls_out(xls_out, wb, "_col_widths2xls", worksheets) workbook = self.read_xls_out() points = xls_out.pys_width2xls_width(width) worksheets = workbook.sheets() worksheet = worksheets[tab] assert worksheet.colinfo_map[col].width == points
def test_code2xls(self, key, val, code): """Test _code2xls method""" row, col, tab = key for __key, __val in code: self.code_array[__key] = __val self.code_array.shape = (1000, 100, 3) wb = xlwt.Workbook() xls_out = Xls(self.code_array, wb) worksheets = [] xls_out._shape2xls(worksheets) self.write_xls_out(xls_out, wb, "_code2xls", worksheets) workbook = self.read_xls_out() worksheets = workbook.sheets() worksheet = worksheets[tab] assert worksheet.cell_value(row, col) == val
def test_row_heights2xls(self, row, tab, hpixels): """Test _row_heights2xls method""" self.code_array.shape = (1000, 100, 30) self.code_array.dict_grid.row_heights = {(row, tab): hpixels} wb = xlwt.Workbook() xls_out = Xls(self.code_array, wb) worksheets = [] xls_out._shape2xls(worksheets) self.write_xls_out(xls_out, wb, "_row_heights2xls", worksheets) workbook = self.read_xls_out() worksheets = workbook.sheets() worksheet = worksheets[tab] xlsheight = self._hpixels_to_xlsheight(hpixels) assert worksheet.rowinfo_map[row].height == int(xlsheight)