Exemple #1
0
 def test_ctor(self, DataValidation):
     dv = DataValidation()
     xml = tostring(dv.to_tree())
     expected = """
     <dataValidation allowBlank="0" showErrorMessage="1" showInputMessage="1" sqref="" />
     """
     diff = compare_xml(xml, expected)
     assert diff is None, diff
Exemple #2
0
    def test_add_after_sqref(self, DataValidation):
        class DummyCell:

            coordinate = "A2"

        dv = DataValidation()
        dv.sqref = "A1"
        dv.add(DummyCell())
        assert dv.cells == MultiCellRange("A1 A2")
Exemple #3
0
    def test_writer_validation(self, DataValidation):
        class DummyCell:

            coordinate = "A1"

        dv = DataValidation(type="list", formula1='"Dog,Cat,Fish"')
        dv.add(DummyCell())

        xml = tostring(dv.to_tree())
        expected = """
        <dataValidation allowBlank="0" showErrorMessage="1" showInputMessage="1" sqref="A1" type="list">
          <formula1>&quot;Dog,Cat,Fish&quot;</formula1>
        </dataValidation>
        """
        diff = compare_xml(xml, expected)
        assert diff is None, diff
Exemple #4
0
    def test_from_xml(self, DataValidation):
        src = """
        <root />
        """
        node = fromstring(src)
        dv = DataValidation.from_tree(node)
        assert dv == DataValidation()

        def test_list_validation(DataValidation):
            dv = DataValidation(type="list", formula1='"Dog,Cat,Fish"')
            assert dv.formula1, '"Dog,Cat == Fish"'
            dv_dict = dict(dv)
            assert dv_dict['type'] == 'list'
            assert dv_dict['allowBlank'] == '0'
            assert dv_dict['showErrorMessage'] == '1'
            assert dv_dict['showInputMessage'] == '1'
Exemple #5
0
 def test_empty_dv(self, DataValidationList, DataValidation):
     dv = DataValidation()
     dvs = DataValidationList(dataValidation=[dv])
     xml = tostring(dvs.to_tree())
     expected = '<dataValidations count="0"/>'
     diff = compare_xml(xml, expected)
     assert diff is None, diff
Exemple #6
0
def test_data_validations(WriteOnlyWorksheet):
    from openpyxl25.worksheet.datavalidation import DataValidation
    ws = WriteOnlyWorksheet
    dv = DataValidation(sqref="A1")
    ws.data_validations.append(dv)
    ws.close()

    with open(ws.filename) as src:
        xml = src.read()

    expected = """
    <worksheet xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
    <sheetPr>
      <outlinePr summaryRight="1" summaryBelow="1"/>
      <pageSetUpPr/>
    </sheetPr>
    <sheetViews>
      <sheetView workbookViewId="0">
        <selection sqref="A1" activeCell="A1"/>
       </sheetView>
    </sheetViews>
    <sheetFormatPr baseColWidth="8" defaultRowHeight="15"/>
     <sheetData />
     <dataValidations count="1">
       <dataValidation allowBlank="0" showErrorMessage="1" showInputMessage="1" sqref="A1" />
     </dataValidations>
    </worksheet>"""
    diff = compare_xml(xml, expected)
    assert diff is None, diff
Exemple #7
0
 def test_parser(self, DataValidation):
     xml = """
     <dataValidation xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" type="list" errorStyle="warning" allowBlank="1" showInputMessage="1" showErrorMessage="1" error="Value must be between 1 and 3!" errorTitle="An Error Message" promptTitle="Multiplier" prompt="for monthly or quartely reports" sqref="H6">
     </dataValidation>
     """
     xml = fromstring(xml)
     dv = DataValidation.from_tree(xml)
     assert dv == DataValidation(error="Value must be between 1 and 3!",
                                 errorStyle="warning",
                                 errorTitle="An Error Message",
                                 prompt="for monthly or quartely reports",
                                 promptTitle="Multiplier",
                                 type="list",
                                 allowBlank="1",
                                 sqref="H6",
                                 showErrorMessage="1",
                                 showInputMessage="1")
Exemple #8
0
 def test_list_validation(DataValidation):
     dv = DataValidation(type="list", formula1='"Dog,Cat,Fish"')
     assert dv.formula1, '"Dog,Cat == Fish"'
     dv_dict = dict(dv)
     assert dv_dict['type'] == 'list'
     assert dv_dict['allowBlank'] == '0'
     assert dv_dict['showErrorMessage'] == '1'
     assert dv_dict['showInputMessage'] == '1'
Exemple #9
0
 def test_read_formula(self, DataValidation):
     xml = """
     <dataValidation xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" allowBlank="0" showErrorMessage="1" showInputMessage="1" sqref="A1" type="list">
       <formula1>&quot;Dog,Cat,Fish&quot;</formula1>
     </dataValidation>
     """
     xml = fromstring(xml)
     dv = DataValidation.from_tree(xml)
     assert dv.type == "list"
     assert dv.formula1 == '"Dog,Cat,Fish"'
Exemple #10
0
 def test_sqref(self, DataValidation):
     dv = DataValidation(sqref="A1")
     assert dv.sqref == MultiCellRange("A1")
Exemple #11
0
 def test_hide_drop_down(self, DataValidation):
     dv = DataValidation()
     assert not dv.hide_drop_down
     dv.hide_drop_down = True
     assert dv.showDropDown is True
Exemple #12
0
 def test_contains(self, DataValidation):
     dv = DataValidation(sqref="A1:D4 E5")
     assert "C2" in dv