-
Notifications
You must be signed in to change notification settings - Fork 698
Expand file tree
/
Copy pathline.py
More file actions
144 lines (108 loc) · 4.95 KB
/
line.py
File metadata and controls
144 lines (108 loc) · 4.95 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
"""Step implementations for LineFormat-related features."""
from __future__ import annotations
from behave import given, then, when
from helpers import test_pptx
from pptx import Presentation
from pptx.enum.dml import MSO_LINE, MSO_LINE_END_TYPE
from pptx.util import Length, Pt
# given ===================================================
@given("a LineFormat object as line")
def given_a_LineFormat_object_as_line(context):
line = Presentation(test_pptx("dml-line")).slides[0].shapes[0].line
context.line = line
@given("a LineFormat object as line having {current} dash style")
def given_a_LineFormat_object_as_line_having_dash_style(context, current):
shape_idx = {"no explicit": 0, "solid": 1, "dashed": 2, "dash-dot": 3}[current]
shape = Presentation(test_pptx("dml-line")).slides[3].shapes[shape_idx]
context.line = shape.line
@given("a LineFormat object as line having {arrowhead} end arrowhead")
def given_a_LineFormat_object_as_line_having_end_arrowhead(context, arrowhead):
shape_idx = {"no explicit": 0, "triangle": 1}[arrowhead]
shape = Presentation(test_pptx("dml-line-end")).slides[0].shapes[shape_idx]
context.line = shape.line
@given("a LineFormat object as line having {arrowhead} begin arrowhead")
def given_a_LineFormat_object_as_line_having_begin_arrowhead(context, arrowhead):
shape_idx = {"no explicit": 0, "stealth": 2}[arrowhead]
shape = Presentation(test_pptx("dml-line-end")).slides[0].shapes[shape_idx]
context.line = shape.line
@given("a LineFormat object as line having {line_width} width")
def given_a_LineFormat_object_as_line_having_width(context, line_width):
shape_idx = {"no explicit": 0, "1 pt": 1}[line_width]
prs = Presentation(test_pptx("dml-line"))
shape = prs.slides[2].shapes[shape_idx]
context.line = shape.line
# when ====================================================
@when("I assign {value_key} to line.dash_style")
def when_I_assign_value_to_line_dash_style(context, value_key):
value = {
"None": None,
"MSO_LINE.DASH": MSO_LINE.DASH,
"MSO_LINE.DASH_DOT": MSO_LINE.DASH_DOT,
"MSO_LINE.SOLID": MSO_LINE.SOLID,
}[value_key]
context.line.dash_style = value
@when("I assign {value_key} to line.end_arrowhead_style")
def when_I_assign_value_to_line_end_arrowhead_style(context, value_key):
value = {
"None": None,
"MSO_LINE_END_TYPE.TRIANGLE": MSO_LINE_END_TYPE.TRIANGLE,
"MSO_LINE_END_TYPE.STEALTH": MSO_LINE_END_TYPE.STEALTH,
}[value_key]
context.line.end_arrowhead_style = value
@when("I assign {line_width} to line.width")
def when_I_assign_value_to_line_width(context, line_width):
value = {"None": None, "1 pt": Pt(1), "2.34 pt": Pt(2.34)}[line_width]
context.line.width = value
# then ====================================================
@then("line.color is a ColorFormat object")
def then_line_color_is_a_ColorFormat_object(context):
class_name = context.line.color.__class__.__name__
expected_value = "ColorFormat"
assert class_name == expected_value, "expected '%s', got '%s'" % (
expected_value,
class_name,
)
@then("line.dash_style is {dash_style}")
def then_line_dash_style_is_value(context, dash_style):
expected_value = {
"None": None,
"MSO_LINE.DASH": MSO_LINE.DASH,
"MSO_LINE.DASH_DOT": MSO_LINE.DASH_DOT,
"MSO_LINE.SOLID": MSO_LINE.SOLID,
}[dash_style]
actual_value = context.line.dash_style
assert actual_value == expected_value, "expected %s, got %s" % (
expected_value,
actual_value,
)
@then("line.end_arrowhead_style is {value_key}")
def then_line_end_arrowhead_style_is_value(context, value_key):
expected_value = {
"None": None,
"MSO_LINE_END_TYPE.TRIANGLE": MSO_LINE_END_TYPE.TRIANGLE,
"MSO_LINE_END_TYPE.STEALTH": MSO_LINE_END_TYPE.STEALTH,
}[value_key]
actual_value = context.line.end_arrowhead_style
assert actual_value == expected_value, "expected %s, got %s" % (expected_value, actual_value)
@then("line.begin_arrowhead_style is {value_key}")
def then_line_begin_arrowhead_style_is_value(context, value_key):
expected_value = {
"None": None,
"MSO_LINE_END_TYPE.STEALTH": MSO_LINE_END_TYPE.STEALTH,
}[value_key]
actual_value = context.line.begin_arrowhead_style
assert actual_value == expected_value, "expected %s, got %s" % (expected_value, actual_value)
@then("line.fill is a FillFormat object")
def then_line_fill_is_a_FillFormat_object(context):
class_name = context.line.fill.__class__.__name__
expected_value = "FillFormat"
assert class_name == expected_value, "expected '%s', got '%s'" % (
expected_value,
class_name,
)
@then("line.width is {line_width}")
def then_line_width_is_value(context, line_width):
expected_value = {"0": 0, "1 pt": Pt(1), "2.34 pt": Pt(2.34)}[line_width]
line_width = context.line.width
assert line_width == expected_value
assert isinstance(line_width, Length)