-
Notifications
You must be signed in to change notification settings - Fork 703
Expand file tree
/
Copy pathtest_base.py
More file actions
723 lines (624 loc) · 23.1 KB
/
test_base.py
File metadata and controls
723 lines (624 loc) · 23.1 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
# pyright: reportPrivateUsage=false
"""Unit-test suite for `pptx.shapes.base` module."""
from __future__ import annotations
from typing import TYPE_CHECKING, cast
import pytest
from pptx.action import ActionSetting
from pptx.dml.effect import ShadowFormat
from pptx.enum.shapes import PP_PLACEHOLDER
from pptx.oxml.shapes.shared import BaseShapeElement
from pptx.oxml.text import CT_TextBody
from pptx.shapes import Subshape
from pptx.shapes.autoshape import Shape
from pptx.shapes.base import BaseShape, _PlaceholderFormat
from pptx.shapes.graphfrm import GraphicFrame
from pptx.shapes.picture import Picture
from pptx.shapes.shapetree import BaseShapeFactory, SlideShapes
from ..oxml.unitdata.shape import (
a_cNvPr,
a_cxnSp,
a_graphicFrame,
a_grpSp,
a_grpSpPr,
a_p_xfrm,
a_pic,
an_ext,
an_nvSpPr,
an_off,
an_sp,
an_spPr,
an_xfrm,
)
from ..unitutil.cxml import element, xml
from ..unitutil.mock import class_mock, instance_mock, loose_mock
if TYPE_CHECKING:
from pptx.opc.package import XmlPart
from pptx.oxml.shapes import ShapeElement
from pptx.types import ProvidesPart
class DescribeBaseShape(object):
"""Unit-test suite for `pptx.shapes.base.BaseShape` objects."""
def it_provides_access_to_its_click_action(self, click_action_fixture):
shape, ActionSetting_, cNvPr, click_action_ = click_action_fixture
click_action = shape.click_action
ActionSetting_.assert_called_once_with(cNvPr, shape)
assert click_action is click_action_
def it_knows_its_shape_id(self, id_fixture):
shape, expected_value = id_fixture
assert shape.shape_id == expected_value
def it_knows_its_name(self, name_get_fixture):
shape, name = name_get_fixture
assert shape.name == name
def it_can_change_its_name(self, name_set_fixture):
shape, new_value, expected_xml = name_set_fixture
shape.name = new_value
assert shape._element.xml == expected_xml
@pytest.mark.parametrize(
("shape_cxml", "expected_x", "expected_y"),
[
("p:cxnSp/p:spPr", None, None),
("p:cxnSp/p:spPr/a:xfrm", None, None),
("p:cxnSp/p:spPr/a:xfrm/a:off{x=123,y=456}", 123, 456),
("p:graphicFrame/p:xfrm", None, None),
("p:graphicFrame/p:xfrm/a:off{x=123,y=456}", 123, 456),
("p:grpSp/p:grpSpPr", None, None),
("p:grpSp/p:grpSpPr/a:xfrm/a:off{x=123,y=456}", 123, 456),
("p:pic/p:spPr", None, None),
("p:pic/p:spPr/a:xfrm", None, None),
("p:pic/p:spPr/a:xfrm/a:off{x=123,y=456}", 123, 456),
("p:sp/p:spPr", None, None),
("p:sp/p:spPr/a:xfrm", None, None),
("p:sp/p:spPr/a:xfrm/a:off{x=123,y=456}", 123, 456),
],
)
def it_has_a_position(
self,
shape_cxml: str,
expected_x: int | None,
expected_y: int | None,
provides_part: ProvidesPart,
):
shape_elm = cast("ShapeElement", element(shape_cxml))
shape = BaseShape(shape_elm, provides_part)
assert shape.left == expected_x
assert shape.top == expected_y
@pytest.fixture
def provides_part(self) -> ProvidesPart:
class FakeProvidesPart:
@property
def part(self) -> XmlPart:
raise NotImplementedError
return FakeProvidesPart()
def it_knows_its_alt_text(self, alt_text_get_fixture):
shape, alt_text = alt_text_get_fixture
assert shape.alt_text == alt_text
def it_can_change_its_alt_text(self, alt_text_set_fixture):
shape, new_value, expected_xml = alt_text_set_fixture
shape.alt_text = new_value
assert shape._element.xml == expected_xml
def it_can_delete_its_alt_text(self, alt_text_del_fixture):
shape, expected_xml = alt_text_del_fixture
del shape.alt_text
assert shape._element.xml == expected_xml
def it_can_change_its_position(self, position_set_fixture):
shape, left, top, expected_xml = position_set_fixture
shape.left = left
shape.top = top
assert shape._element.xml == expected_xml
def it_has_dimensions(self, dimensions_get_fixture):
shape, expected_width, expected_height = dimensions_get_fixture
assert shape.width == expected_width
assert shape.height == expected_height
def it_can_change_its_dimensions(self, dimensions_set_fixture):
shape, width, height, expected_xml = dimensions_set_fixture
shape.width = width
shape.height = height
assert shape._element.xml == expected_xml
def it_knows_its_rotation_angle(self, rotation_get_fixture):
shape, expected_value = rotation_get_fixture
assert shape.rotation == expected_value
def it_can_change_its_rotation_angle(self, rotation_set_fixture):
shape, new_value, expected_xml = rotation_set_fixture
shape.rotation = new_value
assert shape._element.xml == expected_xml
def it_provides_access_to_its_shadow(self, shadow_fixture):
shape, ShadowFormat_, spPr, shadow_ = shadow_fixture
shadow = shape.shadow
ShadowFormat_.assert_called_once_with(spPr)
assert shadow is shadow_
def it_knows_the_part_it_belongs_to(self, part_fixture):
shape, parent_ = part_fixture
part = shape.part
assert part is parent_.part
def it_knows_it_doesnt_have_a_text_frame(self):
shape = BaseShape(None, None)
assert shape.has_text_frame is False
def it_knows_whether_it_is_a_placeholder(self, is_placeholder_fixture):
shape, is_placeholder = is_placeholder_fixture
assert shape.is_placeholder is is_placeholder
def it_provides_access_to_its_placeholder_format(self, phfmt_fixture):
shape, _PlaceholderFormat_, placeholder_format_, ph = phfmt_fixture
placeholder_format = shape.placeholder_format
_PlaceholderFormat_.assert_called_once_with(ph)
assert placeholder_format is placeholder_format_
def it_raises_when_shape_is_not_a_placeholder(self, phfmt_raise_fixture):
shape = phfmt_raise_fixture
with pytest.raises(ValueError):
shape.placeholder_format
def it_knows_it_doesnt_contain_a_chart(self):
shape = BaseShape(None, None)
assert shape.has_chart is False
def it_knows_it_doesnt_contain_a_table(self):
shape = BaseShape(None, None)
assert shape.has_table is False
# fixtures -------------------------------------------------------
@pytest.fixture(
params=[
"p:sp/p:nvSpPr/p:cNvPr",
"p:grpSp/p:nvGrpSpPr/p:cNvPr",
"p:graphicFrame/p:nvGraphicFramePr/p:cNvPr",
"p:cxnSp/p:nvCxnSpPr/p:cNvPr",
"p:pic/p:nvPicPr/p:cNvPr",
]
)
def click_action_fixture(self, request, ActionSetting_, action_setting_):
sp_cxml = request.param
sp = element(sp_cxml)
cNvPr = sp.xpath("//p:cNvPr")[0]
shape = BaseShape(sp, None)
return shape, ActionSetting_, cNvPr, action_setting_
@pytest.fixture(
params=[
("sp", False),
("sp_with_ext", True),
("pic", False),
("pic_with_ext", True),
("graphicFrame", False),
("graphicFrame_with_ext", True),
("grpSp", False),
("grpSp_with_ext", True),
("cxnSp", False),
("cxnSp_with_ext", True),
]
)
def dimensions_get_fixture(self, request, width, height):
shape_elm_fixt_name, expect_values = request.param
shape_elm = request.getfixturevalue(shape_elm_fixt_name)
shape = BaseShape(shape_elm, None)
if not expect_values:
width = height = None
return shape, width, height
@pytest.fixture(
params=[
("sp", "sp_with_ext"),
("pic", "pic_with_ext"),
("graphicFrame", "graphicFrame_with_ext"),
("grpSp", "grpSp_with_ext"),
("cxnSp", "cxnSp_with_ext"),
]
)
def dimensions_set_fixture(self, request, width, height):
start_elm_fixt_name, expected_elm_fixt_name = request.param
start_elm = request.getfixturevalue(start_elm_fixt_name)
shape = BaseShape(start_elm, None)
expected_xml = request.getfixturevalue(expected_elm_fixt_name).xml
return shape, width, height, expected_xml
@pytest.fixture(
params=[
("p:sp/p:nvSpPr/p:cNvPr{id=1}", 1),
("p:cxnSp/p:nvCxnSpPr/p:cNvPr{id=2}", 2),
("p:graphicFrame/p:nvGraphicFramePr/p:cNvPr{id=3}", 3),
("p:grpSp/p:nvGrpSpPr/p:cNvPr{id=4}", 4),
("p:pic/p:nvPicPr/p:cNvPr{id=5}", 5),
]
)
def id_fixture(self, request):
xSp_cxml, expected_value = request.param
shape = BaseShape(element(xSp_cxml), None)
return shape, expected_value
@pytest.fixture(params=[True, False])
def is_placeholder_fixture(self, request, shape_elm_, txBody_):
is_placeholder = request.param
shape_elm_.has_ph_elm = is_placeholder
shape = BaseShape(shape_elm_, None)
return shape, is_placeholder
@pytest.fixture
def name_get_fixture(self, shape_name):
shape_elm = (
an_sp()
.with_nsdecls()
.with_child(an_nvSpPr().with_child(a_cNvPr().with_name(shape_name)))
).element
shape = BaseShape(shape_elm, None)
return shape, shape_name
@pytest.fixture(
params=[
(
"p:sp/p:nvSpPr/p:cNvPr{id=1,name=foo}",
Shape,
"Shape1",
"p:sp/p:nvSpPr/p:cNvPr{id=1,name=Shape1}",
),
(
"p:grpSp/p:nvGrpSpPr/p:cNvPr{id=2,name=bar}",
BaseShape,
"Shape2",
"p:grpSp/p:nvGrpSpPr/p:cNvPr{id=2,name=Shape2}",
),
(
"p:graphicFrame/p:nvGraphicFramePr/p:cNvPr{id=3,name=baz}",
GraphicFrame,
"Shape3",
"p:graphicFrame/p:nvGraphicFramePr/p:cNvPr{id=3,name=Shape3}",
),
(
"p:cxnSp/p:nvCxnSpPr/p:cNvPr{id=4,name=boo}",
BaseShape,
"Shape4",
"p:cxnSp/p:nvCxnSpPr/p:cNvPr{id=4,name=Shape4}",
),
(
"p:pic/p:nvPicPr/p:cNvPr{id=5,name=far}",
Picture,
"Shape5",
"p:pic/p:nvPicPr/p:cNvPr{id=5,name=Shape5}",
),
]
)
def name_set_fixture(self, request):
xSp_cxml, ShapeCls, new_value, expected_xSp_cxml = request.param
shape = ShapeCls(element(xSp_cxml), None)
expected_xml = xml(expected_xSp_cxml)
return shape, new_value, expected_xml
@pytest.fixture
def alt_text_get_fixture(self, shape_alt_text):
shape_elm = (
an_sp()
.with_nsdecls()
.with_child(an_nvSpPr().with_child(a_cNvPr().with_descr(shape_alt_text)))
).element
shape = BaseShape(shape_elm, None)
return shape, shape_alt_text
@pytest.fixture(
params=[
(
"p:sp/p:nvSpPr/p:cNvPr{id=1,descr=foo}",
Shape,
"AltText1",
"p:sp/p:nvSpPr/p:cNvPr{id=1,descr=AltText1}",
),
(
"p:grpSp/p:nvGrpSpPr/p:cNvPr{id=2,descr=bar}",
BaseShape,
"AltText2",
"p:grpSp/p:nvGrpSpPr/p:cNvPr{id=2,descr=AltText2}",
),
(
"p:graphicFrame/p:nvGraphicFramePr/p:cNvPr{id=3,descr=baz}",
GraphicFrame,
"AltText3",
"p:graphicFrame/p:nvGraphicFramePr/p:cNvPr{id=3,descr=AltText3}",
),
(
"p:cxnSp/p:nvCxnSpPr/p:cNvPr{id=4,descr=boo}",
BaseShape,
"AltText4",
"p:cxnSp/p:nvCxnSpPr/p:cNvPr{id=4,descr=AltText4}",
),
(
"p:pic/p:nvPicPr/p:cNvPr{id=5,descr=far}",
Picture,
"AltText5",
"p:pic/p:nvPicPr/p:cNvPr{id=5,descr=AltText5}",
),
]
)
def alt_text_set_fixture(self, request):
xSp_cxml, ShapeCls, new_value, expected_xSp_cxml = request.param
shape = ShapeCls(element(xSp_cxml), None)
expected_xml = xml(expected_xSp_cxml)
return shape, new_value, expected_xml
@pytest.fixture(
params=[
(
"p:sp/p:nvSpPr/p:cNvPr{id=1,descr=foo}",
Shape,
"p:sp/p:nvSpPr/p:cNvPr{id=1}",
),
(
"p:grpSp/p:nvGrpSpPr/p:cNvPr{id=2,descr=bar}",
BaseShape,
"p:grpSp/p:nvGrpSpPr/p:cNvPr{id=2}",
),
(
"p:graphicFrame/p:nvGraphicFramePr/p:cNvPr{id=3,descr=baz}",
GraphicFrame,
"p:graphicFrame/p:nvGraphicFramePr/p:cNvPr{id=3}",
),
(
"p:cxnSp/p:nvCxnSpPr/p:cNvPr{id=4,descr=boo}",
BaseShape,
"p:cxnSp/p:nvCxnSpPr/p:cNvPr{id=4}",
),
(
"p:pic/p:nvPicPr/p:cNvPr{id=5,descr=far}",
Picture,
"p:pic/p:nvPicPr/p:cNvPr{id=5}",
),
]
)
def alt_text_del_fixture(self, request):
xSp_cxml, ShapeCls, expected_xSp_cxml = request.param
shape = ShapeCls(element(xSp_cxml), None)
expected_xml = xml(expected_xSp_cxml)
return shape, expected_xml
@pytest.fixture
def part_fixture(self, shapes_):
parent_ = shapes_
shape = BaseShape(None, parent_)
return shape, parent_
@pytest.fixture
def phfmt_fixture(self, _PlaceholderFormat_, placeholder_format_):
sp = element("p:sp/p:nvSpPr/p:nvPr/p:ph")
ph = sp.xpath("//p:ph")[0]
shape = BaseShape(sp, None)
return shape, _PlaceholderFormat_, placeholder_format_, ph
@pytest.fixture
def phfmt_raise_fixture(self):
return BaseShape(element("p:sp/p:nvSpPr/p:nvPr"), None)
@pytest.fixture(
params=[
("sp", "sp_with_off"),
("pic", "pic_with_off"),
("graphicFrame", "graphicFrame_with_off"),
("grpSp", "grpSp_with_off"),
("cxnSp", "cxnSp_with_off"),
]
)
def position_set_fixture(self, request, left, top):
start_elm_fixt_name, expected_elm_fixt_name = request.param
start_elm = request.getfixturevalue(start_elm_fixt_name)
shape = BaseShape(start_elm, None)
expected_xml = request.getfixturevalue(expected_elm_fixt_name).xml
return shape, left, top, expected_xml
@pytest.fixture(
params=[
("p:sp/p:spPr", 0.0),
("p:sp/p:spPr/a:xfrm{rot=60000}", 1.0),
("p:sp/p:spPr/a:xfrm{rot=2545200}", 42.42),
("p:sp/p:spPr/a:xfrm{rot=-60000}", 359.0),
("p:grpSp/p:grpSpPr/a:xfrm{rot=2545200}", 42.42),
]
)
def rotation_get_fixture(self, request):
xSp_cxml, expected_value = request.param
shape = BaseShapeFactory(element(xSp_cxml), None)
return shape, expected_value
@pytest.fixture(
params=[
("p:sp/p:spPr/a:xfrm", 1.0, "p:sp/p:spPr/a:xfrm{rot=60000}"),
("p:sp/p:spPr/a:xfrm{rot=60000}", 0.0, "p:sp/p:spPr/a:xfrm"),
(
"p:sp/p:spPr/a:xfrm{rot=60000}",
-420.0,
"p:sp/p:spPr/a:xfrm{rot=18000000}",
),
("p:grpSp/p:grpSpPr/a:xfrm", 1.0, "p:grpSp/p:grpSpPr/a:xfrm{rot=60000}"),
]
)
def rotation_set_fixture(self, request):
xSp_cxml, new_value, expected_xSp_cxml = request.param
shape = BaseShapeFactory(element(xSp_cxml), None)
expected_xml = xml(expected_xSp_cxml)
return shape, new_value, expected_xml
@pytest.fixture(
params=[
"p:sp/p:spPr",
"p:cxnSp/p:spPr",
"p:pic/p:spPr",
# ---group and graphic frame shapes override this property---
]
)
def shadow_fixture(self, request, ShadowFormat_, shadow_):
sp_cxml = request.param
sp = element(sp_cxml)
spPr = sp.xpath("//p:spPr")[0]
ShadowFormat_.return_value = shadow_
shape = BaseShape(sp, None)
return shape, ShadowFormat_, spPr, shadow_
# fixture components ---------------------------------------------
@pytest.fixture
def ActionSetting_(self, request, action_setting_):
return class_mock(request, "pptx.shapes.base.ActionSetting", return_value=action_setting_)
@pytest.fixture
def action_setting_(self, request):
return instance_mock(request, ActionSetting)
@pytest.fixture
def cxnSp(self):
return a_cxnSp().with_nsdecls().with_child(an_spPr()).element
@pytest.fixture
def cxnSp_with_ext(self, width, height):
return (
a_cxnSp()
.with_nsdecls()
.with_child(
an_spPr().with_child(an_xfrm().with_child(an_ext().with_cx(width).with_cy(height)))
)
).element
@pytest.fixture
def cxnSp_with_off(self, left, top):
return (
a_cxnSp()
.with_nsdecls()
.with_child(
an_spPr().with_child(an_xfrm().with_child(an_off().with_x(left).with_y(top)))
)
).element
@pytest.fixture
def graphicFrame(self):
# Note that <p:xfrm> element is required on graphicFrame
return a_graphicFrame().with_nsdecls().with_child(a_p_xfrm()).element
@pytest.fixture
def graphicFrame_with_ext(self, width, height):
return (
a_graphicFrame()
.with_nsdecls()
.with_child(a_p_xfrm().with_child(an_ext().with_cx(width).with_cy(height)))
).element
@pytest.fixture
def graphicFrame_with_off(self, left, top):
return (
a_graphicFrame()
.with_nsdecls()
.with_child(a_p_xfrm().with_child(an_off().with_x(left).with_y(top)))
).element
@pytest.fixture
def grpSp(self):
return (a_grpSp().with_nsdecls("p", "a").with_child(a_grpSpPr())).element
@pytest.fixture
def grpSp_with_ext(self, width, height):
return (
a_grpSp()
.with_nsdecls("p", "a")
.with_child(
a_grpSpPr().with_child(
an_xfrm().with_child(an_ext().with_cx(width).with_cy(height))
)
)
).element
@pytest.fixture
def grpSp_with_off(self, left, top):
return (
a_grpSp()
.with_nsdecls("p", "a")
.with_child(
a_grpSpPr().with_child(an_xfrm().with_child(an_off().with_x(left).with_y(top)))
)
).element
@pytest.fixture
def height(self):
return 654
@pytest.fixture
def left(self):
return 123
@pytest.fixture
def pic(self):
return a_pic().with_nsdecls().with_child(an_spPr()).element
@pytest.fixture
def pic_with_off(self, left, top):
return (
a_pic()
.with_nsdecls()
.with_child(
an_spPr().with_child(an_xfrm().with_child(an_off().with_x(left).with_y(top)))
)
).element
@pytest.fixture
def pic_with_ext(self, width, height):
return (
a_pic()
.with_nsdecls()
.with_child(
an_spPr().with_child(an_xfrm().with_child(an_ext().with_cx(width).with_cy(height)))
)
).element
@pytest.fixture
def _PlaceholderFormat_(self, request, placeholder_format_):
return class_mock(
request,
"pptx.shapes.base._PlaceholderFormat",
return_value=placeholder_format_,
)
@pytest.fixture
def placeholder_format_(self, request):
return instance_mock(request, _PlaceholderFormat)
@pytest.fixture
def shadow_(self, request):
return instance_mock(request, ShadowFormat)
@pytest.fixture
def ShadowFormat_(self, request):
return class_mock(request, "pptx.shapes.base.ShadowFormat")
@pytest.fixture
def shape_elm_(self, request, shape_id, shape_name, txBody_):
return instance_mock(
request,
BaseShapeElement,
shape_id=shape_id,
shape_name=shape_name,
txBody=txBody_,
)
@pytest.fixture
def shape_id(self):
return 42
@pytest.fixture
def shape_name(self):
return "Foobar 41"
@pytest.fixture
def shape_alt_text(self):
return "Alternative text description"
@pytest.fixture
def shapes_(self, request):
return instance_mock(request, SlideShapes)
@pytest.fixture
def sp(self):
return an_sp().with_nsdecls().with_child(an_spPr()).element
@pytest.fixture
def sp_with_ext(self, width, height):
return (
an_sp()
.with_nsdecls()
.with_child(
an_spPr().with_child(an_xfrm().with_child(an_ext().with_cx(width).with_cy(height)))
)
).element
@pytest.fixture
def sp_with_off(self, left, top):
return (
an_sp()
.with_nsdecls()
.with_child(
an_spPr().with_child(an_xfrm().with_child(an_off().with_x(left).with_y(top)))
)
).element
@pytest.fixture
def top(self):
return 456
@pytest.fixture
def txBody_(self, request):
return instance_mock(request, CT_TextBody)
@pytest.fixture
def width(self):
return 321
class DescribeSubshape(object):
def it_knows_the_part_it_belongs_to(self, subshape_with_parent_):
subshape, parent_ = subshape_with_parent_
part = subshape.part
assert part is parent_.part
# fixtures ---------------------------------------------
@pytest.fixture
def subshape_with_parent_(self, request):
parent_ = loose_mock(request, name="parent_")
subshape = Subshape(parent_)
return subshape, parent_
class Describe_PlaceholderFormat(object):
def it_knows_its_idx(self, idx_get_fixture):
placeholder_format, expected_value = idx_get_fixture
assert placeholder_format.idx == expected_value
def it_knows_its_type(self, type_get_fixture):
placeholder_format, expected_value = type_get_fixture
assert placeholder_format.type == expected_value
# fixtures ---------------------------------------------
@pytest.fixture(params=[("p:ph", 0), ("p:ph{idx=42}", 42)])
def idx_get_fixture(self, request):
ph_cxml, expected_value = request.param
placeholder_format = _PlaceholderFormat(element(ph_cxml))
return placeholder_format, expected_value
@pytest.fixture(
params=[
("p:ph", PP_PLACEHOLDER.OBJECT),
("p:ph{type=pic}", PP_PLACEHOLDER.PICTURE),
]
)
def type_get_fixture(self, request):
ph_cxml, expected_value = request.param
placeholder_format = _PlaceholderFormat(element(ph_cxml))
return placeholder_format, expected_value