FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-docx/tests/test_api.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_api.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
56 lines (39 loc) · 2.03 KB
Breadcrumbs
python-docx
/
tests
/
test_api.py
Copy path
File metadata and controls
56 lines (39 loc) · 2.03 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
"""Test suite for the docx.api module."""
import
pytest
from
docx
.
api
import
Document
as
DocumentFactoryFn
from
docx
.
document
import
Document
as
DocumentCls
from
docx
.
opc
.
constants
import
CONTENT_TYPE
as
CT
from
.
unitutil
.
mock
import
FixtureRequest
,
Mock
,
class_mock
,
function_mock
,
instance_mock
class
DescribeDocument
:
"""Unit-test suite for `docx.api.Document` factory function."""
def
it_opens_a_docx_file
(
self
,
Package_
:
Mock
,
document_
:
Mock
):
document_part
=
Package_
.
open
.
return_value
.
main_document_part
document_part
.
document
=
document_
document_part
.
content_type
=
CT
.
WML_DOCUMENT_MAIN
document
=
DocumentFactoryFn
(
"foobar.docx"
)
Package_
.
open
.
assert_called_once_with
(
"foobar.docx"
)
assert
document
is
document_
def
it_opens_the_default_docx_if_none_specified
(
self
,
_default_docx_path_
:
Mock
,
Package_
:
Mock
,
document_
:
Mock
):
_default_docx_path_
.
return_value
=
"default-document.docx"
document_part
=
Package_
.
open
.
return_value
.
main_document_part
document_part
.
document
=
document_
document_part
.
content_type
=
CT
.
WML_DOCUMENT_MAIN
document
=
DocumentFactoryFn
()
Package_
.
open
.
assert_called_once_with
(
"default-document.docx"
)
assert
document
is
document_
def
it_raises_on_not_a_Word_file
(
self
,
Package_
:
Mock
):
Package_
.
open
.
return_value
.
main_document_part
.
content_type
=
"BOGUS"
with
pytest
.
raises
(
ValueError
,
match
=
"file 'foobar.xlsx' is not a Word file,"
):
DocumentFactoryFn
(
"foobar.xlsx"
)
# -- fixtures --------------------------------------------------------------------------------
@
pytest
.
fixture
def
_default_docx_path_
(
self
,
request
:
FixtureRequest
):
return
function_mock
(
request
,
"docx.api._default_docx_path"
)
@
pytest
.
fixture
def
document_
(
self
,
request
:
FixtureRequest
):
return
instance_mock
(
request
,
DocumentCls
)
@
pytest
.
fixture
def
Package_
(
self
,
request
:
FixtureRequest
):
return
class_mock
(
request
,
"docx.api.Package"
)
Back
|
FazBrowse Home
|
New Git URL