from __future__ import absolute_import
# Copyright (c) 2010-2017 openpyxl
import pytest
from .. import Strict
@pytest.fixture
[docs]def UniversalMeasure():
from ..excel import UniversalMeasure
class Dummy(Strict):
value = UniversalMeasure()
return Dummy()
[docs]class TestUniversalMeasure:
@pytest.mark.parametrize("value",
["24.73mm", "0cm", "24pt", '999pc', "50pi"]
)
[docs] def test_valid(self, UniversalMeasure, value):
UniversalMeasure.value = value
assert UniversalMeasure.value == value
@pytest.mark.parametrize("value",
[24.73, '24.73zz', "24.73 mm", None, "-24.73cm"]
)
[docs] def test_invalid(self, UniversalMeasure, value):
with pytest.raises(ValueError):
UniversalMeasure.value = "{0}".format(value)
@pytest.fixture
[docs]def HexBinary():
from ..excel import HexBinary
class Dummy(Strict):
value = HexBinary()
return Dummy()
[docs]class TestHexBinary:
@pytest.mark.parametrize("value",
["aa35efd", "AABBCCDD"]
)
[docs] def test_valid(self, HexBinary, value):
HexBinary.value = value
assert HexBinary.value == value
@pytest.mark.parametrize("value",
["GGII", "35.5"]
)
[docs] def test_invalid(self, HexBinary, value):
with pytest.raises(ValueError):
HexBinary.value = value
@pytest.fixture
[docs]def TextPoint():
from ..excel import TextPoint
class Dummy(Strict):
value = TextPoint()
return Dummy()
[docs]class TestTextPoint:
@pytest.mark.parametrize("value",
[-400000, "400000", 0]
)
[docs] def test_valid(self, TextPoint, value):
TextPoint.value = value
assert TextPoint.value == int(value)
[docs] def test_invalid_value(self, TextPoint):
with pytest.raises(ValueError):
TextPoint.value = -400001
[docs] def test_invalid_type(self, TextPoint):
with pytest.raises(TypeError):
TextPoint.value = "40pt"
@pytest.fixture
[docs]def Percentage():
from ..excel import Percentage
class Dummy(Strict):
value = Percentage()
return Dummy()
[docs]class TestPercentage:
@pytest.mark.parametrize("value",
["15%", "15.5%"]
)
def test_valid(self, Percentage, value):
Percentage.value = value
assert Percentage.value == value
@pytest.mark.parametrize("value",
["15", "101%", "-1%"]
)
[docs] def test_valid(self, Percentage, value):
with pytest.raises(ValueError):
Percentage.value = value
@pytest.fixture
[docs]def Guid():
from ..excel import Guid
class Dummy(Strict):
value = Guid()
return Dummy()
[docs]class TestGuid():
@pytest.mark.parametrize("value",
["{00000000-5BD2-4BC8-9F70-7020E1357FB2}"]
)
def test_valid(self, Guid, value):
Guid.value = value
assert Guid.value == value
@pytest.mark.parametrize("value",
["{00000000-5BD2-4BC8-9F70-7020E1357FB2"]
)
[docs] def test_valid(self, Guid, value):
with pytest.raises(ValueError):
Guid.value = value
@pytest.fixture
[docs]def Base64Binary():
from ..excel import Base64Binary
class Dummy(Strict):
value = Base64Binary()
return Dummy()
[docs]class TestBase64Binary():
@pytest.mark.parametrize("value",
["9oN7nWkCAyEZib1RomSJTjmPpCY="]
)
def test_valid(self, Base64Binary, value):
Base64Binary.value = value
assert Base64Binary.value == value
@pytest.mark.parametrize("value",
["==0F"]
)
[docs] def test_valid(self, Base64Binary, value):
with pytest.raises(ValueError):
Base64Binary.value = value
@pytest.fixture
[docs]def CellRange():
from ..excel import CellRange
class Dummy(Strict):
value = CellRange()
return Dummy()
[docs]class TestCellRange():
@pytest.mark.parametrize("value",
["A1",
"A1:H5",
"A:B",
]
)
[docs] def test_valid(self, CellRange, value):
CellRange.value = value
assert CellRange.value == value
@pytest.mark.parametrize("value",
["A1:",
"A1:5",
"A1:B4:C7"
]
)
[docs] def test_invalid(self, CellRange, value):
with pytest.raises(ValueError):
CellRange.value = value