|
10 | 10 |
|
11 | 11 | from docx.opc.constants import RELATIONSHIP_TYPE as RT
|
12 | 12 | from docx.opc.coreprops import CoreProperties
|
13 |
| -from docx.oxml.parts.document import CT_Body |
14 |
| -from docx.oxml.text.run import CT_R |
15 | 13 | from docx.package import ImageParts, Package
|
16 |
| -from docx.parts.document import DocumentPart, InlineShapes |
| 14 | +from docx.parts.document import DocumentPart |
17 | 15 | from docx.parts.image import ImagePart
|
18 | 16 | from docx.parts.numbering import NumberingPart
|
19 | 17 | from docx.parts.styles import StylesPart
|
20 |
| -from docx.shape import InlineShape |
21 | 18 | from docx.styles.style import BaseStyle
|
22 | 19 | from docx.styles.styles import Styles
|
23 | 20 | from docx.text.paragraph import Paragraph
|
24 |
| -from docx.text.run import Run |
25 | 21 |
|
26 | 22 | from ..oxml.parts.unitdata.document import a_body, a_document
|
27 | 23 | from ..oxml.unitdata.text import a_p
|
28 |
| -from ..unitutil.cxml import element |
29 | 24 | from ..unitutil.mock import (
|
30 |
| - instance_mock, class_mock, loose_mock, method_mock, property_mock |
| 25 | + instance_mock, class_mock, method_mock, property_mock |
31 | 26 | )
|
32 | 27 |
|
33 | 28 |
|
@@ -300,133 +295,3 @@ def styles_prop_(self, request, styles_):
|
300 | 295 | @pytest.fixture
|
301 | 296 | def _styles_part_prop_(self, request):
|
302 | 297 | return property_mock(request, DocumentPart, '_styles_part')
|
303 |
| - |
304 |
| - |
305 |
| -class DescribeInlineShapes(object): |
306 |
| - |
307 |
| - def it_knows_how_many_inline_shapes_it_contains( |
308 |
| - self, inline_shapes_fixture): |
309 |
| - inline_shapes, expected_count = inline_shapes_fixture |
310 |
| - assert len(inline_shapes) == expected_count |
311 |
| - |
312 |
| - def it_can_iterate_over_its_InlineShape_instances( |
313 |
| - self, inline_shapes_fixture): |
314 |
| - inline_shapes, inline_shape_count = inline_shapes_fixture |
315 |
| - actual_count = 0 |
316 |
| - for inline_shape in inline_shapes: |
317 |
| - assert isinstance(inline_shape, InlineShape) |
318 |
| - actual_count += 1 |
319 |
| - assert actual_count == inline_shape_count |
320 |
| - |
321 |
| - def it_provides_indexed_access_to_inline_shapes( |
322 |
| - self, inline_shapes_fixture): |
323 |
| - inline_shapes, inline_shape_count = inline_shapes_fixture |
324 |
| - for idx in range(-inline_shape_count, inline_shape_count): |
325 |
| - inline_shape = inline_shapes[idx] |
326 |
| - assert isinstance(inline_shape, InlineShape) |
327 |
| - |
328 |
| - def it_raises_on_indexed_access_out_of_range( |
329 |
| - self, inline_shapes_fixture): |
330 |
| - inline_shapes, inline_shape_count = inline_shapes_fixture |
331 |
| - with pytest.raises(IndexError): |
332 |
| - too_low = -1 - inline_shape_count |
333 |
| - inline_shapes[too_low] |
334 |
| - with pytest.raises(IndexError): |
335 |
| - too_high = inline_shape_count |
336 |
| - inline_shapes[too_high] |
337 |
| - |
338 |
| - def it_can_add_an_inline_picture_to_the_document( |
339 |
| - self, add_picture_fixture): |
340 |
| - # fixture ---------------------- |
341 |
| - (inline_shapes, image_descriptor_, document_, InlineShape_, |
342 |
| - run, r_, image_part_, rId_, shape_id_, new_picture_shape_ |
343 |
| - ) = add_picture_fixture |
344 |
| - # exercise --------------------- |
345 |
| - picture_shape = inline_shapes.add_picture(image_descriptor_, run) |
346 |
| - # verify ----------------------- |
347 |
| - document_.get_or_add_image_part.assert_called_once_with( |
348 |
| - image_descriptor_ |
349 |
| - ) |
350 |
| - InlineShape_.new_picture.assert_called_once_with( |
351 |
| - r_, image_part_, rId_, shape_id_ |
352 |
| - ) |
353 |
| - assert picture_shape is new_picture_shape_ |
354 |
| - |
355 |
| - def it_knows_the_part_it_belongs_to(self, inline_shapes_with_parent_): |
356 |
| - inline_shapes, parent_ = inline_shapes_with_parent_ |
357 |
| - part = inline_shapes.part |
358 |
| - assert part is parent_.part |
359 |
| - |
360 |
| - # fixtures ------------------------------------------------------- |
361 |
| - |
362 |
| - @pytest.fixture |
363 |
| - def add_picture_fixture( |
364 |
| - self, request, body_, document_, image_descriptor_, InlineShape_, |
365 |
| - r_, image_part_, rId_, shape_id_, new_picture_shape_): |
366 |
| - inline_shapes = InlineShapes(body_, None) |
367 |
| - property_mock(request, InlineShapes, 'part', return_value=document_) |
368 |
| - run = Run(r_, None) |
369 |
| - return ( |
370 |
| - inline_shapes, image_descriptor_, document_, InlineShape_, run, |
371 |
| - r_, image_part_, rId_, shape_id_, new_picture_shape_ |
372 |
| - ) |
373 |
| - |
374 |
| - @pytest.fixture |
375 |
| - def inline_shapes_fixture(self): |
376 |
| - body = element( |
377 |
| - 'w:body/w:p/(w:r/w:drawing/wp:inline, w:r/w:drawing/wp:inline)' |
378 |
| - ) |
379 |
| - inline_shapes = InlineShapes(body, None) |
380 |
| - expected_count = 2 |
381 |
| - return inline_shapes, expected_count |
382 |
| - |
383 |
| - # fixture components --------------------------------------------- |
384 |
| - |
385 |
| - @pytest.fixture |
386 |
| - def body_(self, request, r_): |
387 |
| - body_ = instance_mock(request, CT_Body) |
388 |
| - body_.add_p.return_value.add_r.return_value = r_ |
389 |
| - return body_ |
390 |
| - |
391 |
| - @pytest.fixture |
392 |
| - def document_(self, request, rId_, image_part_, shape_id_): |
393 |
| - document_ = instance_mock(request, DocumentPart, name='document_') |
394 |
| - document_.get_or_add_image_part.return_value = image_part_, rId_ |
395 |
| - document_.next_id = shape_id_ |
396 |
| - return document_ |
397 |
| - |
398 |
| - @pytest.fixture |
399 |
| - def image_part_(self, request): |
400 |
| - return instance_mock(request, ImagePart) |
401 |
| - |
402 |
| - @pytest.fixture |
403 |
| - def image_descriptor_(self, request): |
404 |
| - return instance_mock(request, str) |
405 |
| - |
406 |
| - @pytest.fixture |
407 |
| - def InlineShape_(self, request, new_picture_shape_): |
408 |
| - InlineShape_ = class_mock(request, 'docx.parts.document.InlineShape') |
409 |
| - InlineShape_.new_picture.return_value = new_picture_shape_ |
410 |
| - return InlineShape_ |
411 |
| - |
412 |
| - @pytest.fixture |
413 |
| - def inline_shapes_with_parent_(self, request): |
414 |
| - parent_ = loose_mock(request, name='parent_') |
415 |
| - inline_shapes = InlineShapes(None, parent_) |
416 |
| - return inline_shapes, parent_ |
417 |
| - |
418 |
| - @pytest.fixture |
419 |
| - def new_picture_shape_(self, request): |
420 |
| - return instance_mock(request, InlineShape) |
421 |
| - |
422 |
| - @pytest.fixture |
423 |
| - def r_(self, request): |
424 |
| - return instance_mock(request, CT_R) |
425 |
| - |
426 |
| - @pytest.fixture |
427 |
| - def rId_(self, request): |
428 |
| - return instance_mock(request, str) |
429 |
| - |
430 |
| - @pytest.fixture |
431 |
| - def shape_id_(self, request): |
432 |
| - return instance_mock(request, int) |
0 commit comments