FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-docx/tests/test_drawing.py at master · python-openxml/python-docx · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
python-openxml
/
python-docx
Public
Notifications
You must be signed in to change notification settings
Fork
1.3k
Star
5.7k
Code
Issues
373
Pull requests
140
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python-docx
/
tests
/
test_drawing.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
74 lines (56 loc) · 2.46 KB
Breadcrumbs
python-docx
/
tests
/
test_drawing.py
Copy path
File metadata and controls
74 lines (56 loc) · 2.46 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
# pyright: reportPrivateUsage=false
"""Unit test suite for the `docx.drawing` module."""
from
__future__
import
annotations
from
typing
import
cast
import
pytest
from
docx
.
drawing
import
Drawing
from
docx
.
image
.
image
import
Image
from
docx
.
oxml
.
drawing
import
CT_Drawing
from
docx
.
parts
.
document
import
DocumentPart
from
docx
.
parts
.
image
import
ImagePart
from
.
unitutil
.
cxml
import
element
from
.
unitutil
.
mock
import
FixtureRequest
,
Mock
,
instance_mock
class
DescribeDrawing
:
"""Unit-test suite for `docx.drawing.Drawing` objects."""
@
pytest
.
mark
.
parametrize
(
(
"cxml"
,
"expected_value"
),
[
(
"w:drawing/wp:inline/a:graphic/a:graphicData/pic:pic"
,
True
),
(
"w:drawing/wp:anchor/a:graphic/a:graphicData/pic:pic"
,
True
),
(
"w:drawing/wp:inline/a:graphic/a:graphicData/a:grpSp"
,
False
),
(
"w:drawing/wp:anchor/a:graphic/a:graphicData/a:chart"
,
False
),
],
)
def
it_knows_when_it_contains_a_Picture
(
self
,
cxml
:
str
,
expected_value
:
bool
,
document_part_
:
Mock
):
drawing
=
Drawing
(
cast
(
CT_Drawing
,
element
(
cxml
)),
document_part_
)
assert
drawing
.
has_picture
==
expected_value
def
it_provides_access_to_the_image_in_a_Picture_drawing
(
self
,
document_part_
:
Mock
,
image_part_
:
Mock
,
image_
:
Mock
):
image_part_
.
image
=
image_
document_part_
.
part
.
related_parts
=
{
"rId1"
:
image_part_
}
cxml
=
(
"w:drawing/wp:inline/a:graphic/a:graphicData/pic:pic/pic:blipFill/a:blip{r:embed=rId1}"
)
drawing
=
Drawing
(
cast
(
CT_Drawing
,
element
(
cxml
)),
document_part_
)
image
=
drawing
.
image
assert
image
is
image_
def
but_it_raises_when_the_drawing_does_not_contain_a_Picture
(
self
,
document_part_
:
Mock
):
drawing
=
Drawing
(
cast
(
CT_Drawing
,
element
(
"w:drawing/wp:inline/a:graphic/a:graphicData/a:grpSp"
)),
document_part_
,
)
with
pytest
.
raises
(
ValueError
,
match
=
"drawing does not contain a picture"
):
drawing
.
image
# -- fixtures --------------------------------------------------------------------------------
@
pytest
.
fixture
def
document_part_
(
self
,
request
:
FixtureRequest
):
return
instance_mock
(
request
,
DocumentPart
)
@
pytest
.
fixture
def
image_
(
self
,
request
:
FixtureRequest
):
return
instance_mock
(
request
,
Image
)
@
pytest
.
fixture
def
image_part_
(
self
,
request
:
FixtureRequest
):
return
instance_mock
(
request
,
ImagePart
)
Back
|
FazBrowse Home
|
New Git URL