def test_document_property_is_a_Document_instance(self): factory = WordprocessingDocumentFactory() factory.add(MainDocumentPart, '') package = create_zip_archive(factory.to_zip_dict()) # TODO the interface for creating a new WordprocessingDocument sucks document = WordprocessingDocument(path=package) part = document.main_document_part assert isinstance(part.document, Document), part.document
def test_numbering_property_is_a_Numbering_instance(self): factory = WordprocessingDocumentFactory() factory.add(NumberingDefinitionsPart, '') factory.add(MainDocumentPart, '') package = create_zip_archive(factory.to_zip_dict()) # TODO the interface for creating a new WordprocessingDocument sucks document = WordprocessingDocument(path=package) part = document.main_document_part.numbering_definitions_part assert isinstance(part.numbering, Numbering), part.numbering
def load_document(self): # It's likely that we could replace this logic with a # WordprocessingDocumentFactory document = WordprocessingDocument(path=None) package = document.package document_part = package.create_part(uri='/word/document.xml', ) if self.numbering_dict is not None: numbering_xml = DXB.numbering(self.numbering_dict) self.relationships.append({ 'external': False, 'target_path': 'numbering.xml', 'data': numbering_xml, 'relationship_id': 'numbering', 'relationship_type': NumberingDefinitionsPart.relationship_type, # noqa }) if self.styles_xml: self.relationships.append({ 'external': False, 'target_path': 'styles.xml', 'data': self.styles_xml, 'relationship_id': 'styles', 'relationship_type': StyleDefinitionsPart.relationship_type, }) for relationship in self.relationships: target_mode = 'Internal' if relationship['external']: target_mode = 'External' target_uri = relationship['target_path'] if 'data' in relationship: full_target_uri = posixpath.join( package.uri, 'word', target_uri, ) package.streams[full_target_uri] = BytesIO( relationship['data'], ) package.create_part(uri=full_target_uri) document_part.create_relationship( target_uri=target_uri, target_mode=target_mode, relationship_type=relationship['relationship_type'], relationship_id=relationship['relationship_id'], ) package.streams[document_part.uri] = BytesIO(self.document_xml) package.create_relationship( target_uri=document_part.uri, target_mode='Internal', relationship_type=MainDocumentPart.relationship_type, ) # This is the standard page width for a word document (in points), Also # the page width that we are looking for in the test. self._page_width = 612 return document
def load_document(self): self.document = WordprocessingDocument(path=self.path) return self.document
def test_image_parts(self): image_document = WordprocessingDocument( path='tests/fixtures/has_image.docx', ) parts = image_document.main_document_part.image_parts self.assertEqual(len(parts), 1) self.assertEqual(parts[0].uri, '/word/media/image1.gif')
def setUp(self): self.document = WordprocessingDocument( path='tests/fixtures/no_break_hyphen.docx', )