Beispiel #1
0
    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)
Beispiel #2
0
    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)
Beispiel #3
0
    def test_col_widths2xls(self, col, tab, width, points):
        """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()

        worksheets = workbook.sheets()
        worksheet = worksheets[tab]
        assert worksheet.colinfo_map[col].width == points
Beispiel #4
0
    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
Beispiel #5
0
    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
Beispiel #6
0
    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
Beispiel #7
0
    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)
Beispiel #8
0
    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)