|
2 | 2 |
|
3 | 3 | import pytest |
4 | 4 |
|
| 5 | +import docx |
5 | 6 | from docx.api import Document as DocumentFactoryFn |
6 | 7 | from docx.document import Document as DocumentCls |
7 | 8 | from docx.opc.constants import CONTENT_TYPE as CT |
| 9 | +from docx.opc.part import PartFactory |
| 10 | +from docx.parts.document import DocumentPart |
8 | 11 |
|
9 | 12 | from .unitutil.mock import FixtureRequest, Mock, class_mock, function_mock, instance_mock |
10 | 13 |
|
@@ -35,12 +38,26 @@ def it_opens_the_default_docx_if_none_specified( |
35 | 38 | Package_.open.assert_called_once_with("default-document.docx") |
36 | 39 | assert document is document_ |
37 | 40 |
|
| 41 | + def it_opens_a_docm_file(self, Package_: Mock, document_: Mock): |
| 42 | + document_part = Package_.open.return_value.main_document_part |
| 43 | + document_part.document = document_ |
| 44 | + document_part.content_type = CT.WML_DOCUMENT_MAIN_WITH_MACROS |
| 45 | + |
| 46 | + document = DocumentFactoryFn("foobar.docm") |
| 47 | + |
| 48 | + Package_.open.assert_called_once_with("foobar.docm") |
| 49 | + assert document is document_ |
| 50 | + |
38 | 51 | def it_raises_on_not_a_Word_file(self, Package_: Mock): |
39 | 52 | Package_.open.return_value.main_document_part.content_type = "BOGUS" |
40 | 53 |
|
41 | 54 | with pytest.raises(ValueError, match="file 'foobar.xlsx' is not a Word file,"): |
42 | 55 | DocumentFactoryFn("foobar.xlsx") |
43 | 56 |
|
| 57 | + def it_registers_macro_enabled_main_document_parts_with_the_package_reader(self): |
| 58 | + assert docx is not None |
| 59 | + assert PartFactory.part_type_for[CT.WML_DOCUMENT_MAIN_WITH_MACROS] is DocumentPart |
| 60 | + |
44 | 61 | # -- fixtures -------------------------------------------------------------------------------- |
45 | 62 |
|
46 | 63 | @pytest.fixture |
|
0 commit comments