def test_notEqual(self):
     cf = ConditionalFormatting()
     redFill = PatternFill(start_color=Color('FFEE1111'),
                           end_color=Color('FFEE1111'),
                           patternType=fills.FILL_SOLID)
     cf.add(
         'U10:U18',
         CellIsRule(operator='notEqual',
                    formula=['U$7'],
                    stopIfTrue=True,
                    fill=redFill))
     cf.add(
         'V10:V18',
         CellIsRule(operator='!=',
                    formula=['V$7'],
                    stopIfTrue=True,
                    fill=redFill))
     cf.setDxfStyles(self.workbook)
     rules = cf.cf_rules
     assert 'U10:U18' in rules
     assert len(cf.cf_rules['U10:U18']) == 1
     assert rules['U10:U18'][0]['priority'] == 1
     assert rules['U10:U18'][0]['type'] == 'cellIs'
     assert rules['U10:U18'][0]['dxfId'] == 0
     assert rules['U10:U18'][0]['operator'] == 'notEqual'
     assert rules['U10:U18'][0]['formula'][0] == 'U$7'
     assert rules['U10:U18'][0]['stopIfTrue'] == '1'
     assert 'V10:V18' in rules
     assert len(cf.cf_rules['V10:V18']) == 1
     assert rules['V10:V18'][0]['priority'] == 2
     assert rules['V10:V18'][0]['type'] == 'cellIs'
     assert rules['V10:V18'][0]['dxfId'] == 1
     assert rules['V10:V18'][0]['operator'] == 'notEqual'
     assert rules['V10:V18'][0]['formula'][0] == 'V$7'
     assert rules['V10:V18'][0]['stopIfTrue'] == '1'
예제 #2
0
def test_operator_expansion(value, expansion):
    cf1 = CellIsRule()
    cf2 = CellIsRule()
    cf1.operator = value
    cf2.operator = expansion
    assert cf1.operator == expansion
    assert cf2.operator == expansion
 def test_equal(self):
     cf = ConditionalFormatting()
     redFill = Fill()
     redFill.start_color.index = 'FFEE1111'
     redFill.end_color.index = 'FFEE1111'
     redFill.fill_type = Fill.FILL_SOLID
     cf.add(
         'U10:U18',
         CellIsRule(operator='equal',
                    formula=['U$7'],
                    stopIfTrue=True,
                    fill=redFill))
     cf.add(
         'V10:V18',
         CellIsRule(operator='=',
                    formula=['V$7'],
                    stopIfTrue=True,
                    fill=redFill))
     cf.add(
         'W10:W18',
         CellIsRule(operator='==',
                    formula=['W$7'],
                    stopIfTrue=True,
                    fill=redFill))
     cf.setDxfStyles(self.workbook)
     rules = cf.cf_rules
     assert 'U10:U18' in rules
     assert len(cf.cf_rules['U10:U18']) == 1
     assert rules['U10:U18'][0]['priority'] == 1
     assert rules['U10:U18'][0]['type'] == 'cellIs'
     assert rules['U10:U18'][0]['dxfId'] == 0
     assert rules['U10:U18'][0]['operator'] == 'equal'
     assert rules['U10:U18'][0]['formula'][0] == 'U$7'
     assert rules['U10:U18'][0]['stopIfTrue'] == '1'
     assert 'V10:V18' in rules
     assert len(cf.cf_rules['V10:V18']) == 1
     assert rules['V10:V18'][0]['priority'] == 2
     assert rules['V10:V18'][0]['type'] == 'cellIs'
     assert rules['V10:V18'][0]['dxfId'] == 1
     assert rules['V10:V18'][0]['operator'] == 'equal'
     assert rules['V10:V18'][0]['formula'][0] == 'V$7'
     assert rules['V10:V18'][0]['stopIfTrue'] == '1'
     assert 'W10:W18' in rules
     assert len(cf.cf_rules['W10:W18']) == 1
     assert rules['W10:W18'][0]['priority'] == 3
     assert rules['W10:W18'][0]['type'] == 'cellIs'
     assert rules['W10:W18'][0]['dxfId'] == 2
     assert rules['W10:W18'][0]['operator'] == 'equal'
     assert rules['W10:W18'][0]['formula'][0] == 'W$7'
     assert rules['W10:W18'][0]['stopIfTrue'] == '1'
    def test_conditional_font(self):
        """Test to verify font style written correctly."""
        class WS():
            conditional_formatting = ConditionalFormatting()

        worksheet = WS()

        # Create cf rule
        redFill = PatternFill(start_color=Color('FFEE1111'),
                              end_color=Color('FFEE1111'),
                              patternType=fills.FILL_SOLID)
        whiteFont = Font(color=Color("FFFFFFFF"))
        worksheet.conditional_formatting.add(
            'A1:A3',
            CellIsRule(operator='equal',
                       formula=['"Fail"'],
                       stopIfTrue=False,
                       font=whiteFont,
                       fill=redFill))
        worksheet.conditional_formatting.setDxfStyles(self.workbook)

        # First, verify conditional formatting xml
        cfs = write_conditional_formatting(worksheet)
        xml = b""
        for cf in cfs:
            xml += tostring(cf)

        diff = compare_xml(
            xml, """
        <conditionalFormatting sqref="A1:A3">
          <cfRule dxfId="0" operator="equal" priority="1" type="cellIs">
            <formula>"Fail"</formula>
          </cfRule>
        </conditionalFormatting>
        """)
        assert diff is None, diff

        # Second, verify conditional formatting dxf styles
        w = StyleWriter(self.workbook)
        w._write_dxfs()
        xml = tostring(w._root)
        diff = compare_xml(
            xml, """
        <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
          <dxfs count="1">
            <dxf>
              <font>
                <color rgb="FFFFFFFF" />
              </font>
              <fill>
                <patternFill patternType="solid">
                  <fgColor rgb="FFEE1111" />
                  <bgColor rgb="FFEE1111" />
                </patternFill>
              </fill>
            </dxf>
          </dxfs>
        </styleSheet>
        """)
        assert diff is None, diff
예제 #5
0
def test_operator_expansion(value, expansion):
    cf1 = CellIsRule()
    cf2 = CellIsRule()
    cf1.operator = value
    cf2.operator = expansion
    assert cf1.operator == expansion
    assert cf2.operator == expansion
예제 #6
0
    def test_conditional_font(self):
        """Test to verify font style written correctly."""
        class WS():
            conditional_formatting = ConditionalFormatting()

        worksheet = WS()

        # Create cf rule
        redFill = PatternFill(start_color=Color('FFEE1111'),
                              end_color=Color('FFEE1111'),
                              patternType=fills.FILL_SOLID)
        whiteFont = Font(color=Color("FFFFFFFF"))
        worksheet.conditional_formatting.add(
            'A1:A3',
            CellIsRule(operator='equal',
                       formula=['"Fail"'],
                       stopIfTrue=False,
                       font=whiteFont,
                       fill=redFill))
        worksheet.conditional_formatting._save_styles(self.workbook)

        # First, verify conditional formatting xml
        cfs = write_conditional_formatting(worksheet)
        xml = b""
        for cf in cfs:
            xml += tostring(cf)

        diff = compare_xml(
            xml, """
        <conditionalFormatting sqref="A1:A3">
          <cfRule dxfId="0" operator="equal" priority="1" type="cellIs">
            <formula>"Fail"</formula>
          </cfRule>
        </conditionalFormatting>
        """)
        assert diff is None, diff
    def test_conditional_font(self):
        """Test to verify font style written correctly."""
        class WS():
            conditional_formatting = ConditionalFormatting()

        worksheet = WS()

        # Create cf rule
        redFill = Fill()
        redFill.start_color.index = 'FFEE1111'
        redFill.end_color.index = 'FFEE1111'
        redFill.fill_type = Fill.FILL_SOLID
        whiteFont = Font()
        whiteFont.color.index = "FFFFFFFF"
        worksheet.conditional_formatting.add(
            'A1:A3',
            CellIsRule(operator='equal',
                       formula=['"Fail"'],
                       stopIfTrue=False,
                       font=whiteFont,
                       fill=redFill))
        worksheet.conditional_formatting.setDxfStyles(self.workbook)

        # First, verify conditional formatting xml
        temp_buffer = StringIO()
        doc = XMLGenerator(out=temp_buffer, encoding='utf-8')
        write_worksheet_conditional_formatting(doc, worksheet)
        doc.endDocument()
        xml = temp_buffer.getvalue()
        temp_buffer.close()
        diff = compare_xml(
            xml, """
        <conditionalFormatting sqref="A1:A3">
          <cfRule dxfId="0" operator="equal" priority="1" type="cellIs">
            <formula>"Fail"</formula>
          </cfRule>
        </conditionalFormatting>
        """)
        assert diff is None, diff

        # Second, verify conditional formatting dxf styles
        w = StyleWriter(self.workbook)
        w._write_dxfs()
        xml = get_xml(w._root)
        diff = compare_xml(
            xml, """
        <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
          <dxfs count="1">
            <dxf>
              <font>
                <color rgb="FFFFFFFF" />
              </font>
              <fill>
                <patternFill patternType="solid">
                  <fgColor rgb="FFEE1111" />
                  <bgColor rgb="FFEE1111" />
                </patternFill>
              </fill>
            </dxf>
          </dxfs>
        </styleSheet>
        """)
        assert diff is None, diff