GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — python-docx/tests/test_api.py at master · python-openxml/python-docx

Expand file tree

/

test_api.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
56 lines (39 loc) · 2.03 KB
/

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")
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.