示例#1
0
    def test_TradeFormatAddNamedStyle(self):
        '''
        Test the object formation and the creation of the styles in __init__ and addNamedStyle for
        the Workbook. Specifically test that the named style is created and stored in the workbook
        (still there when you close it and open it.)
        '''

        wb = Workbook()
        ws = wb.active
        tf = TradeFormat(wb)

        # Use a list to verify the order
        styleList = list(tf.styles.keys())
        if not os.path.exists("out/"):
            os.mkdir("out/")

        dispath = "out/SCHNOrK.xlsx"
        if os.path.exists(dispath):
            os.remove(dispath)

        # Write one cell for each named style in TradeFormat
        for i, key in enumerate(styleList):
            #     print(key, c((1, i+1)))
            ws[c((1, i + 1))] = key
            ws[c((1, i + 1))].style = tf.styles[key]
        wb.save(dispath)

        wb2 = load_workbook(dispath)
        ws2 = wb2.active

        # Open it back up and check the the named styles are where we think they are
        for i, key in enumerate(styleList):
            #     print(key,ws2[c((1, i+1))].style )
            self.assertEqual(key, ws2[c((1, i + 1))].style)
示例#2
0
    def test_c(self):
        '''Test the function c in the module tradestyle'''
        self.assertEqual(c((3, 4)), 'C4')
        self.assertEqual(c((1, 1), anchor=(4, 5)), 'D5')

        self.assertEqual(c((2, 3), (3, 7)), 'B3:C7')

        self.assertEqual(c((2, 3), (3, 7), (2, 2)), 'C4:D8')
示例#3
0
    def test_formatTrade(self):
        '''
        Test the method TradeFormat.formatTrade. Specifically test that each of the elements in
        srf.tfcolumns has a corresponding elementcorrectly styled in the re-opened workbook and
        that each merged element in srf.tfcolumns is found in the the worsheet.
        '''
        wb = Workbook()
        ws = wb.active

        t = TradeFormat(wb)
        srf = SumReqFields()
        ws = wb.active

        t.formatTrade(ws, srf)

        dispath = "out/SCHNOrK.xlsx"
        if os.path.exists(dispath):
            os.remove(dispath)
        wb.save(dispath)

        wb2 = load_workbook(dispath)
        ws2 = wb2.active

        # test that each listed item in srf.tfcolumns has a corresponding style set in the
        # appropriate cell of the re-opened workbook
        for x in srf.tfcolumns:
            address = srf.tfcolumns[x][0]
            st = srf.tfcolumns[x][1]
            if isinstance(address, list):
                self.assertEqual(ws2[c(address[0])].style, st)
            else:
                self.assertEqual(ws2[c(address)].style, st)

        # test that each list element has a corresponding merged cell group in the worbook
        listofmerge = [
            c(srf.tfcolumns[x][0][0], srf.tfcolumns[x][0][1])
            for x in srf.tfcolumns if isinstance(srf.tfcolumns[x][0], list)
        ]
        wsmerged = ws.merged_cells.ranges
        self.assertEqual(len(listofmerge), len(wsmerged))
        for msmerge in wsmerged:
            self.assertTrue(str(msmerge) in listofmerge)