forked from scanny/python-pptx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_util.py
64 lines (51 loc) · 1.99 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
53
54
55
56
57
58
59
60
61
62
63
64
# encoding: utf-8
"""
Test suite for pptx.util module.
"""
from __future__ import absolute_import
import platform
import pytest
from pptx.compat import to_unicode
from pptx.util import Length, Centipoints, Cm, Emu, Inches, Mm, Pt, Px
def test_to_unicode_raises_on_non_string():
"""to_unicode(text) raises on *text* not a string"""
with pytest.raises(TypeError):
to_unicode(999)
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),
(Px, 10,
95250 if platform.system() == 'Windows' else 127000),
])
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),
(914400, 'px', 96 if platform.system() == 'Windows' else 72),
])
def units_fixture(self, request):
emu, units_prop_name, expected_length_in_units = request.param
return emu, units_prop_name, expected_length_in_units