-
Notifications
You must be signed in to change notification settings - Fork 560
/
Copy pathtest_util.py
52 lines (43 loc) · 1.62 KB
/
test_util.py
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
"""Unit-test suite for `pptx.util` module."""
from __future__ import annotations
import pytest
from pptx.util import Centipoints, Cm, Emu, Inches, Length, Mm, Pt
class DescribeLength(object):
def it_can_construct_from_convenient_units(self, construct_fixture):
UnitCls, units_val, emu = construct_fixture
length = UnitCls(units_val)
assert isinstance(length, Length)
assert length == emu
def it_can_self_convert_to_convenient_units(self, units_fixture):
emu, units_prop_name, expected_length_in_units = units_fixture
length = Length(emu)
length_in_units = getattr(length, units_prop_name)
assert length_in_units == expected_length_in_units
# fixtures -------------------------------------------------------
@pytest.fixture(
params=[
(Length, 914400, 914400),
(Inches, 1.1, 1005840),
(Centipoints, 12.5, 1587),
(Cm, 2.53, 910799),
(Emu, 9144.9, 9144),
(Mm, 13.8, 496800),
(Pt, 24.5, 311150),
]
)
def construct_fixture(self, request):
UnitCls, units_val, emu = request.param
return UnitCls, units_val, emu
@pytest.fixture(
params=[
(914400, "inches", 1.0),
(914400, "centipoints", 7200.0),
(914400, "cm", 2.54),
(914400, "emu", 914400),
(914400, "mm", 25.4),
(914400, "pt", 72.0),
]
)
def units_fixture(self, request):
emu, units_prop_name, expected_length_in_units = request.param
return emu, units_prop_name, expected_length_in_units