-
Notifications
You must be signed in to change notification settings - Fork 551
/
Copy pathtest_shared.py
83 lines (60 loc) · 2.41 KB
/
test_shared.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"""Unit-test suite for `pptx.shared` module."""
from __future__ import annotations
import pytest
from pptx.opc.package import XmlPart
from pptx.shared import ElementProxy, ParentedElementProxy
from .unitutil.cxml import element
from .unitutil.mock import instance_mock
class DescribeElementProxy(object):
"""Unit-test suite for `pptx.shared.ElementProxy` objects."""
def it_knows_when_its_equal_to_another_proxy_object(self, eq_fixture):
proxy, proxy_2, proxy_3, not_a_proxy = eq_fixture
assert (proxy == proxy_2) is True
assert (proxy == proxy_3) is False
assert (proxy == not_a_proxy) is False
assert (proxy != proxy_2) is False
assert (proxy != proxy_3) is True
assert (proxy != not_a_proxy) is True
def it_knows_its_element(self, element_fixture):
proxy, element = element_fixture
assert proxy.element is element
# fixture --------------------------------------------------------
@pytest.fixture
def element_fixture(self):
p = element("w:p")
proxy = ElementProxy(p)
return proxy, p
@pytest.fixture
def eq_fixture(self):
p, q = element("w:p"), element("w:p")
proxy = ElementProxy(p)
proxy_2 = ElementProxy(p)
proxy_3 = ElementProxy(q)
not_a_proxy = "Foobar"
return proxy, proxy_2, proxy_3, not_a_proxy
class DescribeParentedElementProxy(object):
"""Unit-test suite for `pptx.shared.ParentedElementProxy` objects."""
def it_knows_its_parent(self, parent_fixture):
proxy, parent = parent_fixture
assert proxy.parent is parent
def it_knows_its_part(self, part_fixture):
proxy, part_ = part_fixture
assert proxy.part is part_
# fixture --------------------------------------------------------
@pytest.fixture
def parent_fixture(self):
parent = 42
proxy = ParentedElementProxy(element("w:p"), parent)
return proxy, parent
@pytest.fixture
def part_fixture(self, other_proxy_, part_):
other_proxy_.part = part_
proxy = ParentedElementProxy(None, other_proxy_)
return proxy, part_
# fixture components ---------------------------------------------
@pytest.fixture
def other_proxy_(self, request):
return instance_mock(request, ParentedElementProxy)
@pytest.fixture
def part_(self, request):
return instance_mock(request, XmlPart)