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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
from docx import Document
from docxcompose.composer import Composer
from docxcompose.utils import xpath
from utils import ComposedDocument
from utils import docx_path
from utils import FixtureDocument
import pytest
def test_abstractnums_from_styles_are_not_duplicated(multiple_numberings):
anums = xpath(
multiple_numberings.doc.part.numbering_part.element,
'.//w:abstractNum[.//w:pStyle]')
assert len(anums) == 2
def test_restart_first_numbering(multiple_numberings):
paragraphs = xpath(multiple_numberings.doc.element.body, './/w:p')
assert len(xpath(paragraphs[9], './/w:numId')) == 1
def test_do_not_restart_numbering_of_bullets(mixed_numberings):
paragraphs = xpath(mixed_numberings.doc.element.body, './/w:p')
assert len(xpath(paragraphs[10], './/w:numId')) == 0
def test_do_not_break_on_custom_styled_numbering(custom_styled_numbering):
assert custom_styled_numbering.doc.element.xpath('.//w:numId/@w:val') == ['2']*4
def test_preserve_zero_numbering_references(numberings_with_zero_reference):
numberings_with_zero_ref = xpath(
numberings_with_zero_reference.doc.element.body,
'.//w:p//w:numId[@w:val="0"]')
assert len(numberings_with_zero_ref) == 2
def test_restarts_numbering_if_sequence_is_split_across_elements(numbering_with_paragraphs):
numbering_ids = [each.val for each in xpath(
numbering_with_paragraphs.doc.element.body, './/w:numId')]
assert numbering_ids == [3, 3, 3, 3, 4, 4, 4]
def test_restart_numbering_manages_shared_style_names(static_reseed):
doc = FixtureDocument("common_stylename_different_id.docx")
composed = ComposedDocument(
"common_stylename_different_id1.docx",
"common_stylename_different_id2.docx")
assert composed == doc
def test_numberings(static_reseed):
doc = FixtureDocument("numberings.docx")
composed = ComposedDocument(
"numberings.docx", "numberings.docx")
assert composed == doc
def test_restart_numberings():
doc = FixtureDocument("numberings_restart.docx")
composed = ComposedDocument(
"numberings_restart.docx", "numberings_restart.docx")
assert composed == doc
def test_numberings_styles():
doc = FixtureDocument("numberings_styles.docx")
composed = ComposedDocument(
"numberings_styles.docx", "numberings_styles.docx")
assert composed == doc
def test_numbering_reference_to_numbering_zero():
doc = FixtureDocument("numbering_reference_to_numbering_zero.docx")
composed = ComposedDocument("numbering_reference_to_numbering_zero.docx",
"numbering_reference_to_numbering_zero.docx")
assert composed == doc
def test_restarts_numbering_for_all_elements_of_same_sequence():
doc = FixtureDocument("numbering_with_paragraphs_in_between.docx")
composed = ComposedDocument(
"numbering_with_paragraphs_in_between.docx",
"numbering_with_paragraphs_in_between.docx")
assert composed == doc
def test_preserves_list_styles_when_restarting_numberings():
doc = FixtureDocument("broken_listing.docx")
composed = ComposedDocument(
"broken_listing_master.docx", "broken_listing.docx")
assert composed == doc
def test_preserves_list_styles_when_restarting_many_numberings():
doc = FixtureDocument("broken_listing_many.docx")
composed = ComposedDocument(
"broken_listing_master.docx", "broken_listing_many.docx")
assert composed == doc
def test_preserves_list_styles_when_restarting_nested_numberings():
doc = FixtureDocument("broken_listing_nested.docx")
composed = ComposedDocument(
"broken_listing_master.docx", "broken_listing_nested.docx")
assert composed == doc
@pytest.fixture
def numberings_with_zero_reference():
composer = Composer(Document(
docx_path("numbering_reference_to_numbering_zero.docx")))
composer.append(Document(
docx_path("numbering_reference_to_numbering_zero.docx")))
return composer
@pytest.fixture
def numberings_in_styles():
composer = Composer(Document(docx_path("master.docx")))
composer.append(Document(docx_path("numberings_styles.docx")))
return composer
@pytest.fixture
def multiple_numberings():
composer = Composer(Document(docx_path("numberings_styles.docx")))
composer.append(Document(docx_path("numberings_styles.docx")))
return composer
@pytest.fixture
def mixed_numberings():
composer = Composer(Document(docx_path("numberings_restart.docx")))
composer.append(Document(docx_path("numberings_restart.docx")))
return composer
@pytest.fixture
def numbering_with_paragraphs():
composer = Composer(Document(docx_path("master.docx")))
composer.append(Document(docx_path("numbering_with_paragraphs_in_between.docx")))
return composer
@pytest.fixture
def custom_styled_numbering():
composer = Composer(Document(docx_path('master.docx')))
composer.append(Document(docx_path("custom_list_style.docx")))
return composer
|