Skip to content

Commit 56c31be

Browse files
author
Steve Canny
committed
test: reorg fixtures in test_document.py
1 parent a665ad1 commit 56c31be

File tree

1 file changed

+60
-58
lines changed

1 file changed

+60
-58
lines changed

tests/parts/test_document.py

Lines changed: 60 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,66 @@ def add_table_fixture(self, document_part_body_, body_, table_):
152152
rows, cols = 2, 4
153153
return document_part, rows, cols, body_, table_
154154

155+
@pytest.fixture
156+
def document_blob_fixture(self, request, serialize_part_xml_):
157+
document_elm = instance_mock(request, CT_Document)
158+
document_part = DocumentPart(None, None, document_elm, None)
159+
return document_part, document_elm, serialize_part_xml_
160+
161+
@pytest.fixture
162+
def document_body_fixture(self, request, _Body_):
163+
document_elm = (
164+
a_document().with_nsdecls().with_child(
165+
a_body())
166+
).element
167+
body_elm = document_elm[0]
168+
document = DocumentPart(None, None, document_elm, None)
169+
return document, _Body_, body_elm
170+
171+
@pytest.fixture
172+
def inline_shapes_fixture(self, request, InlineShapes_):
173+
document_elm = (
174+
a_document().with_nsdecls().with_child(
175+
a_body())
176+
).element
177+
body_elm = document_elm[0]
178+
document = DocumentPart(None, None, document_elm, None)
179+
return document, InlineShapes_, body_elm
180+
181+
@pytest.fixture(params=[
182+
((), 1), ((1,), 2), ((2,), 1), ((1, 2, 3), 4), ((1, 2, 4), 3),
183+
((0, 0), 1), ((0, 0, 1, 3), 2), (('foo', 1, 2), 3), ((1, 'bar'), 2)
184+
])
185+
def next_id_fixture(self, request):
186+
existing_ids, expected_id = request.param
187+
document_elm = a_document().with_nsdecls().element
188+
for n in existing_ids:
189+
p = a_p().with_nsdecls().element
190+
p.set('id', str(n))
191+
document_elm.append(p)
192+
document = DocumentPart(None, None, document_elm, None)
193+
return document, expected_id
194+
195+
@pytest.fixture
196+
def paragraphs_fixture(self, document_part_body_, body_, paragraphs_):
197+
document_part = DocumentPart(None, None, None, None)
198+
body_.paragraphs = paragraphs_
199+
return document_part, paragraphs_
200+
201+
@pytest.fixture
202+
def sections_fixture(self, request, Sections_):
203+
document_elm = a_document().with_nsdecls().element
204+
document = DocumentPart(None, None, document_elm, None)
205+
return document, document_elm, Sections_
206+
207+
@pytest.fixture
208+
def tables_fixture(self, document_part_body_, body_, tables_):
209+
document_part = DocumentPart(None, None, None, None)
210+
body_.tables = tables_
211+
return document_part, tables_
212+
213+
# fixture components ---------------------------------------------
214+
155215
@pytest.fixture
156216
def _Body_(self, request):
157217
return class_mock(request, 'docx.parts.document._Body')
@@ -175,22 +235,6 @@ def content_type_(self, request):
175235
def document(self):
176236
return DocumentPart(None, None, None, None)
177237

178-
@pytest.fixture
179-
def document_blob_fixture(self, request, serialize_part_xml_):
180-
document_elm = instance_mock(request, CT_Document)
181-
document_part = DocumentPart(None, None, document_elm, None)
182-
return document_part, document_elm, serialize_part_xml_
183-
184-
@pytest.fixture
185-
def document_body_fixture(self, request, _Body_):
186-
document_elm = (
187-
a_document().with_nsdecls().with_child(
188-
a_body())
189-
).element
190-
body_elm = document_elm[0]
191-
document = DocumentPart(None, None, document_elm, None)
192-
return document, _Body_, body_elm
193-
194238
@pytest.fixture
195239
def document_part_(self, request):
196240
return instance_mock(request, DocumentPart)
@@ -238,30 +282,6 @@ def init(self, request):
238282
def InlineShapes_(self, request):
239283
return class_mock(request, 'docx.parts.document.InlineShapes')
240284

241-
@pytest.fixture
242-
def inline_shapes_fixture(self, request, InlineShapes_):
243-
document_elm = (
244-
a_document().with_nsdecls().with_child(
245-
a_body())
246-
).element
247-
body_elm = document_elm[0]
248-
document = DocumentPart(None, None, document_elm, None)
249-
return document, InlineShapes_, body_elm
250-
251-
@pytest.fixture(params=[
252-
((), 1), ((1,), 2), ((2,), 1), ((1, 2, 3), 4), ((1, 2, 4), 3),
253-
((0, 0), 1), ((0, 0, 1, 3), 2), (('foo', 1, 2), 3), ((1, 'bar'), 2)
254-
])
255-
def next_id_fixture(self, request):
256-
existing_ids, expected_id = request.param
257-
document_elm = a_document().with_nsdecls().element
258-
for n in existing_ids:
259-
p = a_p().with_nsdecls().element
260-
p.set('id', str(n))
261-
document_elm.append(p)
262-
document = DocumentPart(None, None, document_elm, None)
263-
return document, expected_id
264-
265285
@pytest.fixture
266286
def parse_xml_(self, request):
267287
return function_mock(request, 'docx.parts.document.parse_xml')
@@ -278,12 +298,6 @@ def package_(self, request):
278298
def paragraphs_(self, request):
279299
return instance_mock(request, list)
280300

281-
@pytest.fixture
282-
def paragraphs_fixture(self, document_part_body_, body_, paragraphs_):
283-
document_part = DocumentPart(None, None, None, None)
284-
body_.paragraphs = paragraphs_
285-
return document_part, paragraphs_
286-
287301
@pytest.fixture
288302
def part_load_fixture(
289303
self, document_part_load_, partname_, blob_, package_,
@@ -311,12 +325,6 @@ def rId_(self, request):
311325
def Sections_(self, request):
312326
return class_mock(request, 'docx.parts.document.Sections')
313327

314-
@pytest.fixture
315-
def sections_fixture(self, request, Sections_):
316-
document_elm = a_document().with_nsdecls().element
317-
document = DocumentPart(None, None, document_elm, None)
318-
return document, document_elm, Sections_
319-
320328
@pytest.fixture
321329
def serialize_part_xml_(self, request):
322330
return function_mock(
@@ -331,12 +339,6 @@ def table_(self, request):
331339
def tables_(self, request):
332340
return instance_mock(request, list)
333341

334-
@pytest.fixture
335-
def tables_fixture(self, document_part_body_, body_, tables_):
336-
document_part = DocumentPart(None, None, None, None)
337-
body_.tables = tables_
338-
return document_part, tables_
339-
340342

341343
class Describe_Body(object):
342344

0 commit comments

Comments
 (0)