/usr/lib/python2.7/dist-packages/openpyxl/worksheet/tests/test_datavalidation.py is in python-openpyxl 2.3.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | from __future__ import absolute_import
# Copyright (c) 2010-2015 openpyxl
import pytest
from openpyxl.workbook import Workbook
from openpyxl.xml.functions import fromstring, tostring
from openpyxl.tests.helper import compare_xml
# There are already unit-tests in test_cell.py that test out the
# coordinate_from_string method. This should be the only way the
# collapse_cell_addresses method can throw, so we don't bother using invalid
# cell coordinates in the test-data here.
COLLAPSE_TEST_DATA = [
(["A1"], "A1"),
(["A1", "B1"], "A1 B1"),
(["A1", "A2", "A3", "A4", "B1", "B2", "B3", "B4"], "A1:A4 B1:B4"),
(["A2", "A4", "A3", "A1", "A5"], "A1:A5"),
]
@pytest.mark.parametrize("cells, expected",
COLLAPSE_TEST_DATA)
def test_collapse_cell_addresses(cells, expected):
from .. datavalidation import collapse_cell_addresses
assert collapse_cell_addresses(cells) == expected
def test_expand_cell_ranges():
from .. datavalidation import expand_cell_ranges
rs = "A1:A3 B1:B3"
assert expand_cell_ranges(rs) == ["A1", "A2", "A3", "B1", "B2", "B3"]
@pytest.fixture
def DataValidation():
from .. datavalidation import DataValidation
return 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'
def test_error_message(DataValidation):
dv = DataValidation("list", formula1='"Dog,Cat,Fish"')
dv.set_error_message('You done bad')
dv_dict = dict(dv)
assert dv_dict['errorTitle'] == 'Validation Error'
assert dv_dict['error'] == 'You done bad'
def test_prompt_message(DataValidation):
dv = DataValidation(type="list", formula1='"Dog,Cat,Fish"')
dv.set_prompt_message('Please enter a value')
dv_dict = dict(dv)
assert dv_dict['promptTitle'] == 'Validation Prompt'
assert dv_dict['prompt'] == 'Please enter a value'
def test_writer_validation(DataValidation):
wb = Workbook()
ws = wb.active
dv = DataValidation(type="list", formula1='"Dog,Cat,Fish"')
dv.add_cell(ws['A1'])
xml = tostring(dv.to_tree())
expected = """
<dataValidation allowBlank="0" showErrorMessage="1" showInputMessage="1" sqref="A1" type="list">
<formula1>"Dog,Cat,Fish"</formula1>
</dataValidation>
"""
diff = compare_xml(xml, expected)
assert diff is None, diff
def test_sqref(DataValidation):
dv = DataValidation()
dv.sqref = "A1"
assert dv.cells == ["A1"]
def test_ctor(DataValidation):
dv = DataValidation()
assert dict(dv) == {'allowBlank': '0', 'showErrorMessage': '1',
'showInputMessage': '1', 'sqref': ''}
def test_with_formula(DataValidation):
xml = """
<dataValidation xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" allowBlank="0" showErrorMessage="1" showInputMessage="1" sqref="A1" type="list">
<formula1>"Dog,Cat,Fish"</formula1>
</dataValidation>
"""
xml = fromstring(xml)
dv = DataValidation.from_tree(xml)
assert dv.cells == ['A1']
assert dv.type == "list"
assert dv.formula1 == '"Dog,Cat,Fish"'
def test_parser(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 dict(dv) == {"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"}
|