def but_it_raises_KeyError_when_bookmark_name_already_exists( self, _bookmarks_prop_, bookmarks_): bookmarks_.__contains__.return_value = True _bookmarks_prop_.return_value = bookmarks_ blkcntnr = BlockItemContainer(None, None) with pytest.raises(KeyError) as e: blkcntnr.start_bookmark("X") assert "Document already contains bookmark with name X" in str(e.value)
def it_can_add_a_paragraph(self, add_paragraph_fixture, _add_paragraph_): text, style, paragraph_, add_run_calls = add_paragraph_fixture _add_paragraph_.return_value = paragraph_ blkcntnr = BlockItemContainer(None, None) paragraph = blkcntnr.add_paragraph(text, style) _add_paragraph_.assert_called_once_with(blkcntnr) assert paragraph.add_run.call_args_list == add_run_calls assert paragraph.style == style assert paragraph is paragraph_
def it_can_add_a_paragraph(self, add_paragraph_fixture, _add_paragraph_): text, style, paragraph_, add_run_calls = add_paragraph_fixture _add_paragraph_.return_value = paragraph_ blkcntnr = BlockItemContainer(None, None) paragraph = blkcntnr.add_paragraph(text, style) _add_paragraph_.assert_called_once_with(blkcntnr) assert paragraph.add_run.call_args_list == add_run_calls assert paragraph.style == style assert paragraph is paragraph_
def add_paragraph_fixture(self, request, _add_paragraph_, paragraph_, add_run_): blkcntnr = BlockItemContainer(None, None) text, style = request.param _add_paragraph_.return_value = paragraph_ add_run_calls = [call(text)] if text else [] paragraph_.style = None return blkcntnr, text, style, paragraph_, add_run_calls
def it_provides_access_to_the_global_bookmarks_collection_to_help( self, bookmarks_fixture, part_prop_, bookmarks_): parent_part_ = bookmarks_fixture parent_part_.bookmarks = bookmarks_ part_prop_.return_value = parent_part_ blkcntnr = BlockItemContainer(None, None) bookmarks = blkcntnr._bookmarks assert bookmarks is bookmarks_
def it_can_start_a_bookmark( self, start_bookmark_fixture, _bookmarks_prop_, bookmarks_, _Bookmark_, bookmark_, ): blockContainer, name, next_id, expected_xml = start_bookmark_fixture bookmarks_.__contains__.return_value = False bookmarks_.next_id = next_id _bookmarks_prop_.return_value = bookmarks_ _Bookmark_.return_value = bookmark_ blkcntnr = BlockItemContainer(blockContainer, None) bookmark = blkcntnr.start_bookmark(name) _Bookmark_.assert_called_once_with((ANY, None)) assert blkcntnr._element.xml == expected_xml assert bookmark is bookmark_
def tables_fixture(self, request): blkcntnr_cxml, expected_count = request.param blkcntnr = BlockItemContainer(element(blkcntnr_cxml), None) return blkcntnr, expected_count
def add_table_fixture(self): blkcntnr = BlockItemContainer(element("w:body"), None) rows, cols, width = 2, 2, Inches(2) expected_xml = snippet_seq("new-tbl")[0] return blkcntnr, rows, cols, width, expected_xml
def _add_paragraph_fixture(self, request): blkcntnr_cxml, after_cxml = "w:body", "w:body/w:p" blkcntnr = BlockItemContainer(element(blkcntnr_cxml), None) expected_xml = xml(after_cxml) return blkcntnr, expected_xml
def add_table_fixture(self, request): blkcntnr_cxml, rows, cols, after_cxml = request.param blkcntnr = BlockItemContainer(element(blkcntnr_cxml), None) expected_xml = xml(after_cxml) return blkcntnr, rows, cols, expected_xml
def add_paragraph_fixture(self, request): blkcntnr_cxml, text, style, after_cxml = request.param blkcntnr = BlockItemContainer(element(blkcntnr_cxml), None) expected_xml = xml(after_cxml) return blkcntnr, text, style, expected_xml